[lld] r286635 - Avoid a crash with -r and .comment.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 13:36:25 PST 2016


Author: rafael
Date: Fri Nov 11 15:36:25 2016
New Revision: 286635

URL: http://llvm.org/viewvc/llvm-project?rev=286635&view=rev
Log:
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.

Added:
    lld/trunk/test/ELF/relocatable-comment.s
Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/relocatable-bss.s
    lld/trunk/test/ELF/relocatable.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=286635&r1=286634&r2=286635&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Nov 11 15:36:25 2016
@@ -267,7 +267,8 @@ template <class ELFT> void Writer<ELFT>:
     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>>();

Modified: lld/trunk/test/ELF/relocatable-bss.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-bss.s?rev=286635&r1=286634&r2=286635&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocatable-bss.s (original)
+++ lld/trunk/test/ELF/relocatable-bss.s Fri Nov 11 15:36:25 2016
@@ -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:

Added: lld/trunk/test/ELF/relocatable-comment.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-comment.s?rev=286635&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-comment.s (added)
+++ lld/trunk/test/ELF/relocatable-comment.s Fri Nov 11 15:36:25 2016
@@ -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", at progbits,1
+	.asciz	"foobar"

Modified: lld/trunk/test/ELF/relocatable.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable.s?rev=286635&r1=286634&r2=286635&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocatable.s (original)
+++ lld/trunk/test/ELF/relocatable.s Fri Nov 11 15:36:25 2016
@@ -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 [




More information about the llvm-commits mailing list