Skip to content

Commit ff2b122

Browse files
committed
[WebAssembly] Remove --emit-relocs
This was added to mimic ELF, but maintaining it has cost and we currently don't have any use for it outside of the test code. Differential Revision: https://reviews.llvm.org/D42324 llvm-svn: 323154
1 parent 7687d42 commit ff2b122

File tree

7 files changed

+85
-97
lines changed

7 files changed

+85
-97
lines changed

lld/test/wasm/data-layout.ll

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,95 @@
11
; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown-wasm %p/Inputs/hello.ll -o %t.hello.o
22
; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown-wasm %s -o %t.o
3-
; RUN: lld -flavor wasm --emit-relocs --allow-undefined --no-entry -o %t.wasm %t.o %t.hello.o
4-
; RUN: obj2yaml %t.wasm | FileCheck %s
53

64
@foo = hidden global i32 1, align 4
75
@aligned_bar = hidden global i32 3, align 16
86

97
@hello_str = external global i8*
108
@external_ref = global i8** @hello_str, align 8
119

10+
; RUN: lld -flavor wasm --allow-undefined -o %t.wasm %t.o %t.hello.o
11+
; RUN: obj2yaml %t.wasm | FileCheck %s
12+
1213
; CHECK: - Type: GLOBAL
13-
; CHECK-NEXT: Globals:
14+
; CHECK-NEXT: Globals:
1415
; CHECK-NEXT: - Index: 0
1516
; CHECK-NEXT: Type: I32
1617
; CHECK-NEXT: Mutable: true
17-
; CHECK-NEXT: InitExpr:
18+
; CHECK-NEXT: InitExpr:
1819
; CHECK-NEXT: Opcode: I32_CONST
1920
; CHECK-NEXT: Value: 66608
2021
; CHECK-NEXT: - Index: 1
2122
; CHECK-NEXT: Type: I32
2223
; CHECK-NEXT: Mutable: false
23-
; CHECK-NEXT: InitExpr:
24+
; CHECK-NEXT: InitExpr:
2425
; CHECK-NEXT: Opcode: I32_CONST
2526
; CHECK-NEXT: Value: 66608
26-
; CHECK-NEXT: - Index: 2
27-
; CHECK-NEXT: Type: I32
28-
; CHECK-NEXT: Mutable: false
29-
; CHECK-NEXT: InitExpr:
30-
; CHECK-NEXT: Opcode: I32_CONST
31-
; CHECK-NEXT: Value: 1024
32-
; CHECK-NEXT: - Index: 3
33-
; CHECK-NEXT: Type: I32
34-
; CHECK-NEXT: Mutable: false
35-
; CHECK-NEXT: InitExpr:
36-
; CHECK-NEXT: Opcode: I32_CONST
37-
; CHECK-NEXT: Value: 1040
38-
; CHECK-NEXT: - Index: 4
39-
; CHECK-NEXT: Type: I32
40-
; CHECK-NEXT: Mutable: false
41-
; CHECK-NEXT: InitExpr:
42-
; CHECK-NEXT: Opcode: I32_CONST
43-
; CHECK-NEXT: Value: 1048
44-
; CHECK-NEXT: - Index: 5
45-
; CHECK-NEXT: Type: I32
46-
; CHECK-NEXT: Mutable: false
47-
; CHECK-NEXT: InitExpr:
48-
; CHECK-NEXT: Opcode: I32_CONST
49-
; CHECK-NEXT: Value: 1052
5027

51-
; CHECK: - Type: DATA
52-
; CHECK-NEXT: Relocations:
53-
; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
54-
; CHECK-NEXT: Index: 5
55-
; CHECK-NEXT: Offset: 0x0000001F
56-
; CHECK-NEXT: Segments:
28+
; CHECK: - Type: DATA
29+
; CHECK-NEXT: Segments:
5730
; CHECK-NEXT: - SectionOffset: 7
5831
; CHECK-NEXT: MemoryIndex: 0
59-
; CHECK-NEXT: Offset:
32+
; CHECK-NEXT: Offset:
6033
; CHECK-NEXT: Opcode: I32_CONST
6134
; CHECK-NEXT: Value: 1024
6235
; CHECK-NEXT: Content: 0100000000000000000000000000000003000000000000001C040000
6336
; CHECK-NEXT: - SectionOffset: 41
6437
; CHECK-NEXT: MemoryIndex: 0
65-
; CHECK-NEXT: Offset:
38+
; CHECK-NEXT: Offset:
6639
; CHECK-NEXT: Opcode: I32_CONST
6740
; CHECK-NEXT: Value: 1052
6841
; CHECK-NEXT: Content: 68656C6C6F0A00
6942

