[PATCH] elf: Check PDE load address with non-empty text section

Sam James sam@gentoo.org
Sun Dec 22 08:12:10 GMT 2024


"H.J. Lu" <hjl.tools@gmail.com> writes:

> On Sun, Dec 22, 2024, 2:19 PM Sam James <sam@gentoo.org> wrote:
>
>  "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>  > On Mon, Dec 2, 2024 at 9:15 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>  >>
>  >> On Sat, Nov 30, 2024 at 12:18 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>  >> >
>  >> > On Sat, Nov 30, 2024, 12:52 AM Florian Weimer <fweimer@redhat.com> wrote:
>  >> >>
>  >> >> * H. J. Lu:
>  >> >>
>  >> >> > +ifneq (,$(load-address-ldflag))
>  >> >> > +tests += \
>  >> >> > +  tst-pie-address \
>  >> >> > +  # tests
>  >> >> > +tests-pie += \
>  >> >> > +  tst-pie-address \
>  >> >> > +  # tests-pie
>  >> >> > +LDFLAGS-tst-pie-address += $(load-address-ldflag)=$(pde-load-address)
>  >> >> > +ifeq (yes,$(enable-static-pie))
>  >> >> > +tests += \
>  >> >> > +  tst-pie-address-static \
>  >> >> > +  # tests
>  >> >> > +tests-static += \
>  >> >> > +  tst-pie-address-static \
>  >> >> > +  # tests-static
>  >> >> > +LDFLAGS-tst-pie-address-static += \
>  >> >> > +  $(load-address-ldflag)=$(pde-load-address)
>  >> >> > +endif
>  >> >> > +endif
>  >> >>
>  >> >> These tests fail on aarch64 and s390x for us:
>  >> >>
>  >> >> =====FAIL: elf/tst-pie-address.out=====
>  >> >> =====FAIL: elf/tst-pie-address.test-result=====
>  >> >> FAIL: elf/tst-pie-address
>  >> >> original exit status 139
>  >> >> =====FAIL: elf/tst-pie-address-static.out=====
>  >> >> =====FAIL: elf/tst-pie-address-static.test-result=====
>  >> >> FAIL: elf/tst-pie-address-static
>  >> >> original exit status 132
>  >> >
>  >> >
>  >> > Do they fail without -Ttext-segment=? My change doesn't
>  >> > touch dynamic PIE.  If it fails, it may be due to glibc or ld bugs.
>  >> >
>  >> >>
>  >> >> The configure checks report this
>  >> >>
>  >> >> checking whether -fPIE is default... no
>  >> >> checking PDE load address... 0x0000000001000000
>  >>
>  >> Somehow aarch64 got
>  >>
>  >> pde-load-address =
>  >>
>  >> in config.make.  I will take a look.
>  >>
>  >
>  > Does this patch it for you?
>  >
>  > Check PDE load address with non-empty text section:
>  >
>  > .globl _start
>  > _start:
>  > .globl __start
>  > .byte 0
>
>  LGTM, but I didn't check it on arm64. I can if you need.
>
> Yes, please.

On trunk, I see:

checking whether -fPIC is default... yes
checking whether -fPIE is default... yes
checking PDE load address...
checking for linker that supports -Ttext-segment=... yes
checking if we can build programs as PIE... yes
checking if we can build static PIE programs... yes

With your patch, I see:

checking whether -fPIC is default... yes
checking whether -fPIE is default... yes
checking PDE load address... 0x0000000000400000
checking for linker that supports -Ttext-segment=0x0000000000400000... yes
checking if we can build programs as PIE... yes
checking if we can build static PIE programs... yes

But I couldn't reproduce the original failure (I assume because default
PIE and some hacks to try repro it didn't work either). No new test
failures.

>
> Thanks.


More information about the Libc-alpha mailing list