[PATCH] D83758: [lld][linkerscript] Fix handling of DEFINED.

Hafiz Abid Qadeer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 13:19:26 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1f166edeb47e: [lld][linkerscript] Fix handling of DEFINED. (authored by abidh).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83758/new/

https://reviews.llvm.org/D83758

Files:
  lld/ELF/ScriptParser.cpp
  lld/test/ELF/linkerscript/Inputs/define.s
  lld/test/ELF/linkerscript/define.test


Index: lld/test/ELF/linkerscript/define.test
===================================================================
--- lld/test/ELF/linkerscript/define.test
+++ lld/test/ELF/linkerscript/define.test
@@ -3,13 +3,17 @@
 # RUN: ld.lld -o %t --script %s %t.o
 # RUN: llvm-objdump --section-headers %t | FileCheck %s
 
+EXTERN(extern_defined)
 SECTIONS {
   . = DEFINED(defined) ? 0x11000 : .;
   .foo : { *(.foo*) }
   . = DEFINED(notdefined) ? 0x12000 : 0x13000;
   .bar : { *(.bar*) }
+  . = DEFINED(extern_defined) ? 0x14000 : 0x15000;
+  .test : { *(.test*) }
 }
 
 # CHECK: 1 .foo  00000008 0000000000011000 DATA
 # CHECK: 2 .bar  00000008 0000000000013000 DATA
-# CHECK: 3 .text 00000000 0000000000013008 TEXT
+# CHECK: 3 .test  00000008 0000000000015000 DATA
+# CHECK: 4 .text 00000000 0000000000015008 TEXT
Index: lld/test/ELF/linkerscript/Inputs/define.s
===================================================================
--- lld/test/ELF/linkerscript/Inputs/define.s
+++ lld/test/ELF/linkerscript/Inputs/define.s
@@ -6,3 +6,6 @@
 
 .section .bar,"a"
 .quad 1
+
+.section .test,"a"
+.quad 1
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -1311,7 +1311,10 @@
   }
   if (tok == "DEFINED") {
     StringRef name = readParenLiteral();
-    return [=] { return symtab->find(name) ? 1 : 0; };
+    return [=] {
+      Symbol *b = symtab->find(name);
+      return (b && b->isDefined()) ? 1 : 0;
+    };
   }
   if (tok == "LENGTH") {
     StringRef name = readParenLiteral();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83758.281342.patch
Type: text/x-patch
Size: 1589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200728/f65ab07c/attachment.bin>


More information about the llvm-commits mailing list