70-
; CHECK: - Type: CUSTOM
71-
; CHECK-NEXT: Name: linking
72-
; CHECK-NEXT: DataSize: 35
43+
44+
; RUN: lld -flavor wasm --relocatable -o %t_reloc.wasm %t.o %t.hello.o
45+
; RUN: obj2yaml %t_reloc.wasm | FileCheck %s -check-prefix=RELOC
46+
47+
; RELOC: - Type: GLOBAL
48+
; RELOC-NEXT: Globals:
49+
; RELOC-NEXT: - Index: 0
50+
; RELOC-NEXT: Type: I32
51+
; RELOC-NEXT: Mutable: false
52+
; RELOC-NEXT: InitExpr:
53+
; RELOC-NEXT: Opcode: I32_CONST
54+
; RELOC-NEXT: Value: 0
55+
; RELOC-NEXT: - Index: 1
56+
; RELOC-NEXT: Type: I32
57+
; RELOC-NEXT: Mutable: false
58+
; RELOC-NEXT: InitExpr:
59+
; RELOC-NEXT: Opcode: I32_CONST
60+
; RELOC-NEXT: Value: 16
61+
62+
; RELOC: - Type: DATA
63+
; RELOC-NEXT: Relocations:
64+
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
65+
; RELOC-NEXT: Index: 3
66+
; RELOC-NEXT: Offset: 0x00000018
67+
; RELOC-NEXT: Segments:
68+
; RELOC-NEXT: - SectionOffset: 6
69+
; RELOC-NEXT: MemoryIndex: 0
70+
; RELOC-NEXT: Offset:
71+
; RELOC-NEXT: Opcode: I32_CONST
72+
; RELOC-NEXT: Value: 0
73+
; RELOC-NEXT: Content: '01000000'
74+
; RELOC-NEXT: - SectionOffset: 15
75+
; RELOC-NEXT: MemoryIndex: 0
76+
; RELOC-NEXT: Offset:
77+
; RELOC-NEXT: Opcode: I32_CONST
78+
; RELOC-NEXT: Value: 16
79+
; RELOC-NEXT: Content: '03000000'
80+
; RELOC-NEXT: - SectionOffset: 24
81+
; RELOC-NEXT: MemoryIndex: 0
82+
; RELOC-NEXT: Offset:
83+
; RELOC-NEXT: Opcode: I32_CONST
84+
; RELOC-NEXT: Value: 24
85+
; RELOC-NEXT: Content: 1C000000
86+
; RELOC-NEXT: - SectionOffset: 33
87+
; RELOC-NEXT: MemoryIndex: 0
88+
; RELOC-NEXT: Offset:
89+
; RELOC-NEXT: Opcode: I32_CONST
90+
; RELOC-NEXT: Value: 28
91+
; RELOC-NEXT: Content: 68656C6C6F0A00
92+
93+
; RELOC: - Type: CUSTOM
94+
; RELOC-NEXT: Name: linking
95+
; RELOC-NEXT: DataSize: 35

lld/test/wasm/stack-pointer.ll

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown-wasm %s -o %t.o
2-
; RUN: lld -flavor wasm --emit-relocs -o %t.wasm %t.o
2+
; RUN: lld -flavor wasm --relocatable -o %t.wasm %t.o
33
; RUN: obj2yaml %t.wasm | FileCheck %s
44

