[PATCH] D13509: [ELF2] Add ENTRY command to the linker script

Denis Protivensky via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 06:57:16 PDT 2015


denis-protivensky created this revision.
denis-protivensky added reviewers: ruiu, rafael.
denis-protivensky added a subscriber: llvm-commits.
denis-protivensky added a project: lld.

Parse ENTRY command, set it as an entry point if -e is not specified.

http://reviews.llvm.org/D13509

Files:
  ELF/LinkerScript.cpp
  test/elf2/linkerscript.s

Index: test/elf2/linkerscript.s
===================================================================
--- test/elf2/linkerscript.s
+++ test/elf2/linkerscript.s
@@ -10,6 +10,26 @@
 # RUN: lld -flavor gnu2 -o %t2 %t.script1
 # RUN: llvm-readobj %t2 > /dev/null
 
+# RUN: echo "ENTRY(_label)" > %t.script
+# RUN: lld -flavor gnu2 -o %t2 %t.script %t
+# RUN: llvm-readobj %t2 > /dev/null
+
+# RUN: echo "ENTRY(_wrong_label)" > %t.script
+# RUN: not lld -flavor gnu2 -o %t2 %t.script %t > %t.log 2>&1
+# RUN: FileCheck -check-prefix=ERR-ENTRY %s < %t.log
+
+# ERR-ENTRY: undefined symbol: _wrong_label
+
+# -e has precedence over linker script's ENTRY.
+# RUN: echo "ENTRY(_label)" > %t.script
+# RUN: lld -flavor gnu2 -e _start -o %t2 %t.script %t
+# RUN: llvm-readobj -file-headers -symbols %t2 | \
+# RUN: FileCheck -check-prefix=ENTRY-OVERLOAD %s
+
+# ENTRY-OVERLOAD: Entry: [[ENTRY:0x[0-9A-F]+]]
+# ENTRY-OVERLOAD: Name: _start
+# ENTRY-OVERLOAD-NEXT: Value: [[ENTRY]]
+
 # RUN: echo "OUTPUT_FORMAT(\"elf64-x86-64\") /*/*/ GROUP(" %t ")" > %t.script
 # RUN: lld -flavor gnu2 -o %t2 %t.script
 # RUN: llvm-readobj %t2 > /dev/null
@@ -29,8 +49,9 @@
 
 # ERR1: unknown directive: FOO
 
-.globl _start;
+.globl _start, _label;
 _start:
   mov $60, %rax
   mov $42, %rdi
+_label:
   syscall
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -38,6 +38,7 @@
 
   void readAsNeeded();
   void readGroup();
+  void readEntry();
   void readOutput();
   void readOutputFormat();
 
@@ -51,6 +52,8 @@
     StringRef Tok = next();
     if (Tok == "GROUP") {
       readGroup();
+    } else if (Tok == "ENTRY") {
+      readEntry();
     } else if (Tok == "OUTPUT") {
       readOutput();
     } else if (Tok == "OUTPUT_FORMAT") {
@@ -145,6 +148,15 @@
   }
 }
 
+void LinkerScript::readEntry() {
+  // -e <symbol> takes predecence over ENTRY(<symbol>).
+  expect("(");
+  StringRef Tok = next();
+  if (Config->Entry.empty())
+    Config->Entry = Tok;
+  expect(")");
+}
+
 void LinkerScript::readOutput() {
   // -o <file> takes predecence over OUTPUT(<file>).
   expect("(");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13509.36733.patch
Type: text/x-patch
Size: 2161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151007/c10ade24/attachment.bin>


More information about the llvm-commits mailing list