Index: lld/trunk/test/wasm/data-layout.ll =================================================================== --- lld/trunk/test/wasm/data-layout.ll +++ lld/trunk/test/wasm/data-layout.ll @@ -1,7 +1,5 @@ ; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown-wasm %p/Inputs/hello.ll -o %t.hello.o ; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown-wasm %s -o %t.o -; RUN: lld -flavor wasm --emit-relocs --allow-undefined --no-entry -o %t.wasm %t.o %t.hello.o -; RUN: obj2yaml %t.wasm | FileCheck %s @foo = hidden global i32 1, align 4 @aligned_bar = hidden global i32 3, align 16 @@ -9,64 +7,89 @@ @hello_str = external global i8* @external_ref = global i8** @hello_str, align 8 +; RUN: lld -flavor wasm --allow-undefined -o %t.wasm %t.o %t.hello.o +; RUN: obj2yaml %t.wasm | FileCheck %s + ; CHECK: - Type: GLOBAL -; CHECK-NEXT: Globals: +; CHECK-NEXT: Globals: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: true -; CHECK-NEXT: InitExpr: +; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 66608 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: +; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 66608 -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 -; CHECK-NEXT: - Index: 3 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1040 -; CHECK-NEXT: - Index: 4 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1048 -; CHECK-NEXT: - Index: 5 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1052 -; CHECK: - Type: DATA -; CHECK-NEXT: Relocations: -; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 -; CHECK-NEXT: Index: 5 -; CHECK-NEXT: Offset: 0x0000001F -; CHECK-NEXT: Segments: +; CHECK: - Type: DATA +; CHECK-NEXT: Segments: ; CHECK-NEXT: - SectionOffset: 7 ; CHECK-NEXT: MemoryIndex: 0 -; CHECK-NEXT: Offset: +; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1024 ; CHECK-NEXT: Content: 0100000000000000000000000000000003000000000000001C040000 ; CHECK-NEXT: - SectionOffset: 41 ; CHECK-NEXT: MemoryIndex: 0 -; CHECK-NEXT: Offset: +; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1052 ; CHECK-NEXT: Content: 68656C6C6F0A00 -; CHECK: - Type: CUSTOM -; CHECK-NEXT: Name: linking -; CHECK-NEXT: DataSize: 35 + +; RUN: lld -flavor wasm --relocatable -o %t_reloc.wasm %t.o %t.hello.o +; RUN: obj2yaml %t_reloc.wasm | FileCheck %s -check-prefix=RELOC + +; RELOC: - Type: GLOBAL +; RELOC-NEXT: Globals: +; RELOC-NEXT: - Index: 0 +; RELOC-NEXT: Type: I32 +; RELOC-NEXT: Mutable: false +; RELOC-NEXT: InitExpr: +; RELOC-NEXT: Opcode: I32_CONST +; RELOC-NEXT: Value: 0 +; RELOC-NEXT: - Index: 1 +; RELOC-NEXT: Type: I32 +; RELOC-NEXT: Mutable: false +; RELOC-NEXT: InitExpr: +; RELOC-NEXT: Opcode: I32_CONST +; RELOC-NEXT: Value: 16 + +; RELOC: - Type: DATA +; RELOC-NEXT: Relocations: +; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 +; RELOC-NEXT: Index: 3 +; RELOC-NEXT: Offset: 0x00000018 +; RELOC-NEXT: Segments: +; RELOC-NEXT: - SectionOffset: 6 +; RELOC-NEXT: MemoryIndex: 0 +; RELOC-NEXT: Offset: +; RELOC-NEXT: Opcode: I32_CONST +; RELOC-NEXT: Value: 0 +; RELOC-NEXT: Content: '01000000' +; RELOC-NEXT: - SectionOffset: 15 +; RELOC-NEXT: MemoryIndex: 0 +; RELOC-NEXT: Offset: +; RELOC-NEXT: Opcode: I32_CONST +; RELOC-NEXT: Value: 16 +; RELOC-NEXT: Content: '03000000' +; RELOC-NEXT: - SectionOffset: 24 +; RELOC-NEXT: MemoryIndex: 0 +; RELOC-NEXT: Offset: +; RELOC-NEXT: Opcode: I32_CONST +; RELOC-NEXT: Value: 24 +; RELOC-NEXT: Content: 1C000000 +; RELOC-NEXT: - SectionOffset: 33 +; RELOC-NEXT: MemoryIndex: 0 +; RELOC-NEXT: Offset: +; RELOC-NEXT: Opcode: I32_CONST +; RELOC-NEXT: Value: 28 +; RELOC-NEXT: Content: 68656C6C6F0A00 + +; RELOC: - Type: CUSTOM +; RELOC-NEXT: Name: linking +; RELOC-NEXT: DataSize: 35 Index: lld/trunk/test/wasm/stack-pointer.ll =================================================================== --- lld/trunk/test/wasm/stack-pointer.ll +++ lld/trunk/test/wasm/stack-pointer.ll @@ -1,9 +1,9 @@ ; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown-wasm %s -o %t.o -; RUN: lld -flavor wasm --emit-relocs -o %t.wasm %t.o +; RUN: lld -flavor wasm --relocatable -o %t.wasm %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s ; Function Attrs: nounwind -define hidden i32 @_start() local_unnamed_addr { +define i32 @_start() local_unnamed_addr { entry: %retval = alloca i32, align 4 ret i32 0 @@ -18,52 +18,30 @@ ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: ReturnType: I32 ; CHECK-NEXT: ParamTypes: -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: ReturnType: NORESULT -; CHECK-NEXT: ParamTypes: +; CHECK-NEXT: - Type: IMPORT +; CHECK-NEXT: Imports: +; CHECK-NEXT: - Module: env +; CHECK-NEXT: Field: __stack_pointer +; CHECK-NEXT: Kind: GLOBAL +; CHECK-NEXT: GlobalType: I32 +; CHECK-NEXT: GlobalMutable: false ; CHECK-NEXT: - Type: FUNCTION -; CHECK-NEXT: FunctionTypes: [ 0, 1 ] +; CHECK-NEXT: FunctionTypes: [ 0 ] ; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: Tables: ; CHECK-NEXT: - ElemType: ANYFUNC ; CHECK-NEXT: Limits: ; CHECK-NEXT: Flags: [ HAS_MAX ] -; CHECK-NEXT: Initial: 0x00000001 -; CHECK-NEXT: Maximum: 0x00000001 +; CHECK-NEXT: Initial: 0x00000000 +; CHECK-NEXT: Maximum: 0x00000000 ; CHECK-NEXT: - Type: MEMORY ; CHECK-NEXT: Memories: -; CHECK-NEXT: - Initial: 0x00000002 -; CHECK-NEXT: - Type: GLOBAL -; CHECK-NEXT: Globals: -; CHECK-NEXT: - Index: 0 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: true -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66560 -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66560 +; CHECK-NEXT: - Initial: 0x00000000 ; CHECK-NEXT: - Type: EXPORT -; CHECK-NEXT: Exports: -; CHECK-NEXT: - Name: memory -; CHECK-NEXT: Kind: MEMORY -; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __wasm_call_ctors -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __stack_pointer -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB @@ -73,9 +51,6 @@ ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 23808080800041106B1A41000B -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 0B ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 0 @@ -84,6 +59,4 @@ ; CHECK-NEXT: FunctionNames: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: _start -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Name: __wasm_call_ctors ; CHECK-NEXT: ... Index: lld/trunk/wasm/Config.h =================================================================== --- lld/trunk/wasm/Config.h +++ lld/trunk/wasm/Config.h @@ -25,7 +25,6 @@ bool AllowUndefined; bool CheckSignatures; bool Demangle; - bool EmitRelocs; bool ImportMemory; bool Relocatable; bool StripAll; Index: lld/trunk/wasm/Driver.cpp =================================================================== --- lld/trunk/wasm/Driver.cpp +++ lld/trunk/wasm/Driver.cpp @@ -249,7 +249,6 @@ Config->AllowUndefined = Args.hasArg(OPT_allow_undefined); Config->CheckSignatures = Args.hasFlag(OPT_check_signatures, OPT_no_check_signatures, false); - Config->EmitRelocs = Args.hasArg(OPT_emit_relocs); Config->Entry = getEntry(Args, Args.hasArg(OPT_relocatable) ? "" : "_start"); Config->ImportMemory = Args.hasArg(OPT_import_memory); Config->OutputFile = Args.getLastArgValue(OPT_o); @@ -259,8 +258,6 @@ Config->StripDebug = Args.hasArg(OPT_strip_debug); errorHandler().Verbose = Args.hasArg(OPT_verbose); ThreadsEnabled = Args.hasFlag(OPT_threads, OPT_no_threads, true); - if (Config->Relocatable) - Config->EmitRelocs = true; Config->InitialMemory = args::getInteger(Args, OPT_initial_memory, 0); Config->GlobalBase = args::getInteger(Args, OPT_global_base, 1024); Index: lld/trunk/wasm/InputChunks.cpp =================================================================== --- lld/trunk/wasm/InputChunks.cpp +++ lld/trunk/wasm/InputChunks.cpp @@ -108,7 +108,7 @@ << " offset=" << Reloc.Offset << " newOffset=" << NewReloc.Reloc.Offset << "\n"); - if (Config->EmitRelocs) + if (Config->Relocatable) NewReloc.NewIndex = File->calcNewIndex(Reloc); switch (Reloc.Type) { Index: lld/trunk/wasm/Options.td =================================================================== --- lld/trunk/wasm/Options.td +++ lld/trunk/wasm/Options.td @@ -51,8 +51,6 @@ def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">; -def emit_relocs: F<"emit-relocs">, HelpText<"Generate relocations in output">; - def strip_all: F<"strip-all">, HelpText<"Strip all symbols">; def strip_debug: F<"strip-debug">, HelpText<"Strip debugging information">; Index: lld/trunk/wasm/Writer.cpp =================================================================== --- lld/trunk/wasm/Writer.cpp +++ lld/trunk/wasm/Writer.cpp @@ -588,7 +588,7 @@ createDataSection(); // Custom sections - if (Config->EmitRelocs) + if (Config->Relocatable) createRelocSections(); createLinkingSection(); if (!Config->StripDebug && !Config->StripAll) @@ -603,7 +603,7 @@ void Writer::calculateImports() { for (Symbol *Sym : Symtab->getSymbols()) { - if (!Sym->isUndefined() || (Sym->isWeak() && !Config->EmitRelocs)) + if (!Sym->isUndefined() || (Sym->isWeak() && !Config->Relocatable)) continue; if (Sym->isFunction()) { @@ -617,7 +617,7 @@ } void Writer::calculateExports() { - bool ExportHidden = Config->EmitRelocs; + bool ExportHidden = Config->Relocatable; StringSet<> UsedNames; auto BudgeLocalName = [&](const Symbol *Sym) { StringRef SymName = Sym->getName(); @@ -659,11 +659,9 @@ for (const Symbol *Sym : DefinedGlobals) { // Can't export the SP right now because its mutable, and mutuable globals - // are yet supported in the official binary format. However, for - // intermediate output we need to export it in case it is the target of any - // relocations. + // are yet supported in the official binary format. // TODO(sbc): Remove this if/when the "mutable global" proposal is accepted. - if (Sym == Config->StackPointerSymbol && !Config->EmitRelocs) + if (Sym == Config->StackPointerSymbol) continue; ExportedSymbols.emplace_back(WasmExportEntry{Sym, BudgeLocalName(Sym)}); } @@ -713,13 +711,13 @@ Config->HeapBaseSymbol->setOutputIndex(GlobalIndex++); } - if (Config->EmitRelocs) + if (Config->Relocatable) DefinedGlobals.reserve(Symtab->getSymbols().size()); uint32_t TableIndex = InitialTableOffset; for (ObjFile *File : Symtab->ObjectFiles) { - if (Config->EmitRelocs) { + if (Config->Relocatable) { DEBUG(dbgs() << "Globals: " << File->getName() << "\n"); for (Symbol *Sym : File->getSymbols()) { // Create wasm globals for data symbols defined in this file