Avoid a crash with -r and .comment.

We would create a MergeInputSection for the synthetic .comment and
crash trying to add it to a regular output section.

With this we just don't add the synthetic section with -r. That is
consistent with gold that doesn't create .note.gnu.gold-version with
-r.

llvm-svn: 286635
This commit is contained in:
Rafael Espindola 2016-11-11 21:36:25 +00:00
parent 088faab429
commit d4372f783b
4 changed files with 33 additions and 5 deletions

View File

@ -267,7 +267,8 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
Out<ELFT>::VerDef = make<VersionDefinitionSection<ELFT>>();
// Initialize linker generated sections
Symtab<ELFT>::X->Sections.push_back(createCommentSection<ELFT>());
if (!Config->Relocatable)
Symtab<ELFT>::X->Sections.push_back(createCommentSection<ELFT>());
if (Config->BuildId == BuildIdKind::Fast)
In<ELFT>::BuildId = make<BuildIdFastHash<ELFT>>();

View File

@ -20,7 +20,7 @@
# CHECK-NEXT: Version:
# CHECK-NEXT: Entry:
# CHECK-NEXT: ProgramHeaderOffset:
# CHECK-NEXT: SectionHeaderOffset: 0xB8
# CHECK-NEXT: SectionHeaderOffset: 0xA8
# CHECK-NEXT: Flags [
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize:

View File

@ -0,0 +1,27 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
# RUN: ld.lld -r %t1.o -o %t
# RUN: llvm-readobj -s -section-data %t | FileCheck %s
# CHECK: Name: .comment
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT: SHF_MERGE
# CHECK-NEXT: SHF_STRINGS
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset:
# CHECK-NEXT: Size: 7
# CHECK-NEXT: Link:
# CHECK-NEXT: Info:
# CHECK-NEXT: AddressAlignment: 1
# CHECK-NEXT: EntrySize: 1
# CHECK-NEXT: SectionData (
# CHECK-NEXT: 0000: 666F6F62 617200 |foobar.|
# CHECK-NEXT: )
# We used to crash creating a merge and non merge .comment sections.
.section .comment,"MS",@progbits,1
.asciz "foobar"

View File

@ -30,15 +30,15 @@
# CHECK-NEXT: Version: 1
# CHECK-NEXT: Entry: 0x0
# CHECK-NEXT: ProgramHeaderOffset: 0x0
# CHECK-NEXT: SectionHeaderOffset: 0x2D0
# CHECK-NEXT: SectionHeaderOffset: 0x2C0
# CHECK-NEXT: Flags [
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 64
# CHECK-NEXT: ProgramHeaderEntrySize: 0
# CHECK-NEXT: ProgramHeaderCount: 0
# CHECK-NEXT: SectionHeaderEntrySize: 64
# CHECK-NEXT: SectionHeaderCount: 8
# CHECK-NEXT: StringTableSectionIndex: 6
# CHECK-NEXT: SectionHeaderCount: 7
# CHECK-NEXT: StringTableSectionIndex: 5
# CHECK-NEXT: }
# CHECK: Relocations [