diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index 5dccb3b1d79f..d7831218d5ac 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -184,7 +184,9 @@ public: // Set the entry symbol name. You may also need to call addDeadStripRoot() for // the symbol if your platform supports dead-stripping, so that the symbol // will not be removed from the output. - virtual void setEntrySymbolName(StringRef name) { + void setEntrySymbolName(StringRef name) { + // Entry function have to be resolved as an undefined symbol. + addInitialUndefinedSymbol(name); _entrySymbolName = name; } diff --git a/lld/test/pecoff/entry.test b/lld/test/pecoff/entry.test new file mode 100644 index 000000000000..2a7e8f520d9e --- /dev/null +++ b/lld/test/pecoff/entry.test @@ -0,0 +1,9 @@ +# REQUIRES: debug +# Verify that entry atom will not be dead-stripped. + +# RUN: yaml2obj %p/Inputs/main.obj.yaml > %t.obj +# RUN: lld -flavor link /mllvm -debug-only=WriterPECOFF /out:%t.exe \ +# RUN: /subsystem:console /entry:_main /force -- %t.obj >& %t.log +# RUN: FileCheck %s < %t.log + +CHECK: : _main