This is the mail archive of the 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]

Fwd: Referring to a specific symbol in a static library with gold

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.

Thanks again!


On Thu, Aug 3, 2017 at 7:16 PM, Cary Coutant <> 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:
>   "musl/lib/libc.a(exit.o)"(.text.exit)
> should work. If you want something that will work in both linkers, try
> something like this:
>   "musl/lib/libc.a*exit.o*"(.text.exit)
> or just
>   "*exit.o*"(.text.exit)
> -cary

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