[lld] r301729 - [ELF] When a rel points to a SHF_MERGE section, don't merge the sec.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 28 18:24:35 PDT 2017


Author: davide
Date: Fri Apr 28 20:24:34 2017
New Revision: 301729

URL: http://llvm.org/viewvc/llvm-project?rev=301729&view=rev
Log:
[ELF] When a rel points to a SHF_MERGE section, don't merge the sec.

Fixes PR32785. Thanks to Piotr Padlewski for the report and
Rafael for the fix.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/test/ELF/relocation-in-merge.s

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=301729&r1=301728&r2=301729&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Apr 28 20:24:34 2017
@@ -398,9 +398,13 @@ elf::ObjectFile<ELFT>::createInputSectio
     if (Target->FirstRelocation)
       fatal(toString(this) +
             ": multiple relocation sections to one section are not supported");
-    if (isa<MergeInputSection>(Target))
-      fatal(toString(this) +
-            ": relocations pointing to SHF_MERGE are not supported");
+    if (isa<MergeInputSection>(Target)) {
+      this->Sections[Sec.sh_info] =
+          make<InputSection>(Target->Flags, Target->Type, Target->Alignment,
+                             Target->Data, Target->Name);
+      this->Sections[Sec.sh_info]->File = Target->File;
+      Target = this->Sections[Sec.sh_info];
+    }
 
     size_t NumRelocations;
     if (Sec.sh_type == SHT_RELA) {

Modified: lld/trunk/test/ELF/relocation-in-merge.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocation-in-merge.s?rev=301729&r1=301728&r2=301729&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocation-in-merge.s (original)
+++ lld/trunk/test/ELF/relocation-in-merge.s Fri Apr 28 20:24:34 2017
@@ -1,7 +1,12 @@
 // REQUIRES: x86
 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
-// RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
-// CHECK: relocations pointing to SHF_MERGE are not supported
+// RUN: ld.lld %t.o -o %t -shared
+// RUN: llvm-objdump -section-headers %t | FileCheck %s
 
-        .section	.foo,"aM", at progbits,4
-        .long bar
+// Test that we accept this by just not merging the section.
+// CHECK:  .foo          00000008
+
+bar:
+        .section	.foo,"aM", at progbits,8
+        .long bar - .
+        .long bar - .




More information about the llvm-commits mailing list