[LLVMdev] [lld] need to figure out if file is an archive member and record more information...

Rui Ueyama ruiu at google.com
Tue Dec 2 21:39:07 PST 2014


I think another way to do what you want is to add a new parameter to
parse() to propagate library file name to the parser, so that the parser
can determine if it's reading a library member. In this way you don't have
to make a derived class of MemoryBuffer.

One fault of that approach is the new parameter seems a bit arbitrary. In
order to get file name, you would call MemoryBuffer::getIdentifier, but in
order to get, you would use the second parameter of parse(). This is not
wrong but looks odd.

The other approach is to parse "filename(libraryname)" string returned from
MemoryBuffer::getIdentifier. But this is of course not robust. (What if we
have an object file whose file path contains parentheses?)

So I think making a derived class would be fine.

On Tue, Dec 2, 2014 at 9:24 PM, Shankar Easwaran <shankare at codeaurora.org>
wrote:

> On 12/2/2014 11:19 PM, Rui Ueyama wrote:
>
>> Do you have to know whether a MemoryBuffer was in a library or not during
>> parsing that MemoryBuffer?
>>
> Yes, I need to know that while parsing the buffer too.
>
>
>> If not, we could just set a library name to a File in
>> FileArchive::instantiateMember after we call _registry.parseFile.
>>
>> On Tue, Dec 2, 2014 at 9:08 PM, Shankar Easwaran <shankare at codeaurora.org
>> >
>> wrote:
>>
>>  Hi Nick,
>>>
>>> Currently the Reader doesnot have  a way to figure out that a file that
>>> is
>>> being parsed is part of an archive.
>>>
>>> For linker script support this is needed to match a rule that matches
>>> only
>>> if the file is from an archive library (or a member of an archive.
>>>
>>> For example :-
>>>
>>> SECTIONS {
>>> .myoutputsection : {
>>>      libc.a : { *(.text) }
>>>      printf.o : { *(.rodata) }
>>> }
>>> }
>>>
>>> The colon is used to denote an archive file or a member of an archive
>>> file
>>> and the rule says pick all text sections from members of libc.a that the
>>> linker uses for the current link step.
>>>
>>> Current Design
>>> ------------------------
>>> In the current design we record the archive file and the member in the
>>> memory buffer and identify using library(member) which is part of the
>>> MemoryBuffer.
>>>
>>> Information that needs to be recorded
>>> ---------------------------------------------------------
>>> The linker also needs to store the library and the member names
>>> separately
>>> as the linker script syntax allows to to distinguish library names and
>>> member names.
>>>
>>> Approach we could take is :-
>>> -------------------------------------------
>>> a) Rename MemoryBuffer to LinkerMemoryBuffer, which is a container for
>>> MemoryBuffer but with extra information(that contains the filename and an
>>> optional member name)
>>>
>>> If the member name is not empty, the Reader could treat this as an
>>> archive
>>> member.
>>>
>>> Comments ??
>>>
>>> Shankar Easwaran
>>>
>>> --
>>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted
>>> by the Linux Foundation
>>>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>>
>>>
>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted
> by the Linux Foundation
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141202/c20f9656/attachment.html>


More information about the llvm-dev mailing list