<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Aug 31, 2016 at 2:57 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I don't think it is that overkill because this is non-intrusive. Most parts of the linker can be agnostic on the presence of the -b feature with that approach.</div><div class=""><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 31, 2016 at 12:28 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Creating an ELF file in memory seems way more than what is needed.<br>
Even if we had a generic ELF writer in LLVM it would probably be an<br>
overkill to use it for this.<br>
<br>
Cheers,<br>
Rafael<br></blockquote></div></div></div></div></blockquote><div><br></div><div>I agree with Rui here. I looked at what it would take to do it without creating an ELF file and it ends up touching a lot of code. Using the existing ELF machinery makes this a very isolated change for a special case feature. However if you see a simple way to implement it without ELF I'm fine with doing so.</div><div><br></div><div>- Michael Spencer<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
On 30 August 2016 at 21:15, Rui Ueyama via llvm-commits<br>
<div><div><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
> ruiu added inline comments.<br>
><br>
> ================<br>
> Comment at: ELF/Driver.cpp:500<br>
> @@ +499,3 @@<br>
> +    case OPT_script:<br>
> +      addFile(Arg->getValue(), true);<br>
> +      break;<br>
> ----------------<br>
> Bigcheese wrote:<br>
>> ruiu wrote:<br>
>> > I'd directly call `readLinkerScript` if OPT_script. It should allows you to remove the second parameter from `addFile`.<br>
>> I was looking at that, but then I'd have to copy:<br>
>><br>
>><br>
>> ```<br>
>>   if (Config->Verbose)<br>
>>     outs() << Path << "\n";<br>
>><br>
>>   Optional<MemoryBufferRef> Buffer = readFile(Path);<br>
>>   if (!Buffer.hasValue())<br>
>>     return;<br>
>>   MemoryBufferRef MBRef = *Buffer;<br>
>> ```<br>
>><br>
>> Which seems like more complexity than adding a param.<br>
> Ah right. I'm fine with your change.<br>
><br>
> ================<br>
> Comment at: ELF/InputFiles.cpp:714<br>
> @@ +713,3 @@<br>
> +std::unique_ptr<InputFile> BinaryFile::createELF() {<br>
> +  SimpleELFWriter<ELFT> ELF(ET_REL, Config->EMachine);<br>
> +  auto DataSec = ELF.addSection(".data");<br>
> ----------------<br>
> Bigcheese wrote:<br>
>> ruiu wrote:<br>
>> > Can you move all these details into SimpleELFWriter so that we can just do something like<br>
>> ><br>
>> >   std::vector<uint8_t> Buf = createELFFromBinary(MB);<br>
>> >   return createELFFile<ObjectFile>(Memo<wbr>ryBufferRef(Buf, MB.getBufferIdentifier()));<br>
>> ><br>
>> If the concern is just having this much code in InputFile.cpp I'm fine with moving it somewhere else and calling it from here.<br>
>><br>
>> As for moving the code into SimpleELFWriter, I would rather keep SimpleELFWriter simple and not mix responsibilities. I plan to extend/refactor SimpleELFWriter to LLVMObject at some point and use it for final ELF emission for MC, split dwarf, objcopy (maybe), etc.<br>
>><br>
>> This was extracted (and reduced) from our internal version of the linker which has need of it elsewhere. So I'm already at 3 active uses of this code including this patch.<br>
> My concern was mostly about the amount of code you added to this file. What we want to do here is to wrap a binary blob with an ELF header, and we are not interested in the details, so I wanted to move all these details to other file.<br>
><br>
> I see a room to simplify the writer thing, but as long as it is encapsulated into one file, we can improve the implementation independently from other file.<br>
><br>
> ================<br>
> Comment at: ELF/SimpleELFWriter.h:31<br>
> @@ +30,3 @@<br>
> +public:<br>
> +  SimpleELFWriter(std::uint16_t Type, std::uint16_t Machine) {<br>
> +    memcpy(Header.e_ident, "\177ELF", 4);<br>
> ----------------<br>
> Please create a .cpp file and move the definitions to that file.<br>
><br>
><br>
> <a href="https://reviews.llvm.org/D24060" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2406<wbr>0</a><br>
><br>
><br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>