55
; Function Attrs: nounwind
6-
define hidden i32 @_start() local_unnamed_addr {
6+
define i32 @_start() local_unnamed_addr {
77
entry:
88
%retval = alloca i32, align 4
99
ret i32 0
@@ -18,52 +18,30 @@ entry:
1818
; CHECK-NEXT: - Index: 0
1919
; CHECK-NEXT: ReturnType: I32
2020
; CHECK-NEXT: ParamTypes:
21-
; CHECK-NEXT: - Index: 1
22-
; CHECK-NEXT: ReturnType: NORESULT
23-
; CHECK-NEXT: ParamTypes:
21+
; CHECK-NEXT: - Type: IMPORT
22+
; CHECK-NEXT: Imports:
23+
; CHECK-NEXT: - Module: env
24+
; CHECK-NEXT: Field: __stack_pointer
25+
; CHECK-NEXT: Kind: GLOBAL
26+
; CHECK-NEXT: GlobalType: I32
27+
; CHECK-NEXT: GlobalMutable: false
2428
; CHECK-NEXT: - Type: FUNCTION
25-
; CHECK-NEXT: FunctionTypes: [ 0, 1 ]
29+
; CHECK-NEXT: FunctionTypes: [ 0 ]
2630
; CHECK-NEXT: - Type: TABLE
2731
; CHECK-NEXT: Tables:
2832
; CHECK-NEXT: - ElemType: ANYFUNC
2933
; CHECK-NEXT: Limits:
3034
; CHECK-NEXT: Flags: [ HAS_MAX ]
31-
; CHECK-NEXT: Initial: 0x00000001
32-
; CHECK-NEXT: Maximum: 0x00000001
35+
; CHECK-NEXT: Initial: 0x00000000
36+
; CHECK-NEXT: Maximum: 0x00000000
3337
; CHECK-NEXT: - Type: MEMORY
3438
; CHECK-NEXT: Memories:
35-
; CHECK-NEXT: - Initial: 0x00000002
36-
; CHECK-NEXT: - Type: GLOBAL
37-
; CHECK-NEXT: Globals:
38-
; CHECK-NEXT: - Index: 0
39-
; CHECK-NEXT: Type: I32
40-
; CHECK-NEXT: Mutable: true
41-
; CHECK-NEXT: InitExpr:
42-
; CHECK-NEXT: Opcode: I32_CONST
43-
; CHECK-NEXT: Value: 66560
44-
; CHECK-NEXT: - Index: 1
45-
; CHECK-NEXT: Type: I32
46-
; CHECK-NEXT: Mutable: false
47-
; CHECK-NEXT: InitExpr:
48-
; CHECK-NEXT: Opcode: I32_CONST
49-
; CHECK-NEXT: Value: 66560
39+
; CHECK-NEXT: - Initial: 0x00000000
5040
; CHECK-NEXT: - Type: EXPORT
51-
; CHECK-NEXT: Exports:
52-
; CHECK-NEXT: - Name: memory
53-
; CHECK-NEXT: Kind: MEMORY
54-
; CHECK-NEXT: Index: 0
55-
; CHECK-NEXT: - Name: __wasm_call_ctors
56-
; CHECK-NEXT: Kind: FUNCTION
57-
; CHECK-NEXT: Index: 1
41+
; CHECK-NEXT: Exports:
5842
; CHECK-NEXT: - Name: _start
5943
; CHECK-NEXT: Kind: FUNCTION
6044
; CHECK-NEXT: Index: 0
61-
; CHECK-NEXT: - Name: __stack_pointer
62-
; CHECK-NEXT: Kind: GLOBAL
63-
; CHECK-NEXT: Index: 0
64-
; CHECK-NEXT: - Name: __heap_base
65-
; CHECK-NEXT: Kind: GLOBAL
66-
; CHECK-NEXT: Index: 1
6745
; CHECK-NEXT: - Type: CODE
6846
; CHECK-NEXT: Relocations:
6947
; CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB
@@ -73,9 +51,6 @@ entry:
7351
; CHECK-NEXT: - Index: 0
7452
; CHECK-NEXT: Locals:
7553
; CHECK-NEXT: Body: 23808080800041106B1A41000B
76-
; CHECK-NEXT: - Index: 1
77-
; CHECK-NEXT: Locals:
78-
; CHECK-NEXT: Body: 0B
7954
; CHECK-NEXT: - Type: CUSTOM
8055
; CHECK-NEXT: Name: linking
8156
; CHECK-NEXT: DataSize: 0
@@ -84,6 +59,4 @@ entry:
8459
; CHECK-NEXT: FunctionNames:
8560
; CHECK-NEXT: - Index: 0
8661
; CHECK-NEXT: Name: _start
87-
; CHECK-NEXT: - Index: 1
88-
; CHECK-NEXT: Name: __wasm_call_ctors
8962
; CHECK-NEXT: ...

lld/wasm/Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ struct Configuration {
2525
bool AllowUndefined;
2626
bool CheckSignatures;
2727
bool Demangle;
28-
bool EmitRelocs;
2928
bool ImportMemory;
3029
bool Relocatable;
3130
bool StripAll;

lld/wasm/Driver.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
249249
Config->AllowUndefined = Args.hasArg(OPT_allow_undefined);
250250
Config->CheckSignatures =
251251
Args.hasFlag(OPT_check_signatures, OPT_no_check_signatures, false);
252-
Config->EmitRelocs = Args.hasArg(OPT_emit_relocs);
253252
Config->Entry = getEntry(Args, Args.hasArg(OPT_relocatable) ? "" : "_start");
254253
Config->ImportMemory = Args.hasArg(OPT_import_memory);
255254
Config->OutputFile = Args.getLastArgValue(OPT_o);
@@ -259,8 +258,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
259258
Config->StripDebug = Args.hasArg(OPT_strip_debug);
260259
errorHandler().Verbose = Args.hasArg(OPT_verbose);
261260
ThreadsEnabled = Args.hasFlag(OPT_threads, OPT_no_threads, true);
262-
if (Config->Relocatable)
263-
Config->EmitRelocs = true;
264261

265262
Config->InitialMemory = args::getInteger(Args, OPT_initial_memory, 0);
266263
Config->GlobalBase = args::getInteger(Args, OPT_global_base, 1024);

lld/wasm/InputChunks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void InputChunk::calcRelocations() {
108108
<< " offset=" << Reloc.Offset
109109
<< " newOffset=" << NewReloc.Reloc.Offset << "\n");
110110

111-
if (Config->EmitRelocs)
111+
if (Config->Relocatable)
112112
NewReloc.NewIndex = File->calcNewIndex(Reloc);
113113

114114
switch (Reloc.Type) {

lld/wasm/Options.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def verbose: F<"verbose">, HelpText<"Verbose mode">;
5151

5252
def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
5353

54-
def emit_relocs: F<"emit-relocs">, HelpText<"Generate relocations in output">;
55-
5654
def strip_all: F<"strip-all">, HelpText<"Strip all symbols">;
5755

5856
def strip_debug: F<"strip-debug">, HelpText<"Strip debugging information">;

lld/wasm/Writer.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ void Writer::createSections() {
588588
createDataSection();
589589

590590
// Custom sections
591-
if (Config->EmitRelocs)
591+
if (Config->Relocatable)
592592
createRelocSections();
593593
createLinkingSection();
594594
if (!Config->StripDebug && !Config->StripAll)
@@ -603,7 +603,7 @@ void Writer::createSections() {
603603

604604
void Writer::calculateImports() {
605605
for (Symbol *Sym : Symtab->getSymbols()) {
606-
if (!Sym->isUndefined() || (Sym->isWeak() && !Config->EmitRelocs))
606+
if (!Sym->isUndefined() || (Sym->isWeak() && !Config->Relocatable))
607607
continue;
608608

609609
if (Sym->isFunction()) {
@@ -617,7 +617,7 @@ void Writer::calculateImports() {
617617
}
618618

619619
void Writer::calculateExports() {
620-
bool ExportHidden = Config->EmitRelocs;
620+
bool ExportHidden = Config->Relocatable;
621621
StringSet<> UsedNames;
622622
auto BudgeLocalName = [&](const Symbol *Sym) {
623623
StringRef SymName = Sym->getName();
@@ -659,11 +659,9 @@ void Writer::calculateExports() {
659659

660660
for (const Symbol *Sym : DefinedGlobals) {
661661
// Can't export the SP right now because its mutable, and mutuable globals
662-
// are yet supported in the official binary format. However, for
663-
// intermediate output we need to export it in case it is the target of any
664-
// relocations.
662+
// are yet supported in the official binary format.
665663
// TODO(sbc): Remove this if/when the "mutable global" proposal is accepted.
666-
if (Sym == Config->StackPointerSymbol && !Config->EmitRelocs)
664+
if (Sym == Config->StackPointerSymbol)
667665
continue;
668666
ExportedSymbols.emplace_back(WasmExportEntry{Sym, BudgeLocalName(Sym)});
669667
}
@@ -713,13 +711,13 @@ void Writer::assignIndexes() {
713711
Config->HeapBaseSymbol->setOutputIndex(GlobalIndex++);
714712
}
715713

716-
if (Config->EmitRelocs)
714+
if (Config->Relocatable)
717715
DefinedGlobals.reserve(Symtab->getSymbols().size());
718716

719717
uint32_t TableIndex = InitialTableOffset;
720718

721719
for (ObjFile *File : Symtab->ObjectFiles) {
722-
if (Config->EmitRelocs) {
720+
if (Config->Relocatable) {
723721
DEBUG(dbgs() << "Globals: " << File->getName() << "\n");
724722
for (Symbol *Sym : File->getSymbols()) {
725723
// Create wasm globals for data symbols defined in this file

0 commit comments

Comments
 (0)