[v2,4/4] powerpc64: Enable static-pie

Message ID 20220228064052.3413334-5-amodra@gmail.com
State Deferred
Delegated to: Tulio Magno Quites Machado Filho
Headers
Series PowerPC64 static-pie |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Alan Modra Feb. 28, 2022, 6:40 a.m. UTC
  * sysdeps/powerpc/powerpc64/configure.ac (SUPPORT_STATIC_PIE): Define.
	(PI_STATIC_AND_HIDDEN): Define.
	* sysdeps/powerpc/powerpc64/configure: Regenerate.
  

Comments

Tulio Magno Quites Machado Filho April 8, 2022, 10:49 p.m. UTC | #1
Alan Modra via Libc-alpha <libc-alpha@sourceware.org> writes:

> 	* sysdeps/powerpc/powerpc64/configure.ac (SUPPORT_STATIC_PIE): Define.
> 	(PI_STATIC_AND_HIDDEN): Define.
> 	* sysdeps/powerpc/powerpc64/configure: Regenerate.

While the code in this patch is perfect, I'm slightly inclined to think its
merge should be delayed until the failures on both powerpc64-linux and
powerpc64le-linux are fixed.

Another option would be to restrict this code to powerpc64le-linux only,
although I haven't had the success you mentioned in the cover letter.

Anyway, in one of my tests in particular (powerpc64le-linux, GCC 8, Binutils
2.30, without --enable-static-pie) I noticed many tests failing.  I'm still
investigating what happened.
  
Alan Modra April 14, 2022, 1:16 a.m. UTC | #2
On Fri, Apr 08, 2022 at 07:49:05PM -0300, Tulio Magno Quites Machado Filho wrote:
> Alan Modra via Libc-alpha <libc-alpha@sourceware.org> writes:
> 
> > 	* sysdeps/powerpc/powerpc64/configure.ac (SUPPORT_STATIC_PIE): Define.
> > 	(PI_STATIC_AND_HIDDEN): Define.
> > 	* sysdeps/powerpc/powerpc64/configure: Regenerate.
> 
> While the code in this patch is perfect, I'm slightly inclined to think its
> merge should be delayed until the failures on both powerpc64-linux and
> powerpc64le-linux are fixed.
> 
> Another option would be to restrict this code to powerpc64le-linux only,
> although I haven't had the success you mentioned in the cover letter.
> 
> Anyway, in one of my tests in particular (powerpc64le-linux, GCC 8, Binutils
> 2.30, without --enable-static-pie) I noticed many tests failing.  I'm still
> investigating what happened.

binutils-2.30 is too old.  You'll find __rela_iplt_start and
__rela_iplt_end symbols being defined in PIEs.  Those symbols are
supposed to mark out IFUNC relocs in ET_EXEC static binaries.  Their
presence in ET_DYN static binaries is bad, especially since it seems
they have garbage values not pointing at the correct set of
relocations.  I suspect, but haven't checked, that the garbage values
are due to -z combreloc.  This bug in ld was fixed with commit
795e3bb7de9, so you'll need at least binutils-2.33 for static-pie.

I'll note that static-pie is enabled in glibc without any user
--enable-static-pie, ie. it is the default if SUPPORT_STATIC_PIE is
set.  SUPPORT_STATIC_PIE is enabled unconditionally for x86 and
aarch64 without any toolchain checks, and I foolishly followed that
precedent.  Likely x86 would fail the glibc testsuite all over the
place with an old binutils too.
  
Fangrui Song April 14, 2022, 3:42 a.m. UTC | #3
On 2022-04-14, Alan Modra via Libc-alpha wrote:
>On Fri, Apr 08, 2022 at 07:49:05PM -0300, Tulio Magno Quites Machado Filho wrote:
>> Alan Modra via Libc-alpha <libc-alpha@sourceware.org> writes:
>>
>> > 	* sysdeps/powerpc/powerpc64/configure.ac (SUPPORT_STATIC_PIE): Define.
>> > 	(PI_STATIC_AND_HIDDEN): Define.
>> > 	* sysdeps/powerpc/powerpc64/configure: Regenerate.
>>
>> While the code in this patch is perfect, I'm slightly inclined to think its
>> merge should be delayed until the failures on both powerpc64-linux and
>> powerpc64le-linux are fixed.
>>
>> Another option would be to restrict this code to powerpc64le-linux only,
>> although I haven't had the success you mentioned in the cover letter.
>>
>> Anyway, in one of my tests in particular (powerpc64le-linux, GCC 8, Binutils
>> 2.30, without --enable-static-pie) I noticed many tests failing.  I'm still
>> investigating what happened.
>
>binutils-2.30 is too old.  You'll find __rela_iplt_start and
>__rela_iplt_end symbols being defined in PIEs.  Those symbols are
>supposed to mark out IFUNC relocs in ET_EXEC static binaries.  Their
>presence in ET_DYN static binaries is bad, especially since it seems
>they have garbage values not pointing at the correct set of
>relocations.  I suspect, but haven't checked, that the garbage values
>are due to -z combreloc.  This bug in ld was fixed with commit
>795e3bb7de9, so you'll need at least binutils-2.33 for static-pie.

I think conditional definition of __rela_iplt_start depending on
-no-pie/-pie is inelegant: it makes __rela_iplt_start the only symbol
with -no-pie/-pie internal linker script difference.
-no-pie/-pie internal linker scripts could otherwise be very similar,
with just the image base difference.
  

Patch

diff --git a/sysdeps/powerpc/powerpc64/configure b/sysdeps/powerpc/powerpc64/configure
index fddea0355a..f19dd5578e 100644
--- a/sysdeps/powerpc/powerpc64/configure
+++ b/sysdeps/powerpc/powerpc64/configure
@@ -1,6 +1,12 @@ 
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/powerpc/powerpc64.
 
+$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
+
+
+$as_echo "#define SUPPORT_STATIC_PIE 1" >>confdefs.h
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for support for overlapping .opd entries" >&5
 $as_echo_n "checking for support for overlapping .opd entries... " >&6; }
 if ${libc_cv_overlapping_opd+:} false; then :
diff --git a/sysdeps/powerpc/powerpc64/configure.ac b/sysdeps/powerpc/powerpc64/configure.ac
index 1f3d54414c..7764a65822 100644
--- a/sysdeps/powerpc/powerpc64/configure.ac
+++ b/sysdeps/powerpc/powerpc64/configure.ac
@@ -1,6 +1,15 @@ 
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/powerpc/powerpc64.
 
+dnl It is possible to access static and hidden symbols in a position
+dnl independent way requiring no relocation on powerpc64.  The linker
+dnl edits medium and large model code that uses GOT/TOC entries (which
+dnl would require relocation) to r2 relative accesses.
+AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+dnl Static PIE is supported.
+AC_DEFINE(SUPPORT_STATIC_PIE)
+
 AC_CACHE_CHECK(for support for overlapping .opd entries,
 libc_cv_overlapping_opd, [dnl
 libc_cv_overlapping_opd=no