Bug 29514 - Need to use -fPIE not -fpie
Summary: Need to use -fPIE not -fpie
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: build (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 2.37
Assignee: Richard Henderson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-23 18:35 UTC by Richard Henderson
Modified: 2022-08-29 20:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
patch (1.27 KB, patch)
2022-08-23 21:06 UTC, Richard Henderson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Henderson 2022-08-23 18:35:11 UTC
In Makeconfig, similar to "pic-ccflag = -fPIC", the default
for pie-ccflag should be '-fPIE' not '-fpie'.

Otherwise, large projects using -static-pie may see, e.g.

/usr/lib/gcc/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/lib/../lib/libc.a(init-first.o): in function `__libc_init_first':
(.text+0x10): relocation truncated to fit: R_AARCH64_LD64_GOTPAGE_LO15 against symbol `__environ' defined in .bss section in /usr/lib/gcc/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/lib/../lib/libc.a(environ.o)
/usr/bin/ld: (.text+0x10): warning: too many GOT entries for -fpic, please recompile with -fPIC
Comment 1 Florian Weimer 2022-08-23 19:04:38 UTC
Seems reasonable. Are you going to send a patch? Thanks.
Comment 2 Carlos O'Donell 2022-08-23 19:11:44 UTC
(In reply to Florian Weimer from comment #1)
> Seems reasonable. Are you going to send a patch? Thanks.

1049 # This can be changed by a sysdep makefile
1050 pic-ccflag = -fPIC
1051 # This one should always stay like this unless there is a very good reason.
1052 PIC-ccflag = -fPIC
1053 endif
1054 # This can be changed by a sysdep makefile
1055 pie-ccflag = -fpie

Yes, for pic-ccflag we use -fPIC, but for pie-ccflags we only use -fPIE.

These should be consistent one way or the other, and I wonder if that's a per-architecture choice that depends on the choices the compiler makes to support the larger code model.

A high quality submission should discuss the visible code generation changes that the change brings.
Comment 3 Richard Henderson 2022-08-23 21:06:32 UTC
Created attachment 14291 [details]
patch
Comment 4 Richard Henderson 2022-08-29 20:39:54 UTC
commit 51231c469b49fb3837590f40a93f88db9a20bb86
Author: Richard Henderson <richard.henderson@linaro.org>
Date:   Tue Aug 23 13:49:23 2022 -0700

    Makeconfig: Set pie-ccflag to -fPIE by default [BZ# 29514]
    
    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.
    
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
    Tested-by: Carlos O'Donell <carlos@redhat.com>