This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Symbols defined via linker script: local or global?


Hello Alan,

On 07/07/16 14:26, Alan Modra wrote:
On Thu, Jul 07, 2016 at 07:56:19AM +0200, Sebastian Huber wrote:
sorry for the delay. I have now a test case. It seems to be related to the
--gc-sections option.
Indeed.  elf_gc_sweep_symbol is forcing the symbols local.  The
problem is that lang_gc_sections runs fairly early in the linking
process, before sections are laid out, and your script is defining
symbols inside output section statements.  Although
lang_do_assignments runs before lang_gc_sections, it doesn't descend
into output section statements.  That results in the assignments
"SC = .;" and "SD = .;" not being performed.  So SC, which was an
undefined symbol in your object file, stays undefined.  SD remains
unknown, until the "SF = SD;" assignment, where the reference makes it
an undefined symbol.  Somewhat oddly, this assignment doesn't put SF
into the symbol hash table (because the expression for its value
wasn't valid).  So when elf_gc_sweep_symbol runs, it sees SA and SB
defined, and SC, SD and SE undefined.  SF is unknown.  Even though SA,
SC and SE are referenced from your object file, their section is
discarded, and thus relocations in that section do not mark their
symbols.  elf_gc_sweep_symbol forces unmarked undefined symbols
local.

lang_do_assignments probably should descend into output section
statements, and all the fallout from not having a BFD section,
be fixed.


thanks for your analysis. It looks complicated, is this a bug or a feature? If its a bug, is it worth to fix or is my use case too exotic?

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]