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; 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 Inputs; 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<"">, + HelpText<"Name of entry point symbol">; 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("_start", Undefined::Synthetic); + EntrySym = new (Alloc) Undefined(Config->EntryPoint, Undefined::Synthetic); resolve(EntrySym); // In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol is magical 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: +