| Message ID | 20260424134932.1638126-1-adhemerval.zanella@linaro.org |
|---|---|
| State | New |
| Headers | show |
| Series | arm: Enable static-pie support (BZ 34098) | expand |
On Fri, Apr 24, 2026 at 10:49:23AM -0300, Adhemerval Zanella wrote: > It requires proper gcc support [1], and without proper compiler support > the arm configure disable static-pie support. > > The start.S requires some adjustment to avoid loading main from > the GOT. > > Checked on arm-linux-gnueabihf with and without the gcc patch applied. Could you share how you tested it? Perhaps it makes sense to add a test that is supposed to link successfully as a static PIE? The patch seems OK but I struggle to test it properly. > > [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598610.html > --- > NEWS | 3 +++ > sysdeps/arm/configure | 52 ++++++++++++++++++++++++++++++++++++++++ > sysdeps/arm/configure.ac | 29 ++++++++++++++++++++++ > sysdeps/arm/start.S | 16 +++++++++++++ > 4 files changed, 100 insertions(+) > > diff --git a/NEWS b/NEWS > index eac9322161..6a45bb06ff 100644 > --- a/NEWS > +++ b/NEWS > @@ -18,6 +18,9 @@ Major new features: > > * New locale added: hrx_BR (Hunsrik language spoken in Brazil). > > +* Static PIE is ow support for arm-*-linux-gnueabi. It requires toolchain Nit: s/ow support/now supported/g > + support to correctly set the expected linker options. > + > Deprecated and removed features, and other changes affecting compatibility: > > * Although malloc and related functions currently return pointers > diff --git a/sysdeps/arm/configure b/sysdeps/arm/configure > index 935e022c74..b964c3917a 100644 > --- a/sysdeps/arm/configure > +++ b/sysdeps/arm/configure > > ... > OK > diff --git a/sysdeps/arm/configure.ac b/sysdeps/arm/configure.ac > index cd00ddc9d9..0c4f0f0de8 100644 > --- a/sysdeps/arm/configure.ac > +++ b/sysdeps/arm/configure.ac > @@ -1,6 +1,35 @@ > GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. > # Local configure fragment for sysdeps/arm. > > +dnl Test if the foolchain supports static PIE, the -static-pie should not only > +dnl be accepted, but also generate a ET_DYN without a INTERP entry. > +AC_CACHE_CHECK([if compiler support static PIE], > +libc_cv_static_pie_on_arm, [ > +cat > conftest.S <<\EOF > +.text > +.global _start > +.type _start,#function > +_start: > + > +.data > +.align 2 > +ptr: > + /* This shoul produce an R_ARM_RELATIVE. */ > + .word _start > +EOF > + > + libc_cv_static_pie_on_arm=no > + if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S]) \ > + && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep -q R_ARM_RELATIVE]) \ > + && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest | grep -q INTERP]) > + then > + libc_cv_static_pie_on_arm=yes > + fi > + rm -rf conftest* ]) > +if test "$libc_cv_static_pie_on_arm" = yes; then > + AC_DEFINE(SUPPORT_STATIC_PIE) > +fi > + OK > diff --git a/sysdeps/arm/start.S b/sysdeps/arm/start.S > index a7e62b3934..68e032ef4d 100644 > --- a/sysdeps/arm/start.S > +++ b/sysdeps/arm/start.S > @@ -90,6 +90,7 @@ _start: > push { a1 } > > #ifdef PIC > +# ifdef SHARED > ldr sl, .L_GOT > adr a4, .L_GOT > add sl, sl, a4 > @@ -103,6 +104,16 @@ _start: > /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ > /* Let the libc call main and exit with its return code. */ > bl __libc_start_main(PLT) > +# else > + ldr a1, .L_main_rel /* Load the relative offset of main. */ > + adr a4, .L_main_rel /* Load the actual runtime address of the label. */ > + add a1, a4, a1 /* Add them together to get the absolute address. */ > + > + mov a4, #0 /* Used to be init. */ > + push { a4 } /* Used to be fini. */ > + > + bl __libc_start_main > +# endif Nit: add /* # ifdef SHARED */ after 'endif' > #else > > mov a4, #0 /* Used to init. */ > @@ -119,9 +130,14 @@ _start: > > #ifdef PIC > .align 2 > +# ifdef SHARED > .L_GOT: > .word _GLOBAL_OFFSET_TABLE_ - .L_GOT > .word main(GOT) > +# else > +.L_main_rel: > + .word main - .L_main_rel > +# endif OK Cheers, Yury
On 29/04/26 07:00, Yury Khrustalev wrote: > On Fri, Apr 24, 2026 at 10:49:23AM -0300, Adhemerval Zanella wrote: >> It requires proper gcc support [1], and without proper compiler support >> the arm configure disable static-pie support. >> >> The start.S requires some adjustment to avoid loading main from >> the GOT. >> >> Checked on arm-linux-gnueabihf with and without the gcc patch applied. > > Could you share how you tested it? Perhaps it makes sense to add a test > that is supposed to link successfully as a static PIE? The easiest way to check the static-pie is to bootstrap a toolchain with the gcc patch, otherwise you will need to hack glibc testing to pass the same flags when -static-pie is used. The new configure.ac piece checks whether compiler does support it, similar on how it was done recently for loongarch and riscv. If static-pie is properly support (i.e, if compiler driver issues the linker with correct flags and generates a ET_DYN without PT_INTERP with the expect RELATIVE relocation), all static binaries will be built as static-pie and it will fail to load without the start.S fix. > > The patch seems OK but I struggle to test it properly. > >> >> [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598610.html >> --- >> NEWS | 3 +++ >> sysdeps/arm/configure | 52 ++++++++++++++++++++++++++++++++++++++++ >> sysdeps/arm/configure.ac | 29 ++++++++++++++++++++++ >> sysdeps/arm/start.S | 16 +++++++++++++ >> 4 files changed, 100 insertions(+) >> >> diff --git a/NEWS b/NEWS >> index eac9322161..6a45bb06ff 100644 >> --- a/NEWS >> +++ b/NEWS >> @@ -18,6 +18,9 @@ Major new features: >> >> * New locale added: hrx_BR (Hunsrik language spoken in Brazil). >> >> +* Static PIE is ow support for arm-*-linux-gnueabi. It requires toolchain > Nit: s/ow support/now supported/g > >> + support to correctly set the expected linker options. >> + >> Deprecated and removed features, and other changes affecting compatibility: >> >> * Although malloc and related functions currently return pointers >> diff --git a/sysdeps/arm/configure b/sysdeps/arm/configure >> index 935e022c74..b964c3917a 100644 >> --- a/sysdeps/arm/configure >> +++ b/sysdeps/arm/configure >> >> ... >> > > OK > >> diff --git a/sysdeps/arm/configure.ac b/sysdeps/arm/configure.ac >> index cd00ddc9d9..0c4f0f0de8 100644 >> --- a/sysdeps/arm/configure.ac >> +++ b/sysdeps/arm/configure.ac >> @@ -1,6 +1,35 @@ >> GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. >> # Local configure fragment for sysdeps/arm. >> >> +dnl Test if the foolchain supports static PIE, the -static-pie should not only >> +dnl be accepted, but also generate a ET_DYN without a INTERP entry. >> +AC_CACHE_CHECK([if compiler support static PIE], >> +libc_cv_static_pie_on_arm, [ >> +cat > conftest.S <<\EOF >> +.text >> +.global _start >> +.type _start,#function >> +_start: >> + >> +.data >> +.align 2 >> +ptr: >> + /* This shoul produce an R_ARM_RELATIVE. */ >> + .word _start >> +EOF >> + >> + libc_cv_static_pie_on_arm=no >> + if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S]) \ >> + && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep -q R_ARM_RELATIVE]) \ >> + && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest | grep -q INTERP]) >> + then >> + libc_cv_static_pie_on_arm=yes >> + fi >> + rm -rf conftest* ]) >> +if test "$libc_cv_static_pie_on_arm" = yes; then >> + AC_DEFINE(SUPPORT_STATIC_PIE) >> +fi >> + > > OK > >> diff --git a/sysdeps/arm/start.S b/sysdeps/arm/start.S >> index a7e62b3934..68e032ef4d 100644 >> --- a/sysdeps/arm/start.S >> +++ b/sysdeps/arm/start.S >> @@ -90,6 +90,7 @@ _start: >> push { a1 } >> >> #ifdef PIC >> +# ifdef SHARED >> ldr sl, .L_GOT >> adr a4, .L_GOT >> add sl, sl, a4 >> @@ -103,6 +104,16 @@ _start: >> /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ >> /* Let the libc call main and exit with its return code. */ >> bl __libc_start_main(PLT) >> +# else >> + ldr a1, .L_main_rel /* Load the relative offset of main. */ >> + adr a4, .L_main_rel /* Load the actual runtime address of the label. */ >> + add a1, a4, a1 /* Add them together to get the absolute address. */ >> + >> + mov a4, #0 /* Used to be init. */ >> + push { a4 } /* Used to be fini. */ >> + >> + bl __libc_start_main >> +# endif > > Nit: add /* # ifdef SHARED */ after 'endif' > >> #else >> >> mov a4, #0 /* Used to init. */ >> @@ -119,9 +130,14 @@ _start: >> >> #ifdef PIC >> .align 2 >> +# ifdef SHARED >> .L_GOT: >> .word _GLOBAL_OFFSET_TABLE_ - .L_GOT >> .word main(GOT) >> +# else >> +.L_main_rel: >> + .word main - .L_main_rel >> +# endif > > OK > > Cheers, > Yury >
> From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> > Sent: Wednesday, April 29, 2026 21:36 > To: Yury Khrustalev <yury.khrustalev@arm.com> > Cc: libc-alpha@sourceware.org <libc-alpha@sourceware.org>; 정재윤/Task Leader/SW Platform(연)선행Platform개발실 Lightweight System Task <jaeyoon.jung@lge.com>; Sam James <sam@gentoo.org> > Subject: Re: [PATCH] arm: Enable static-pie support (BZ 34098) > > > > On 29/04/26 07:00, Yury Khrustalev wrote: > > On Fri, Apr 24, 2026 at 10:49:23AM -0300, Adhemerval Zanella wrote: > >> It requires proper gcc support [1], and without proper compiler support > >> the arm configure disable static-pie support. > >> > >> The start.S requires some adjustment to avoid loading main from > >> the GOT. > >> > >> Checked on arm-linux-gnueabihf with and without the gcc patch applied. > > > > Could you share how you tested it? Perhaps it makes sense to add a test > > that is supposed to link successfully as a static PIE? > > The easiest way to check the static-pie is to bootstrap a toolchain with > the gcc patch, otherwise you will need to hack glibc testing to pass the > same flags when -static-pie is used. > In my case, I verified it in my Yocto build system with two patches applied to the corresponding recipes in oe-core. The test result was successful as shared in https://sourceware.org/bugzilla/show_bug.cgi?id=34098. I'm also considering to send those patches to oe-core once this patch gets accepted and merged. Best regards, --- Jaeyoon Jung Software Platform Lab. / Corporate R&D / LG Electronics Inc.
On Wed, Apr 29, 2026 at 01:01:19PM +0000, Jaeyoon Jung wrote: > > From:�Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> > > Sent:�Wednesday, April 29, 2026 21:36 > > To:�Yury Khrustalev <yury.khrustalev@arm.com> > > Cc:�libc-alpha@sourceware.org <libc-alpha@sourceware.org>; Jaeyoon Jung <jaeyoon.jung@lge.com>; Sam James <sam@gentoo.org> > > Subject:�Re: [PATCH] arm: Enable static-pie support (BZ 34098) > > � > > > > > > On 29/04/26 07:00, Yury Khrustalev wrote: > > > On Fri, Apr 24, 2026 at 10:49:23AM -0300, Adhemerval Zanella wrote: > > >> It requires proper gcc support [1], and without proper compiler support > > >> the arm configure disable static-pie support. > > >> > > >> The start.S requires some adjustment to avoid loading main from > > >> the GOT. > > >> > > >> Checked on arm-linux-gnueabihf with and without the gcc patch applied. > > > > > > Could you share how you tested it? Perhaps it makes sense to add a test > > > that is supposed to link successfully as a static PIE? > > > > The easiest way to check the static-pie is to bootstrap a toolchain with > > the gcc patch, otherwise you will need to hack glibc testing to pass the > > same flags when -static-pie is used. > > > > In my case, I verified it in my Yocto build system with two patches applied > to the corresponding recipes in oe-core. The test result was successful as > shared in https://sourceware.org/bugzilla/show_bug.cgi?id=34098. > I'm also considering to send those patches to oe-core once this patch gets > accepted and merged. > > Thanks both! In this case, LGTM Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com> Adhemerval, feel free to push after fixing the two minor things I raised in my previous email. Thanks, Yury
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes: > It requires proper gcc support [1], and without proper compiler support > the arm configure disable static-pie support. > > The start.S requires some adjustment to avoid loading main from > the GOT. > > Checked on arm-linux-gnueabihf with and without the gcc patch applied. > > [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598610.html Thanks. I'll handle the GCC side soon. Reviewed-by: Sam James <sam@gentoo.org> > --- > NEWS | 3 +++ > sysdeps/arm/configure | 52 ++++++++++++++++++++++++++++++++++++++++ > sysdeps/arm/configure.ac | 29 ++++++++++++++++++++++ > sysdeps/arm/start.S | 16 +++++++++++++ > 4 files changed, 100 insertions(+) > > diff --git a/NEWS b/NEWS > index eac9322161..6a45bb06ff 100644 > --- a/NEWS > +++ b/NEWS > @@ -18,6 +18,9 @@ Major new features: > > * New locale added: hrx_BR (Hunsrik language spoken in Brazil). > > +* Static PIE is ow support for arm-*-linux-gnueabi. It requires > toolchain now supported > + support to correctly set the expected linker options. > + > Deprecated and removed features, and other changes affecting compatibility: > > * Although malloc and related functions currently return pointers > diff --git a/sysdeps/arm/configure b/sysdeps/arm/configure > index 935e022c74..b964c3917a 100644 > --- a/sysdeps/arm/configure > +++ b/sysdeps/arm/configure > @@ -1,6 +1,58 @@ > # This file is generated from configure.ac by Autoconf. DO NOT EDIT! > # Local configure fragment for sysdeps/arm. > > +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler support static PIE" >&5 > +printf %s "checking if compiler support static PIE... " >&6; } > +if test ${libc_cv_static_pie_on_arm+y} > +then : > + printf %s "(cached) " >&6 > +else case e in #( > + e) > +cat > conftest.S <<\EOF > +.text > +.global _start > +.type _start,#function > +_start: > + > +.data > +.align 2 > +ptr: > + /* This shoul produce an R_ARM_RELATIVE. */ > + .word _start > +EOF > + > + libc_cv_static_pie_on_arm=no > + if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S' > + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 > + (eval $ac_try) 2>&5 > + ac_status=$? > + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > + test $ac_status = 0; }; } \ > + && { ac_try='LC_ALL=C $READELF -Wr conftest | grep -q R_ARM_RELATIVE' > + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 > + (eval $ac_try) 2>&5 > + ac_status=$? > + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > + test $ac_status = 0; }; } \ > + && ! { ac_try='LC_ALL=C $READELF -Wl conftest | grep -q INTERP' > + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 > + (eval $ac_try) 2>&5 > + ac_status=$? > + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > + test $ac_status = 0; }; } > + then > + libc_cv_static_pie_on_arm=yes > + fi > + rm -rf conftest* ;; > +esac > +fi > +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie_on_arm" >&5 > +printf "%s\n" "$libc_cv_static_pie_on_arm" >&6; } > +if test "$libc_cv_static_pie_on_arm" = yes; then > + printf "%s\n" "#define SUPPORT_STATIC_PIE 1" >>confdefs.h > + > +fi > + > # We check to see if the compiler and flags are > # selecting the hard-float ABI and if they are then > # we set libc_cv_arm_pcs_vfp to yes which causes > diff --git a/sysdeps/arm/configure.ac b/sysdeps/arm/configure.ac > index cd00ddc9d9..0c4f0f0de8 100644 > --- a/sysdeps/arm/configure.ac > +++ b/sysdeps/arm/configure.ac > @@ -1,6 +1,35 @@ > GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. > # Local configure fragment for sysdeps/arm. > > +dnl Test if the foolchain supports static PIE, the -static-pie should not only > +dnl be accepted, but also generate a ET_DYN without a INTERP entry. > +AC_CACHE_CHECK([if compiler support static PIE], > +libc_cv_static_pie_on_arm, [ > +cat > conftest.S <<\EOF > +.text > +.global _start > +.type _start,#function > +_start: > + > +.data > +.align 2 > +ptr: > + /* This shoul produce an R_ARM_RELATIVE. */ should > + .word _start > +EOF > + > + libc_cv_static_pie_on_arm=no > + if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S]) \ > + && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep -q R_ARM_RELATIVE]) \ > + && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest | grep -q INTERP]) > + then > + libc_cv_static_pie_on_arm=yes > + fi > + rm -rf conftest* ]) > +if test "$libc_cv_static_pie_on_arm" = yes; then > + AC_DEFINE(SUPPORT_STATIC_PIE) > +fi > + > # We check to see if the compiler and flags are > # selecting the hard-float ABI and if they are then > # we set libc_cv_arm_pcs_vfp to yes which causes > diff --git a/sysdeps/arm/start.S b/sysdeps/arm/start.S > index a7e62b3934..68e032ef4d 100644 > --- a/sysdeps/arm/start.S > +++ b/sysdeps/arm/start.S > @@ -90,6 +90,7 @@ _start: > push { a1 } > > #ifdef PIC > +# ifdef SHARED > ldr sl, .L_GOT > adr a4, .L_GOT > add sl, sl, a4 > @@ -103,6 +104,16 @@ _start: > /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ > /* Let the libc call main and exit with its return code. */ > bl __libc_start_main(PLT) > +# else > + ldr a1, .L_main_rel /* Load the relative offset of main. */ > + adr a4, .L_main_rel /* Load the actual runtime address of the label. */ > + add a1, a4, a1 /* Add them together to get the absolute address. */ > + > + mov a4, #0 /* Used to be init. */ > + push { a4 } /* Used to be fini. */ > + > + bl __libc_start_main > +# endif > #else > > mov a4, #0 /* Used to init. */ > @@ -119,9 +130,14 @@ _start: > > #ifdef PIC > .align 2 > +# ifdef SHARED > .L_GOT: > .word _GLOBAL_OFFSET_TABLE_ - .L_GOT > .word main(GOT) > +# else > +.L_main_rel: > + .word main - .L_main_rel > +# endif > #endif > > .cantunwind
On Apr 24 2026, Adhemerval Zanella wrote: > It requires proper gcc support [1], and without proper compiler support > the arm configure disable static-pie support. > > The start.S requires some adjustment to avoid loading main from > the GOT. > > Checked on arm-linux-gnueabihf with and without the gcc patch applied. This breaks the arm-main-in-dso test in mold, since it changes the relocation for main from R_ARM_GOT32 to R_ARM_REL32, and mold does not generate a PLT for the latter.
On 02/06/26 11:37, Andreas Schwab wrote: > On Apr 24 2026, Adhemerval Zanella wrote: > >> It requires proper gcc support [1], and without proper compiler support >> the arm configure disable static-pie support. >> >> The start.S requires some adjustment to avoid loading main from >> the GOT. >> >> Checked on arm-linux-gnueabihf with and without the gcc patch applied. > > This breaks the arm-main-in-dso test in mold, since it changes the > relocation for main from R_ARM_GOT32 to R_ARM_REL32, and mold does not > generate a PLT for the latter. > I recall I first followed aarch64 strategy to use __wrap_main for PIC && !SHARED, but the one I used ended in a simpler implementation. It seems that wrap one should be safe for different linkers.
diff --git a/NEWS b/NEWS index eac9322161..6a45bb06ff 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,9 @@ Major new features: * New locale added: hrx_BR (Hunsrik language spoken in Brazil). +* Static PIE is ow support for arm-*-linux-gnueabi. It requires toolchain + support to correctly set the expected linker options. + Deprecated and removed features, and other changes affecting compatibility: * Although malloc and related functions currently return pointers diff --git a/sysdeps/arm/configure b/sysdeps/arm/configure index 935e022c74..b964c3917a 100644 --- a/sysdeps/arm/configure +++ b/sysdeps/arm/configure @@ -1,6 +1,58 @@ # This file is generated from configure.ac by Autoconf. DO NOT EDIT! # Local configure fragment for sysdeps/arm. +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler support static PIE" >&5 +printf %s "checking if compiler support static PIE... " >&6; } +if test ${libc_cv_static_pie_on_arm+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) +cat > conftest.S <<\EOF +.text +.global _start +.type _start,#function +_start: + +.data +.align 2 +ptr: + /* This shoul produce an R_ARM_RELATIVE. */ + .word _start +EOF + + libc_cv_static_pie_on_arm=no + if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } \ + && { ac_try='LC_ALL=C $READELF -Wr conftest | grep -q R_ARM_RELATIVE' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } \ + && ! { ac_try='LC_ALL=C $READELF -Wl conftest | grep -q INTERP' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + libc_cv_static_pie_on_arm=yes + fi + rm -rf conftest* ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie_on_arm" >&5 +printf "%s\n" "$libc_cv_static_pie_on_arm" >&6; } +if test "$libc_cv_static_pie_on_arm" = yes; then + printf "%s\n" "#define SUPPORT_STATIC_PIE 1" >>confdefs.h + +fi + # We check to see if the compiler and flags are # selecting the hard-float ABI and if they are then # we set libc_cv_arm_pcs_vfp to yes which causes diff --git a/sysdeps/arm/configure.ac b/sysdeps/arm/configure.ac index cd00ddc9d9..0c4f0f0de8 100644 --- a/sysdeps/arm/configure.ac +++ b/sysdeps/arm/configure.ac @@ -1,6 +1,35 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. # Local configure fragment for sysdeps/arm. +dnl Test if the foolchain supports static PIE, the -static-pie should not only +dnl be accepted, but also generate a ET_DYN without a INTERP entry. +AC_CACHE_CHECK([if compiler support static PIE], +libc_cv_static_pie_on_arm, [ +cat > conftest.S <<\EOF +.text +.global _start +.type _start,#function +_start: + +.data +.align 2 +ptr: + /* This shoul produce an R_ARM_RELATIVE. */ + .word _start +EOF + + libc_cv_static_pie_on_arm=no + if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S]) \ + && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep -q R_ARM_RELATIVE]) \ + && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest | grep -q INTERP]) + then + libc_cv_static_pie_on_arm=yes + fi + rm -rf conftest* ]) +if test "$libc_cv_static_pie_on_arm" = yes; then + AC_DEFINE(SUPPORT_STATIC_PIE) +fi + # We check to see if the compiler and flags are # selecting the hard-float ABI and if they are then # we set libc_cv_arm_pcs_vfp to yes which causes diff --git a/sysdeps/arm/start.S b/sysdeps/arm/start.S index a7e62b3934..68e032ef4d 100644 --- a/sysdeps/arm/start.S +++ b/sysdeps/arm/start.S @@ -90,6 +90,7 @@ _start: push { a1 } #ifdef PIC +# ifdef SHARED ldr sl, .L_GOT adr a4, .L_GOT add sl, sl, a4 @@ -103,6 +104,16 @@ _start: /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ /* Let the libc call main and exit with its return code. */ bl __libc_start_main(PLT) +# else + ldr a1, .L_main_rel /* Load the relative offset of main. */ + adr a4, .L_main_rel /* Load the actual runtime address of the label. */ + add a1, a4, a1 /* Add them together to get the absolute address. */ + + mov a4, #0 /* Used to be init. */ + push { a4 } /* Used to be fini. */ + + bl __libc_start_main +# endif #else mov a4, #0 /* Used to init. */ @@ -119,9 +130,14 @@ _start: #ifdef PIC .align 2 +# ifdef SHARED .L_GOT: .word _GLOBAL_OFFSET_TABLE_ - .L_GOT .word main(GOT) +# else +.L_main_rel: + .word main - .L_main_rel +# endif #endif .cantunwind