This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: PING^N: [PATCH] Add --enable-static-pie to build static PIE [BZ #19574]
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: "Maciej W. Rozycki" <macro at mips dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Thu, 30 Nov 2017 17:08:41 -0800
- Subject: Re: PING^N: [PATCH] Add --enable-static-pie to build static PIE [BZ #19574]
- Authentication-results: sourceware.org; auth=none
- References: <CAMe9rOoyPf-77=cqmEW5Vg2KHwq48g6giW38qpA=oDUsnHaxCA@mail.gmail.com> <alpine.DEB.2.20.1711011603010.26405@digraph.polyomino.org.uk> <CAMe9rOrWi1W+F6K3TRL-2ipz-K4e0aP0ywsVg0XWgdCU1FV7OQ@mail.gmail.com> <CAMe9rOrTW7-JBtfOWjQrqMtS6Kp8efsAAbouFwQOnaAzh=sNpA@mail.gmail.com> <CAMe9rOr5qR-MnP+bEY_3OPdPK1qTnn_7JLi3Xn688E9JWKr1Zw@mail.gmail.com> <5A12C781.3030700@arm.com> <CAMe9rOohYeS4BJFp=TB4Zz26V4K2n8ZXSJX9kYqgEa=eW+w1xQ@mail.gmail.com> <5A18196C.90208@arm.com> <CAMe9rOqFfabivUDke1_ZxyEtV+L9T7VwKKdsdnR9M418L2TQBg@mail.gmail.com> <CAMe9rOpNdwd52vEnAUzOkmwkJXUWZz9-=dc9xfeZ96CYVM=8gQ@mail.gmail.com> <02278c7c-ade4-c8f2-c978-e66f77a101bd@redhat.com> <alpine.DEB.2.00.1711302227190.31156@tp.orcam.me.uk> <CAMe9rOpDRknZANuSvXAqU_qaXzGRjt=uY5BZLJoE_o9Ke+9yfw@mail.gmail.com> <alpine.DEB.2.00.1711302308170.31156@tp.orcam.me.uk>
On Thu, Nov 30, 2017 at 3:31 PM, Maciej W. Rozycki <macro@mips.com> wrote:
> On Thu, 30 Nov 2017, H.J. Lu wrote:
>
>> > Or likely a bug in the `make' recipe used to link `sln' -- Scrt1.o has to
>> > be chosen instead for PIE links and the GCC driver gets it right, however
>> > we use `-nostartfiles' and link in the bits by hand.
>>
>> My current patch links rcrt1.o for static PIE. I got
>>
>> mips64-glibc-linux-gnu-gcc -mabi=32 -nostdlib -nostartfiles -static -o
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/elf/sln
>> -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/csu/rcrt1.o
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/csu/crti.o
>> `mips64-glibc-linux-gnu-gcc -mabi=32 --print-file-name=crtbeginS.o`
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/elf/sln.o
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/elf/static-stubs.o
>> -Wl,--start-group
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a
>> -lgcc -Wl,--end-group `mips64-glibc-linux-gnu-gcc -mabi=32
>> --print-file-name=crtendS.o`
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/csu/crtn.o
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/csu/rcrt1.o:
>> relocation R_MIPS_HI16 against `_gp' can not be used when making a
>> shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(bsd-_setjmp.o):
>> relocation R_MIPS_26 against `__sigsetjmp' can not be used when making
>> a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(sched_yield.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(symlink.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(unlink.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(munmap.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(mprotect.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(madvise.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(mremap.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(sysinfo.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(sysdep.o):
>> relocation R_MIPS_26 against `__errno_location' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(setjmp.o):
>> relocation R_MIPS_26 against `__sigsetjmp_aux' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(uname.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(prctl.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> /export/ssd/git/toolchain/install/compilers/mips64-linux-gnu/bin/../lib/gcc/mips64-glibc-linux-gnu/7.2.1/../../../../mips64-glibc-linux-gnu/bin/ld:
>> /export/gnu/import/git/toolchain/build/glibcs/mips-linux-gnu/glibc/libc.a(setitimer.o):
>> relocation R_MIPS_26 against `__syscall_error' can not be used when
>> making a shared object; recompile with -fPIC
>> collect2: error: ld returned 1 exit status
>
> I don't know what rcrt1.o is, this is the first time I see it mentioned.
See:
https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00247.html
> However overall all these MIPS relocations are strictly non-PIC ones, so
> clearly this code has not been correctly built.
That is MIPS specific issue. It could be bfd_link_pic vs bfd_link_executable
in MIPS linker backend.
> AFAICT you need to pass -DPIC to GCC when assembling sysdeps/mips/start.S
> to get a position-independent intermediate object. The same applies to
> our other MIPS assembly sources.
Everything is compiled with -fPIE -DPIC:
+ifeq (yes,$(enable-static-pie))
+pic-default = -DPIC
+pie-default = $(pie-ccflag)
+ifeq (yes,$(have-static-pie))
+default-pie-ldflag = -static-pie
+else
+default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
+endif
+endif
--
H.J.