Index: test/wasm/data-layout.ll =================================================================== --- test/wasm/data-layout.ll +++ test/wasm/data-layout.ll @@ -1,6 +1,6 @@ ; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.o ; RUN: llc -filetype=obj %s -o %t.o -; RUN: lld -flavor wasm --emit-relocs --allow-undefined -o %t.wasm %t.o %t.hello.o +; RUN: lld -flavor wasm --emit-relocs --allow-undefined --entry '' -o %t.wasm %t.o %t.hello.o ; RUN: obj2yaml %t.wasm | FileCheck %s target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" Index: test/wasm/entry.ll =================================================================== --- test/wasm/entry.ll +++ test/wasm/entry.ll @@ -12,11 +12,13 @@ ret void } -; CHECK: - Type: EXPORT -; CHECK: Exports: -; CHECK: - Name: memory -; CHECK: Kind: MEMORY -; CHECK: Index: 0 -; CHECK: - Name: entry -; CHECK: Kind: FUNCTION -; CHECK: Index: 0 +; CHECK: - Type: EXPORT +; CHECK-NEXT: Exports: +; CHECK-NEXT: - Name: memory +; CHECK-NEXT: Kind: MEMORY +; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Name: entry +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Type: START +; CHECK-NEXT: StartFunction: 0 Index: test/wasm/local-symbols.ll =================================================================== --- test/wasm/local-symbols.ll +++ test/wasm/local-symbols.ll @@ -54,6 +54,8 @@ ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Type: START +; CHECK-NEXT: StartFunction: 1 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Locals: Index: test/wasm/stack-pointer.ll =================================================================== --- test/wasm/stack-pointer.ll +++ test/wasm/stack-pointer.ll @@ -48,6 +48,8 @@ ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 +; CHECK-NEXT: - Type: START +; CHECK-NEXT: StartFunction: 0 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB Index: test/wasm/weak-alias-overide.ll =================================================================== --- test/wasm/weak-alias-overide.ll +++ test/wasm/weak-alias-overide.ll @@ -65,6 +65,8 @@ ; CHECK-NEXT: - Name: call_bar ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 3 +; CHECK-NEXT: - Type: START +; CHECK-NEXT: StartFunction: 1 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Locals: Index: test/wasm/weak-alias.ll =================================================================== --- test/wasm/weak-alias.ll +++ test/wasm/weak-alias.ll @@ -59,6 +59,8 @@ ; CHECK-NEXT: - Name: call_bar ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 2 +; CHECK-NEXT: - Type: START +; CHECK-NEXT: StartFunction: 0 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Locals: Index: test/wasm/weak-external.ll =================================================================== --- test/wasm/weak-external.ll +++ test/wasm/weak-external.ll @@ -66,6 +66,8 @@ ; CHECK-NEXT: - Name: get_address_of_global_var ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 1 +; CHECK-NEXT: - Type: START +; CHECK-NEXT: StartFunction: 2 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: Index: wasm/Driver.cpp =================================================================== --- wasm/Driver.cpp +++ wasm/Driver.cpp @@ -243,10 +243,11 @@ Config->CheckSignatures = Args.hasFlag(OPT_check_signatures, OPT_no_check_signatures, false); Config->EmitRelocs = Args.hasArg(OPT_emit_relocs); - Config->Entry = Args.getLastArgValue(OPT_entry); + Config->Relocatable = Args.hasArg(OPT_relocatable); + Config->Entry = Args.getLastArgValue(OPT_entry, + Config->Relocatable ? "" : "_start"); Config->ImportMemory = Args.hasArg(OPT_import_memory); Config->OutputFile = Args.getLastArgValue(OPT_o); - Config->Relocatable = Args.hasArg(OPT_relocatable); Config->SearchPaths = args::getStrings(Args, OPT_L); Config->StripAll = Args.hasArg(OPT_strip_all); Config->StripDebug = Args.hasArg(OPT_strip_debug); @@ -278,10 +279,10 @@ error("undefined symbols specified for relocatable output file"); if (!Config->Relocatable) { - if (Config->Entry.empty()) - Config->Entry = "_start"; - static WasmSignature Signature = {{}, WASM_TYPE_NORESULT}; - addSyntheticUndefinedFunction(Config->Entry, &Signature); + if (!Config->Entry.empty()) { + static WasmSignature Signature = {{}, WASM_TYPE_NORESULT}; + addSyntheticUndefinedFunction(Config->Entry, &Signature); + } // Handle the `--undefined ` options. for (StringRef S : args::getStrings(Args, OPT_undefined)) Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -337,7 +337,19 @@ } } -void Writer::createStartSection() {} +void Writer::createStartSection() { + if (Config->Entry.empty()) + return; + + const Symbol *Sym = Symtab->find(Config->Entry); + assert(Sym && Sym->isDefined() && Sym->isFunction()); + + SyntheticSection *Section = createSyntheticSection(WASM_SEC_START); + raw_ostream &OS = Section->getStream(); + + log("Start: " + Sym->getName()); + writeUleb128(OS, Sym->getOutputIndex(), "start index"); +} void Writer::createElemSection() { if (!NumElements)