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: how to link a section in specific .o inside .a via linker script?


> I don't know and I haven't tried it, but did you try it like:
>
>     .text : { /lib/libc.a(bar.o(.text)) }
>
>...since the .text is a section of bar.o, not of libc.a?

Thanks for the suggestion. Unfortunately it doesn't work. I've been
reading through ldgram.y and ldlang.c and there just doesn't seem to
be support for this level of specificity.

I've been playing around with an experimental patch to fix this, where
there is a new (admittedly ugly) MEMBER operator in the linker script
that lets you specify a pair of a .a and .o file, that you can use in
place of any normal (possibly wildcarded) filename, e.g in my case:

    /* Only get .text section from bar.o inside foo.a */
    .text : { MEMBER(foo.a , bar.o)(.text) }

or even:

    /* Only get .text section from either bar.o or baz.o inside foo.a */
    .text : { MEMBER(foo.a , bar.o baz.o)(.text) }

The MEMBER operator produces a 'wildcard_spec' just like a normal
filename would, but it fills in a new 'struct name_list' field on the
wildcard_spec that, if non-null, restricts the linker to only
considering the specified members in the archive.

I've never looked at this part of the ld sources before, and I admit
I'm doing a lot of guesswork in the implementation, so I'd be happy to
hear any suggestions from someone familiar with the code.

-Mat


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