<div dir="ltr">Done, sorry about the delay I was on vacation for a few days.<br><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 3, 2017 at 8:22 AM Rafael Avila de Espindola <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Is anything blocking committing this?<br>
<br>
Cheers,<br>
Rafael<br>
<br>
Rafael Avila de Espindola <<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>> writes:<br>
<br>
> LGTM, thanks!<br>
><br>
> Cheers,<br>
> Rafael<br>
><br>
> Petr Hosek via Phabricator via llvm-commits<br>
> <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> writes:<br>
><br>
>> phosek created this revision.<br>
>> phosek added a project: lld.<br>
>> Herald added a subscriber: emaste.<br>
>><br>
>> Script commands are processed before unused synthetic sections are<br>
>> removed. Therefore, if a linker script matches one of these sections<br>
>> it'll get emitted as an empty output section because the logic for<br>
>> removing unused synthetic sections ignores script commands which<br>
>> could have already matched and captured one of these sections. This<br>
>> patch fixes that by also removing the unused synthetic sections from<br>
>> the script commands.<br>
>><br>
>><br>
>> Repository:<br>
>>   rL LLVM<br>
>><br>
>> <a href="https://reviews.llvm.org/D34800" rel="noreferrer" target="_blank">https://reviews.llvm.org/D34800</a><br>
>><br>
>> Files:<br>
>>   ELF/Writer.cpp<br>
>>   test/ELF/linkerscript/unused-synthetic.s<br>
>><br>
>><br>
>> Index: test/ELF/linkerscript/unused-synthetic.s<br>
>> ===================================================================<br>
>> --- /dev/null<br>
>> +++ test/ELF/linkerscript/unused-synthetic.s<br>
>> @@ -0,0 +1,18 @@<br>
>> +# REQUIRES: x86<br>
>> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o<br>
>> +# RUN: echo "SECTIONS { \<br>
>> +# RUN:    .got  : { *(.got) } \<br>
>> +# RUN:    .plt  : { *(.plt) } \<br>
>> +# RUN:    .text : { *(.text) } \<br>
>> +# RUN:  }" > %t.script<br>
>> +# RUN: ld.lld -shared -o %t.so --script %t.script %t.o<br>
>> +<br>
>> +# RUN: llvm-objdump -section-headers %t.so | FileCheck %s<br>
>> +# CHECK-NOT:  .got<br>
>> +# CHECK-NOT:  .plt<br>
>> +# CHECK:      .text<br>
>> +# CHECK-NEXT: .dynsym<br>
>> +<br>
>> +.global _start<br>
>> +_start:<br>
>> +  nop<br>
>> Index: ELF/Writer.cpp<br>
>> ===================================================================<br>
>> --- ELF/Writer.cpp<br>
>> +++ ELF/Writer.cpp<br>
>> @@ -1149,8 +1149,17 @@<br>
>>      SS->Live = false;<br>
>>      // If there are no other sections in the output section, remove it from the<br>
>>      // output.<br>
>> -    if (OS->Sections.empty())<br>
>> +    if (OS->Sections.empty()) {<br>
>>        V.erase(std::find(V.begin(), V.end(), OS));<br>
>> +      // Also remove script commands matching the output section.<br>
>> +      auto &Cmds = Script->Opt.Commands;<br>
>> +      auto I = std::remove_if(Cmds.begin(), Cmds.end(), [&](BaseCommand *Cmd) {<br>
>> +        if (auto *OSCmd = dyn_cast<OutputSectionCommand>(Cmd))<br>
>> +          return OSCmd->Sec == OS;<br>
>> +        return false;<br>
>> +      });<br>
>> +      Cmds.erase(I, Cmds.end());<br>
>> +    }<br>
>>    }<br>
>>  }<br>
>><br>
>><br>
>><br>
>> Index: test/ELF/linkerscript/unused-synthetic.s<br>
>> ===================================================================<br>
>> --- /dev/null<br>
>> +++ test/ELF/linkerscript/unused-synthetic.s<br>
>> @@ -0,0 +1,18 @@<br>
>> +# REQUIRES: x86<br>
>> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o<br>
>> +# RUN: echo "SECTIONS { \<br>
>> +# RUN:    .got  : { *(.got) } \<br>
>> +# RUN:    .plt  : { *(.plt) } \<br>
>> +# RUN:    .text : { *(.text) } \<br>
>> +# RUN:  }" > %t.script<br>
>> +# RUN: ld.lld -shared -o %t.so --script %t.script %t.o<br>
>> +<br>
>> +# RUN: llvm-objdump -section-headers %t.so | FileCheck %s<br>
>> +# CHECK-NOT:  .got<br>
>> +# CHECK-NOT:  .plt<br>
>> +# CHECK:      .text<br>
>> +# CHECK-NEXT: .dynsym<br>
>> +<br>
>> +.global _start<br>
>> +_start:<br>
>> +  nop<br>
>> Index: ELF/Writer.cpp<br>
>> ===================================================================<br>
>> --- ELF/Writer.cpp<br>
>> +++ ELF/Writer.cpp<br>
>> @@ -1149,8 +1149,17 @@<br>
>>      SS->Live = false;<br>
>>      // If there are no other sections in the output section, remove it from the<br>
>>      // output.<br>
>> -    if (OS->Sections.empty())<br>
>> +    if (OS->Sections.empty()) {<br>
>>        V.erase(std::find(V.begin(), V.end(), OS));<br>
>> +      // Also remove script commands matching the output section.<br>
>> +      auto &Cmds = Script->Opt.Commands;<br>
>> +      auto I = std::remove_if(Cmds.begin(), Cmds.end(), [&](BaseCommand *Cmd) {<br>
>> +        if (auto *OSCmd = dyn_cast<OutputSectionCommand>(Cmd))<br>
>> +          return OSCmd->Sec == OS;<br>
>> +        return false;<br>
>> +      });<br>
>> +      Cmds.erase(I, Cmds.end());<br>
>> +    }<br>
>>    }<br>
>>  }<br>
>><br>
>> _______________________________________________<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/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>