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

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

Do you have to know whether a MemoryBuffer was in a library or not during parsing that MemoryBuffer?

If not, we could just set a library name to a File in FileArchive::instantiateMember after we call _registry.parseFile.

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.

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.

Thanks Rui for the feedback.

I would settle for a derived class and the class would be called LinkerMemoryBuffer. I will send a patch for review soon.

Shankar Easwaran