Shankar Easwaran
2014-Dec-03 05:24 UTC
[LLVMdev] [lld] need to figure out if file is an archive member and record more information...
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
Rui Ueyama
2014-Dec-03 05:39 UTC
[LLVMdev] [lld] need to figure out if file is an archive member and record more information...
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>
shankarke
2014-Dec-03 05:52 UTC
[LLVMdev] [lld] need to figure out if file is an archive member and record more information...
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> On Dec 2, 2014, at 23:40, Rui Ueyama [via LLVM] <ml-node+s1065342n74959h12 at n5.nabble.com> wrote: > > 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 <[hidden email]> 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 <[hidden email]> >>> 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 >>>> [hidden email] 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 > > > _______________________________________________ > LLVM Developers mailing list > [hidden email] http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > If you reply to this email, your message will be added to the discussion below: > http://llvm.1065342.n5.nabble.com/lld-need-to-figure-out-if-file-is-an-archive-member-and-record-more-information-tp74956p74959.html > To start a new topic under LLVM - Dev, email ml-node+s1065342n3h76 at n5.nabble.com > To unsubscribe from LLVM - Dev, click here. > NAML-- View this message in context: http://llvm.1065342.n5.nabble.com/lld-need-to-figure-out-if-file-is-an-archive-member-and-record-more-information-tp74956p74960.html Sent from the LLVM - Dev mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141202/8de1580f/attachment-0001.html>