[PATCH] D13212: [ELF2] - Implemented -e flag

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 06:33:16 PDT 2015


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: grimar, llvm-commits.

Implemented -e flag ("Use entry as the explicit symbol for beginning execution of your program, rather than the default entry point.");
Actually docs also says that:

"If there is no symbol named entry, the linker will try to parse entry as a number, and use that as the entry address (the number will be interpreted in base 10; you may use a leading 0x for base 16, or a leading 0 for base 8)."

But I doubt that it is a real usecase and not sure if it should be implemented or not ?

http://reviews.llvm.org/D13212

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/Options.td
  ELF/SymbolTable.cpp
  test/elf2/entry.s

Index: test/elf2/entry.s
===================================================================
--- test/elf2/entry.s
+++ test/elf2/entry.s
@@ -0,0 +1,7 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
+# RUN: not lld -flavor gnu2 %t1 -o %t2
+# RUN: lld -flavor gnu2 %t1 -o %t2 -e _end
+
+.globl _end;
+_end: 
+
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -72,7 +72,7 @@
   Target.reset(createTarget(EMachine));
   if (Config->Shared)
     return;
-  EntrySym = new (Alloc) Undefined<ELFT>("_start", Undefined<ELFT>::Synthetic);
+  EntrySym = new (Alloc) Undefined<ELFT>(Config->EntryPoint, Undefined<ELFT>::Synthetic);
   resolve<ELFT>(EntrySym);
 
   // In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol is magical
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -37,3 +37,6 @@
 
 def export_dynamic : Flag<["--"], "export-dynamic">,
      HelpText<"Put symbols in the dynamic symbol table">;
+
+def e : Separate<["-"], "e">, MetaVarName<"<entry>">,
+     HelpText<"Name of entry point symbol">;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -97,6 +97,10 @@
   if (Args.hasArg(OPT_noinhibit_exec))
     Config->NoInhibitExec = true;
 
+  // Handle -e
+  if (auto *Arg = Args.getLastArg(OPT_e))
+    Config->EntryPoint = Arg->getValue();
+
   // Create a list of input files.
   std::vector<MemoryBufferRef> Inputs;
 
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -25,6 +25,7 @@
   bool DiscardNone = false;
   bool ExportDynamic = false;
   bool NoInhibitExec = false;
+  llvm::StringRef EntryPoint = "_start";
 };
 
 extern Configuration *Config;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13212.35861.patch
Type: text/x-patch
Size: 1933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150928/bcacf2ec/attachment.bin>


More information about the llvm-commits mailing list