[lld] r293284 - Port r292594.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 27 05:13:46 PST 2017


Author: rafael
Date: Fri Jan 27 07:13:45 2017
New Revision: 293284

URL: http://llvm.org/viewvc/llvm-project?rev=293284&view=rev
Log:
Port r292594.

[ELF] - Do not crash when assign common symbol's values in script

Found that during attempts of linking linux kernel,
previously we partially duplicated code from getOutputSection(),
and it missed commons symbol case.

Differential revision: https://reviews.llvm.org/D28903

Added:
    lld/branches/release_40/test/ELF/linkerscript/common-assign.s
Modified:
    lld/branches/release_40/ELF/LinkerScript.cpp
    lld/branches/release_40/ELF/SyntheticSections.h

Modified: lld/branches/release_40/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/LinkerScript.cpp?rev=293284&r1=293283&r2=293284&view=diff
==============================================================================
--- lld/branches/release_40/ELF/LinkerScript.cpp (original)
+++ lld/branches/release_40/ELF/LinkerScript.cpp Fri Jan 27 07:13:45 2017
@@ -918,12 +918,7 @@ const OutputSectionBase *LinkerScript<EL
     return CurOutSec ? CurOutSec : (*OutputSections)[0];
   }
 
-  if (auto *DR = dyn_cast_or_null<DefinedRegular<ELFT>>(Sym))
-    return DR->Section ? DR->Section->OutSec : nullptr;
-  if (auto *DS = dyn_cast_or_null<DefinedSynthetic>(Sym))
-    return DS->Section;
-
-  return nullptr;
+  return SymbolTableSection<ELFT>::getOutputSection(Sym);
 }
 
 // Returns indices of ELF headers containing specific section, identified

Modified: lld/branches/release_40/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/SyntheticSections.h?rev=293284&r1=293283&r2=293284&view=diff
==============================================================================
--- lld/branches/release_40/ELF/SyntheticSections.h (original)
+++ lld/branches/release_40/ELF/SyntheticSections.h Fri Jan 27 07:13:45 2017
@@ -372,6 +372,8 @@ public:
 
   ArrayRef<SymbolTableEntry> getSymbols() const { return Symbols; }
 
+  static const OutputSectionBase *getOutputSection(SymbolBody *Sym);
+
   unsigned NumLocals = 0;
   StringTableSection<ELFT> &StrTabSec;
 
@@ -379,8 +381,6 @@ private:
   void writeLocalSymbols(uint8_t *&Buf);
   void writeGlobalSymbols(uint8_t *Buf);
 
-  const OutputSectionBase *getOutputSection(SymbolBody *Sym);
-
   // A vector of symbols and their string table offsets.
   std::vector<SymbolTableEntry> Symbols;
 };

Added: lld/branches/release_40/test/ELF/linkerscript/common-assign.s
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/test/ELF/linkerscript/common-assign.s?rev=293284&view=auto
==============================================================================
--- lld/branches/release_40/test/ELF/linkerscript/common-assign.s (added)
+++ lld/branches/release_40/test/ELF/linkerscript/common-assign.s Fri Jan 27 07:13:45 2017
@@ -0,0 +1,48 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; pfoo = foo; pbar = bar; }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-readobj -symbols %t1 | FileCheck %s
+
+# CHECK:       Symbol {
+# CHECK:         Name: bar
+# CHECK-NEXT:     Value: 0x134
+# CHECK-NEXT:     Size: 4
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type: Object
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: .bss
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: foo
+# CHECK-NEXT:     Value: 0x138
+# CHECK-NEXT:     Size: 4
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type: Object
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: .bss
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: pfoo
+# CHECK-NEXT:     Value: 0x138
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type: None
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: .bss
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: pbar
+# CHECK-NEXT:     Value: 0x134
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Type: None
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: .bss
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+.comm	foo,4,4
+.comm	bar,4,4
+movl	$1, foo(%rip)
+movl	$2, bar(%rip)




More information about the llvm-commits mailing list