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>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Thu, 30 Nov 2017 20:18:21 -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> <CAMe9rOoaP=LT16Ee=-MOsL=zpem5XDjo4avhkJgC38FbeqSF4w@mail.gmail.com> <alpine.DEB.2.00.1712010142540.31156@tp.orcam.me.uk>
On Thu, Nov 30, 2017 at 5:57 PM, Maciej W. Rozycki <macro@mips.com> wrote:
> On Thu, 30 Nov 2017, H.J. Lu wrote:
>
>> > 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.
>
> Well, these relocations are produced by GAS, which obviously has nothing
> to do with linking. You need to find a way for them not to be produced in
> the first place, as they are not valid in a PIE executable link.
>
>> > 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
>
> Well, that doesn't prove that these options actually make it to the GCC
> invocation line for say rcrt1.o. Quoting the actual line for rcrt1.o from
> a build log would be more useful.
>
This patch fixes mips build with --enable-static-pie:
diff --git a/sysdeps/mips/Makefile b/sysdeps/mips/Makefile
index fd891ddf09..7ac6fa5031 100644
--- a/sysdeps/mips/Makefile
+++ b/sysdeps/mips/Makefile
@@ -23,6 +23,9 @@ CPPFLAGS-crtn.S += $(pic-ccflag)
endif
ASFLAGS-.os += $(pic-ccflag)
+# libc.a and libc_p.a must be compiled with -fPIE/-fpie for static PIE.
+ASFLAGS-.o += $(pie-default)
+ASFLAGS-.op += $(pie-default)
ifeq ($(subdir),elf)
ifneq ($(o32-fpabi),)
Can you try native mips build with --enable-static-pie using hjl/pie/static
branch?
Thanks.
--
H.J.