Makeconfig: Set pie-ccflag to -fPIE by default [BZ# 29514]

Message ID 20220823204923.1969486-1-richard.henderson@linaro.org
State Committed
Commit 51231c469b49fb3837590f40a93f88db9a20bb86
Headers
Series Makeconfig: Set pie-ccflag to -fPIE by default [BZ# 29514] |

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

Richard Henderson Aug. 23, 2022, 8:49 p.m. UTC
  We should default to the larger code model, in order to support
larger applications built with -static -pie.  This should be
consistent with pic-ccflag, which defaults to -fPIC.

Remove the now redundant override from sysdeps/sparc/Makefile.
Note that -fno-pie and -fno-PIE have the same effect.

---

For aarch64, the code changes are small but significant:

 0000000000000000 <__libc_init_first>:
    0:  a9bd7bfd        stp     x29, x30, [sp, #-48]!
-   4:  90000003        adrp    x3, 0 <_GLOBAL_OFFSET_TABLE_>
-                       4: R_AARCH64_ADR_PREL_PG_HI21   _GLOBAL_OFFSET_TABLE_
+   4:  90000003        adrp    x3, 0 <__environ>
+                       4: R_AARCH64_ADR_GOT_PAGE       __environ
    8:  90000004        adrp    x4, 0 <__libc_init_first>
                        8: R_AARCH64_ADR_PREL_PG_HI21   .bss
    c:  910003fd        mov     x29, sp
   10:  f9400063        ldr     x3, [x3]
-                       10: R_AARCH64_LD64_GOTPAGE_LO15 __environ
+                       10: R_AARCH64_LD64_GOT_LO12_NC  __environ

In the small model, we are constrained to 15 bits of GOT, with a
single shared base, _GLOBAL_OFFSET_TABLE_.  In the large model,
each symbol has a page + offset pair.  For small functions like
this, where there are no other variable references to share the
common GOT pointer, there is no actual code change.

For s390x, I would expect changes similar to c64a10e54441, and
an eventual similar bug report if this were left unchanged.

For x86, ppc64 and riscv64, -fpie & -fPIE are identical.

r~

---
 Makeconfig             | 2 +-
 sysdeps/sparc/Makefile | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)
  

Comments

Carlos O'Donell Aug. 26, 2022, 9:22 p.m. UTC | #1
On 8/23/22 16:49, Richard Henderson via Libc-alpha wrote:
> We should default to the larger code model, in order to support
> larger applications built with -static -pie.  This should be
> consistent with pic-ccflag, which defaults to -fPIC.
> 
> Remove the now redundant override from sysdeps/sparc/Makefile.
> Note that -fno-pie and -fno-PIE have the same effect.

This has been discussed downthread in the RESEND version.

Wilco seems happy with the patch.

This looks good to me too. Thanks for the provided analysis of the
generated code.

It is early in the release cycle and we can test this in the downstream
distributions e.g. Fedora Rawhide (s390x, ppc64le, aarch64, x86_64, i686)
and openSUSE Tumbleweed (likewise).

Passes pre-commit CI.

When it passes my internal tester I'll push this for Richard.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
 
> ---
> 
> For aarch64, the code changes are small but significant:
> 
>  0000000000000000 <__libc_init_first>:
>     0:  a9bd7bfd        stp     x29, x30, [sp, #-48]!
> -   4:  90000003        adrp    x3, 0 <_GLOBAL_OFFSET_TABLE_>
> -                       4: R_AARCH64_ADR_PREL_PG_HI21   _GLOBAL_OFFSET_TABLE_
> +   4:  90000003        adrp    x3, 0 <__environ>
> +                       4: R_AARCH64_ADR_GOT_PAGE       __environ
>     8:  90000004        adrp    x4, 0 <__libc_init_first>
>                         8: R_AARCH64_ADR_PREL_PG_HI21   .bss
>     c:  910003fd        mov     x29, sp
>    10:  f9400063        ldr     x3, [x3]
> -                       10: R_AARCH64_LD64_GOTPAGE_LO15 __environ
> +                       10: R_AARCH64_LD64_GOT_LO12_NC  __environ
> 
> In the small model, we are constrained to 15 bits of GOT, with a
> single shared base, _GLOBAL_OFFSET_TABLE_.  In the large model,
> each symbol has a page + offset pair.  For small functions like
> this, where there are no other variable references to share the
> common GOT pointer, there is no actual code change.
> 
> For s390x, I would expect changes similar to c64a10e54441, and
> an eventual similar bug report if this were left unchanged.
> 
> For x86, ppc64 and riscv64, -fpie & -fPIE are identical.
> 
> r~
> 
> ---
>  Makeconfig             | 2 +-
>  sysdeps/sparc/Makefile | 3 ---
>  2 files changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/Makeconfig b/Makeconfig
> index e78cf220af..f8164a0025 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -1052,7 +1052,7 @@ pic-ccflag = -fPIC
>  PIC-ccflag = -fPIC
>  endif
>  # This can be changed by a sysdep makefile
> -pie-ccflag = -fpie
> +pie-ccflag = -fPIE
>  no-pie-ccflag = -fno-pie
>  # This one should always stay like this unless there is a very good reason.
>  PIE-ccflag = -fPIE
> diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
> index 12c2c1b085..26b4a84606 100644
> --- a/sysdeps/sparc/Makefile
> +++ b/sysdeps/sparc/Makefile
> @@ -1,9 +1,6 @@
>  # The Sparc `long double' is a distinct type we support.
>  long-double-fcts = yes
>  
> -pie-ccflag = -fPIE
> -no-pie-ccflag = -fno-PIE
> -
>  ifeq ($(subdir),gmon)
>  sysdep_routines += sparc-mcount
>  endif
  

Patch

diff --git a/Makeconfig b/Makeconfig
index e78cf220af..f8164a0025 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -1052,7 +1052,7 @@  pic-ccflag = -fPIC
 PIC-ccflag = -fPIC
 endif
 # This can be changed by a sysdep makefile
-pie-ccflag = -fpie
+pie-ccflag = -fPIE
 no-pie-ccflag = -fno-pie
 # This one should always stay like this unless there is a very good reason.
 PIE-ccflag = -fPIE
diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
index 12c2c1b085..26b4a84606 100644
--- a/sysdeps/sparc/Makefile
+++ b/sysdeps/sparc/Makefile
@@ -1,9 +1,6 @@ 
 # The Sparc `long double' is a distinct type we support.
 long-double-fcts = yes
 
-pie-ccflag = -fPIE
-no-pie-ccflag = -fno-PIE
-
 ifeq ($(subdir),gmon)
 sysdep_routines += sparc-mcount
 endif