[PATCH] D29273: [ELF] - Added partial support for --emit-relocs (no --gc-section case)

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 31 01:20:58 PST 2017


>> +# REQUIRES: x86
>> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
>> +# RUN: echo "SECTIONS { /DISCARD/ : { *(.debug*) } }" > %t.script
>> +# RUN: ld.lld --emit-relocs --script %t.script %t.o -o %t1
>> +# RUN: llvm-readobj -r %t1 | FileCheck %s
>> +
>> +# CHECK:      Relocations [
>> +# CHECK-NEXT: ]
>> +
>> +.section .debug_str,"MS", at progbits,1
>> +.Linfo_string0:
>> +  .asciz "AAA"
>> +
>> +.section  .debug_info,"", at progbits
>> +  .long .Linfo_string0
>
>This is better handled along the followup patch that adds gc, no?

But that is not about GC actually. It is about handling /DISCARD/ from script.
Honestly I am not sure we even need to support --gc-sections with --emit-relocs.
I did not met this combination in kernel yet. But the case above is real case from kernel.

>> Index: ELF/LinkerScript.cpp
>> ===================================================================
>> --- ELF/LinkerScript.cpp
>> +++ ELF/LinkerScript.cpp
>> @@ -262,6 +262,12 @@
>>    for (InputSectionBase<ELFT> *S : V) {
>>      S->Live = false;
>>      reportDiscarded(S);
>> +
>> +    // If we discard a section, we also should discard a dependent section.
>> +    InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S);
>> +    if (!IS || !IS->DependentSection || !IS->DependentSection->Live)
>> +      continue;
>> +    discard({IS->DependentSection});
>>    }
>>  }
>
>And this.

And without that piece of code, the testcase above just will crash.
So if we want to handle --gc-sections too, that is should be in other patch, but I
would keep this code for handling /DISCARD/ as it is not relative to GC.

>Cheers,
>Rafael


More information about the llvm-commits mailing list