This is the mail archive of the
mailing list for the binutils project.
Re: Symbols defined via linker script: local or global?
- From: Alan Modra <amodra at gmail dot com>
- To: Sebastian Huber <sebastian dot huber at embedded-brains dot de>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Thu, 7 Jul 2016 21:56:22 +0930
- Subject: Re: Symbols defined via linker script: local or global?
- Authentication-results: sourceware.org; auth=none
- References: <email@example.com> <20160512121548.GB2111@bubble.grove.modra.org> <firstname.lastname@example.org> <20160512124228.GC2111@bubble.grove.modra.org> <57347A7F.email@example.com> <577DEF03.firstname.lastname@example.org>
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
lang_do_assignments probably should descend into output section
statements, and all the fallout from not having a BFD section,
Australia Development Lab, IBM