[PATCH] D22664: [ELF/Linkerscript] Define an absolute if we find an undefined during symbol assignment

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 22:25:33 PDT 2016


davide created this revision.
davide added a reviewer: ruiu.
davide added a subscriber: llvm-commits.

Avoid an undefined reference failure.


https://reviews.llvm.org/D22664

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript-undef.s

Index: test/ELF/linkerscript-undef.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript-undef.s
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+
+# RUN: echo "SECTIONS { patatino = 0x1234; }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck %s
+# CHECK: 0000000000001234         *ABS*    00000000 patatino
+
+.global _start
+_start:
+  call patatino
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -528,10 +528,15 @@
 }
 
 template <class ELFT> void LinkerScript<ELFT>::addScriptedSymbols() {
-  for (const std::unique_ptr<BaseCommand> &Base : Opt.Commands)
-    if (auto *Cmd = dyn_cast<SymbolAssignment>(Base.get()))
-      if (Cmd->Name != "." && Symtab<ELFT>::X->find(Cmd->Name) == nullptr)
-        Symtab<ELFT>::X->addAbsolute(Cmd->Name, STV_DEFAULT);
+  for (const std::unique_ptr<BaseCommand> &Base : Opt.Commands) {
+    if (auto *Cmd = dyn_cast<SymbolAssignment>(Base.get())) {
+      if (Cmd->Name != ".") {
+        SymbolBody *B = Symtab<ELFT>::X->find(Cmd->Name);
+        if (B == nullptr || B->isUndefined())
+          Symtab<ELFT>::X->addAbsolute(Cmd->Name, STV_DEFAULT);
+      }
+    }
+  }
 }
 
 template <class ELFT> bool LinkerScript<ELFT>::hasPhdrsCommands() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22664.65027.patch
Type: text/x-patch
Size: 1445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160722/e2f5b38a/attachment.bin>


More information about the llvm-commits mailing list