[Bug other/89856] New: `ld: warning: direct access to global weak symbol means the weak symbol cannot be overridden at runtime` using LTO with optimization and -fprofile-generate

zerolo at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Mar 27 18:08:00 GMT 2019


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

            Bug ID: 89856
           Summary: `ld: warning: direct access to global weak symbol
                    means the weak symbol cannot be overridden at runtime`
                    using LTO with optimization and -fprofile-generate
           Product: gcc
           Version: 7.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zerolo at gmail dot com
  Target Milestone: ---

Created attachment 46037
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46037&action=edit
Example triggering "This was likely caused by different translation units being
compiled with different visibility settings"

(Split off from #68771, and I'm also not sure which component to attach this
to)

Compiling the attached example with

g++-7 -shared -O1 -flto -fprofile-generate test.cpp -o test.dylib

causes the following warning:

ld: warning: direct access in function '__GLOBAL__sub_I_65535_0_test.cpp' from
file
'/var/folders/02/yl3m8d4d0397mk6dxn6dpcqw0000gp/T//ccaTTZJD.ltrans0.ltrans.o'
to global weak symbol '__ZGVZ19BroadcastFromMasterImEvPT_mE4bufs' from file
'/var/folders/02/yl3m8d4d0397mk6dxn6dpcqw0000gp/T//ccaTTZJD.ltrans0.ltrans.o'
means the weak symbol cannot be overridden at runtime. This was likely caused
by different translation units being compiled with different visibility
settings.

Whether this warning is accurate or not, what consequences it has, or whether
something that leads to this warning is off, is unclear.

Removing any of the options (either disabling optimization, or removing either
-flto or lfprofile-generate) makes the warning go away.

This is on Darwin (but according to Iain Sandoe also happens on Linux).


More information about the Gcc-bugs mailing list