This is the mail archive of the
mailing list for the binutils project.
Fwd: Referring to a specific symbol in a static library with gold
- From: Pierre Olivier <polivier at vt dot edu>
- To: Binutils <binutils at sourceware dot org>
- Date: Thu, 3 Aug 2017 21:17:38 -0400
- Subject: Fwd: Referring to a specific symbol in a static library with gold
- Authentication-results: sourceware.org; auth=none
- References: <CANXd-Z-RNq_XMm6GuhvkYQwT=3B0_8oWFS2vjVMLt8BWnha4tQ@mail.gmail.com> <CAJimCsE33JHT2LUvK31gk4hRW0L8-Pjg-zXHRQGd9jZMKgU9gQ@mail.gmail.com> <CANXd-Z8-eELP3JxJ5Qh6wemVXGgMFc9GEX8RFADVHZYjvi8Phg@mail.gmail.com>
Thanks a lot Cary, your suggestion of using the quotes worked
perfectly. I previously tried using the parenthesis and as I did not
thought about quoting the spelling, I got a parsing error from gold.
Thanks also for the clarification about -ffunctions-sections, the
static musl libc.a is indeed compiled with this option.
On Thu, Aug 3, 2017 at 7:16 PM, Cary Coutant <email@example.com> wrote:
> > When laying out symbols in the address space using a linker script, ld allows to
> > refer to a specific symbol coming from a specific object file inside a static
> > library with the following syntax:
> > archive.a:object_file.o(.section.symbol_name)
> That isn't quite what that syntax means. When you see
> ".section.symbol_name" in the linker script (or in a readelf or
> objdump list of sections), that is the whole name of the section, and
> you'll only see sections with names like that if you use the
> -ffunction-sections option when compiling. Given that your script
> works with ld, and if you just use the full filename wild card with
> gold, it looks like your musl libraries were indeed compiled with
> -ffunction-sections, but that's not something you can always assume is
> true for system libraries. So the linker isn't really searching for a
> section named ".text" that defines a symbol named "exit" -- instead,
> it's simply looking for a section named ".text.exit". Subtle
> difference, but you should be aware of it.
> > Now, while neither of these work with gold:
> > musl/lib/libc.a:exit.o(.text.exit);
> > musl/lib/libc.a(.text.exit);
> > This works:
> > *(.text.exit);
> > Is that a missing feature in gold? or am I doing something wrong, maybe there is
> > another way to refer to a specific symbol of a specific object file in an
> > archive using gold?
> If you look at the resulting -Map output file, I suspect you'll see
> the name of the object file is written as "musl/lib/libc.a(exit.o)".
> That's the spelling you need to use in the script, and because of the
> parentheses, you need to quote it. This:
> should work. If you want something that will work in both linkers, try
> something like this:
> or just