https://sourceware.org/bugzilla/show_bug.cgi?id=25618
Bug ID: 25618 Summary: use of gcc lto breaks --exclude-libs Product: binutils Version: 2.34 Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: sergeev917 at gmail dot com Target Milestone: --- Created attachment 12329 --> https://sourceware.org/bugzilla/attachment.cgi?id=12329&action=edit source files and shell validation script (Originally reported to GCC bug tracker: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93980) The apparent issue is that with LTO disabled -Wl,--exclude-libs,ALL flag works as intended, but with -flto -- symbols from linked archives are not hidden anymore. The issue is easily reproduced with about 10 lines of code with no std libs involved. The reproducer consists of a static library "foo" and a shared library "bar" that links with "foo" (and we would like to hide "foo" symbols in "bar"). foo.h: #pragma once __attribute__((visibility("default"))) int foo(); foo.cc: #include "foo.h" int foo() { return 100; } bar.h: #pragma once __attribute__((visibility("default"))) int bar(); bar.cc: #include "bar.h" #include "foo.h" int bar() { return foo(); } Build commands: g++ -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -flto -c foo.cc -o .foo.o ar qc .foo.a .foo.o g++ -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -flto -c bar.cc -o .bar.o g++ -Wl,--exclude-libs,ALL -flto -shared -o libbar.so .bar.o .foo.a readelf --dyn-syms --wide libbar.so | c++filt The last command produces both bar() and foo() -- that is, foo() is not hidden. Replacing -flto with -fno-lto gives only bar(), which is the expected result. The issue is present when using both ld.bfd and ld.gold (ie -fuse-ld=gold). -- $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-9.2.0-r4/work/gcc-9.2.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/9.2.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/python --enable-languages=c,c++,go,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --disable-nls --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.2.0-r4 p5' --disable-esp --enable-libstdcxx-time --with-build-config=bootstrap-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --with-multilib-list=m64 --disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libmudflap --disable-libssp --disable-systemtap --enable-vtable-verify --enable-lto --without-isl --enable-default-pie --enable-default-ssp Thread model: posix gcc version 9.2.0 (Gentoo 9.2.0-r4 p5) $ ld -v GNU ld (Gentoo 2.34 p1) 2.34.0 -- You are receiving this mail because: You are on the CC list for the bug.