Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -367,17 +367,20 @@ return &InputSection::Discarded; case SHT_RELA: case SHT_REL: { + // Find the relocation target section and associate this + // section with it. Target can be discarded, for example + // if it is a duplicated member of SHT_GROUP section, we + // do not create or proccess relocatable sections then. + InputSectionBase *Target = getRelocTarget(Sec); + if (!Target) + return nullptr; + // This section contains relocation information. // If -r is given, we do not interpret or apply relocation // but just copy relocation sections to output. if (Config->Relocatable) return make>(this, &Sec, Name); - // Find the relocation target section and associate this - // section with it. - InputSectionBase *Target = getRelocTarget(Sec); - if (!Target) - return nullptr; if (Target->FirstRelocation) fatal(toString(this) + ": multiple relocation sections to one section are not supported"); Index: lld/trunk/test/ELF/relocation-group.test =================================================================== --- lld/trunk/test/ELF/relocation-group.test +++ lld/trunk/test/ELF/relocation-group.test @@ -0,0 +1,43 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: ld.lld %t.o %t.o -o %t -r +# RUN: llvm-readobj -s %t.o | FileCheck %s + +# CHECK: Name: .text.foo +# CHECK: Name: .rela.text.foo + +## YAML below corresponds to following asm code: +## .section .text,"axG",@progbits,foo,comdat +## .quad bar +## gas 2.27 does not include .rela.text to group in that case: +## COMDAT group section [ 1] `.group' [foo] contains 1 sections: +## [Index] Name +## [ 5] .text +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .group + Type: SHT_GROUP + Link: .symtab + Info: foo + Members: + - SectionOrType: GRP_COMDAT + - SectionOrType: .text.foo + - Name: .text.foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] + - Name: .rela.text.foo + Type: SHT_RELA + Flags: [ SHF_INFO_LINK ] + Link: .symtab + Info: .text.foo + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: R_X86_64_64 +Symbols: + Global: + - Name: foo