bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ld: once multiple symbol definitions are allowed, both definitions e


From: Jim Wilson
Subject: Re: ld: once multiple symbol definitions are allowed, both definitions end up in the executable
Date: Tue, 17 Jan 2017 12:13:29 -0800

On Tue, Jan 17, 2017 at 6:56 AM, Pavel Shishpor
<address@hidden> wrote:
> Thanks a lot for the answer: it put me on the right track. The
> '-ffunction-sections' option works OK on toy examples though GNU linker
> crashed when I tried the following on real-life object files compiled with
> -ffunction-sections and -fdata-sections options enabled:
>
> for i in $object_files_original
> do
>         objcopy --weaken $i  # weaken symbols for linker not to complain
> about multiple definitions
> done
> ld.bfd -r --gc-sections -u external_symbol1...
> $object_files_with_replacement_fucntions $object_files_original -o
> combined.o
>
> ld.bfd: BFD (GNU Binutils) 2.27 assertion fail elflink.c:8380
> <repeated 6 times more>
>
> Any clues how to debug it?

You can try different GNU ld versions.  Maybe it works in an earlier
or later version.  In general, -ffunction-sections and -gc-sections
are not commonly used options.  So they may not be as reliable as most
other gcc/ld options.  Normally, I suggest trying gold, but I don't
know if it implements -gc-sections.  They don't bother to support some
of the less common BFD linker options.

Debugging this will require some knowledge of how bfd and the linker
works, which could take some time.  But in general, debugging this is
the same as most other programs, put a breakpoint at the assert, and
try to work your way backwards to figure out what went wrong.  If you
want us to debug this, then you have to file a bug report via bugzilla
that has a testcase that we can use to reproduce.

Speaking of which, the bug-gcc mailing list isn't really meant for
emailed bug reports.  It is where bugzilla sends email.  It is better
to ask a question on the main list, or to file a bug report into
bugzilla.

> Also I have not tried COMDAT magic: looks like there are no any external
> tweaks to put function to COMDAT sections but g++ decides on its own what
> should be go to COMDAT sections.

You are right.  I thought we had an attribute or something.  You might
be able to do this by using a section attribute to put it in a
linkonce section, but I'm not sure if that really works offhand.

In general, as I mentioned earlier, it is best to avoid duplicate
definitions to begin with, rather than try to fix them at link time.

Jim



reply via email to

[Prev in Thread] Current Thread [Next in Thread]