Hi Romain, can you confirm that attached patch works for you? I tested with non-PIE and PIE and both seems to work.
best regards Waldemar Romain Naour wrote, > Hi Waldemar, > > Le 19/05/2021 à 00:09, Waldemar Brodkorb a écrit : > > Hi Romain, > > Romain Naour wrote, > > > >> Hello, > >> > >> Recently in Buildroot the option BR2_PIC_PIE has been enabled by default > >> along > >> with other hardening features [1]. Since then some ppc defconfig such > >> qemu_ppc_e500mc_defconfig are failing to boot due to a segfault in init > >> program. > >> > >> The segfault appear very early in __uClibc_main while starting any > >> binaries, > >> an issue located in crt1.S (powerpc)[2]. > >> > >> After some trial and error, removing HAVE_ASM_PPC_REL16 from CFLAGS [3] > >> allow to generate a working system again. But this is actually wrong since > >> instead we should consider HAVE_ASM_PPC_REL16 always true nowadays. > > > > What if the assembly inside HAVE_ASM_PPC_REL16 isn't pie safe? > > Good question. > > I guess it should work with pie (see PIEFLAG_NAME:=-fpie) > https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/Rules.mak?h=v1.0.38#n480 > > I did a try with Glibc without any problem with BR2_PIC_PIE enabled. > > Best regards, > Romain > > > > >> Indeed, Glibc removed HAVE_ASM_PPC_REL16 since version 2.22 [4] since "the > >> minimum binutils supports rel16 relocs". Binutils 2.22 supports > >> R_PPC_REL16 as > >> default. > >> > >> uClibc-ng should remove HAVE_ASM_PPC_REL16 but keep the code as it was > >> defined. > >> But this doesn't fix the initial issue. > >> > >> Any idea ? > >> > >> [1] > >> https://git.buildroot.net/buildroot/commit/?id=810ba387bec3c5b6904e8893fb4cb6f9d3717466 > >> [2] > >> https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/powerpc/crt1.S?id=2bf4991c4dd7b50b74656011dea9c40464ff390c#n47 > >> [3] > >> https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/Rules.mak?id=2bf4991c4dd7b50b74656011dea9c40464ff390c#n486 > >> [4] > >> https://sourceware.org/git/?p=glibc.git;a=commit;h=59261ad3eb345e0d7b9f5c73e1a09d046991cea5 > > > > best regards > > Waldemar > > >
diff --git a/libc/sysdeps/linux/powerpc/crt1.S b/libc/sysdeps/linux/powerpc/crt1.S index 27bfc5a5a..14b21fdb3 100644 --- a/libc/sysdeps/linux/powerpc/crt1.S +++ b/libc/sysdeps/linux/powerpc/crt1.S @@ -48,15 +48,8 @@ _start: mr r9,r1 /* Save the stack pointer and pass it to __uClibc_main */ clrrwi r1,r1,4 /* Align stack ptr to 16 bytes */ #ifdef __PIC__ -# ifdef HAVE_ASM_PPC_REL16 - bcl 20,31,1f -1: mflr r31 - addis r31,r31,_GLOBAL_OFFSET_TABLE_-1b@ha - addi r31,r31,_GLOBAL_OFFSET_TABLE_-1b@l -# else bl _GLOBAL_OFFSET_TABLE_-4@local mflr r31 -# endif #endif /* Set up the small data pointer in r13. */ #ifdef __PIC__
_______________________________________________ devel mailing list [email protected] https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
