Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -30,6 +30,7 @@ bool ExportDynamic = false; bool NoInhibitExec = false; bool AllowMultipleDefinition = false; + llvm::StringRef Entry; }; extern Configuration *Config; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -142,6 +142,9 @@ if (Args.hasArg(OPT_allow_multiple_definition)) Config->AllowMultipleDefinition = true; + if (auto *Arg = Args.getLastArg(OPT_entry)) + Config->Entry = Arg->getValue(); + // Create a list of input files. std::vector Inputs; Index: ELF/Options.td =================================================================== --- ELF/Options.td +++ ELF/Options.td @@ -55,3 +55,9 @@ def sysroot : Joined<["--"], "sysroot=">, HelpText<"Set the system root">; + +def entry : Separate<["--", "-"], "entry">, MetaVarName<"">, + HelpText<"Name of entry point symbol">; + +def alias_entry : Separate<["-"], "e">, + Alias; Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -74,8 +74,9 @@ Target.reset(createTarget(EMachine)); if (Config->Shared) return; - EntrySym = new (Alloc) - Undefined(Target->getDefaultEntry(), Undefined::Synthetic); + EntrySym = new (Alloc) Undefined( + Config->Entry.empty() ? Target->getDefaultEntry() : Config->Entry, + 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,6 @@ +# 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: