Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 940709 - sys-libs/glibc: fails to link with --gc-sections in LDFLAGS
Summary: sys-libs/glibc: fails to link with --gc-sections in LDFLAGS
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-03 10:59 UTC by Holger Hoffstätte
Modified: 2024-10-07 16:00 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Full build log (build.log.xz,9.68 KB, application/x-xz)
2024-10-03 11:00 UTC, Holger Hoffstätte
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Holger Hoffstätte 2024-10-03 10:59:58 UTC
Building glibc fails with -ffunction-sections/-fdata-sctions in CFLAGS and --gc-sections in LDFLAGS:

x86_64-pc-linux-gnu-gcc -m64 -pipe -march=znver2 -O2 -fcf-protection=none -Wl,-O1,--as-needed,--gc-sections,-z,now,-z,pack-relative-relocs -nostdlib -nostartfiles -r -o /tmp/portage/sys-libs/glibc-2.40-r3/work/build-amd64-x86_64-pc-linux-gnu-nptl/csu/crt1.o /tmp/portage/sys-libs/glibc-2.40-r3/work/build-amd64-x86_64-pc-linux-gnu-nptl/csu/start.o /tmp/portage/sys-libs/glibc-2.40-r3/work/build-amd64-x86_64-pc-linux-gnu-nptl/csu/abi-note.o /tmp/portage/sys-libs/glibc-2.40-r3/work/build-amd64-x86_64-pc-linux-gnu-nptl/csu/init.o /tmp/portage/sys-libs/glibc-2.40-r3/work/build-amd64-x86_64-pc-linux-gnu-nptl/csu/static-reloc.o
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: --gc-sections requires a defined symbol root specified by -e or -u


Reproducible: Always

Steps to Reproduce:
1. add -fdata-sections -ffunction-sections to CFLAGS, --gc-sections to LDFLAGS
2. try to build glibc
3. failure



Reporting it here after consultation with sam on IRC.
It seems that CFLAGS are filtered and -fdata-sections -ffunction-sections are removed, but LDFLAGS is unfiltered and therefore --gc-sections cannot work either.
Comment 1 Holger Hoffstätte 2024-10-03 11:00:41 UTC
Created attachment 904820 [details]
Full build log
Comment 2 Larry the Git Cow gentoo-dev 2024-10-07 15:55:59 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fbe427b18343c5ad45bc2fd56ae691f1c95295ff

commit fbe427b18343c5ad45bc2fd56ae691f1c95295ff
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-10-07 15:53:11 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-10-07 15:54:58 +0000

    sys-libs/glibc: filter -Wl,--gc-sections
    
    This fails to link when building static-reloc.o but it's broken in other
    ways too -- amonakov points out that glibc's linker scripts aren't
    ready for gc-sections (odd runtime side-effects like I/O flushing at exit
    not occurring), see PR21557 comment 0 for it being mentioned as an aside.
    
    Thanks to holgerh for reporting.
    
    Closes: https://bugs.gentoo.org/940709
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-libs/glibc/glibc-2.19-r3.ebuild  | 5 +++++
 sys-libs/glibc/glibc-2.31-r7.ebuild  | 5 +++++
 sys-libs/glibc/glibc-2.32-r8.ebuild  | 5 +++++
 sys-libs/glibc/glibc-2.33-r14.ebuild | 5 +++++
 sys-libs/glibc/glibc-2.34-r14.ebuild | 5 +++++
 sys-libs/glibc/glibc-2.35-r11.ebuild | 5 +++++
 sys-libs/glibc/glibc-2.36-r8.ebuild  | 5 +++++
 sys-libs/glibc/glibc-2.37-r10.ebuild | 5 +++++
 sys-libs/glibc/glibc-2.38-r13.ebuild | 5 +++++
 sys-libs/glibc/glibc-2.39-r10.ebuild | 5 +++++
 sys-libs/glibc/glibc-2.39-r6.ebuild  | 5 +++++
 sys-libs/glibc/glibc-2.39-r9.ebuild  | 5 +++++
 sys-libs/glibc/glibc-2.40-r3.ebuild  | 5 +++++
 sys-libs/glibc/glibc-2.40-r4.ebuild  | 5 +++++
 sys-libs/glibc/glibc-9999.ebuild     | 5 +++++
 15 files changed, 75 insertions(+)