https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93980

            Bug ID: 93980
           Summary: use of lto breaks -Wl,--exclude-libs
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sergeev917 at gmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 47934
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47934&action=edit
source files and shell validation script

The apparent issue is that with LTO disabled -Wl,--exclude-libs,ALL works as
intended, but with -flto -- symbols from linked archives are not hidden
anymore.

Since this particular issue involves more than one translation unit, I'm not
sure about the appropriate submission format. 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 commands produces both bar() and foo() -- that is, foo() is not
hidden. Replacing -flto with -fno-lto gives only bar().

--

$ 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)

Reply via email to