authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-28 12:53:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-28 12:53:08-05:00
log5768fcb0850335fa8b5f3dca23f1bbfca5d6efb2
treeccf3f503ec9ff6b1855c017e3c836d594bd9448e
parent6bc19b437c4323f3b71ad38c5e8e9d0a54ad8d74
signaturelock-open Commit is signed but in an unrecognized format.

update embedded LLD to 8.0.0rc3


26 files changed, 406 insertions(+), 218 deletions(-)

deps/lld-prebuilt/ELF/Options.inc+1-1
......@@ -54,7 +54,7 @@ OPTION(prefix_2, "Bsymbolic-functions", Bsymbolic_functions, Flag, INVALID, INVA
5454OPTION(prefix_2, "Bsymbolic", Bsymbolic, Flag, INVALID, INVALID, nullptr, 0, 0,
5555 "Bind defined symbols locally", nullptr, nullptr)
5656OPTION(prefix_2, "build-id=", build_id_eq, Joined, INVALID, INVALID, nullptr, 0, 0,
57 "Generate build ID note", "[fast,md5,sha,uuid,0x<hexstring>]", nullptr)
57 "Generate build ID note", "[fast,md5,sha1,uuid,0x<hexstring>]", nullptr)
5858OPTION(prefix_2, "build-id", build_id, Flag, INVALID, INVALID, nullptr, 0, 0,
5959 "Alias for --build-id=fast", nullptr, nullptr)
6060OPTION(prefix_1, "b", anonymous_16, Separate, INVALID, format, nullptr, 0, 0,
deps/lld/ELF/Driver.cpp+1-1
......@@ -130,7 +130,7 @@ static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef Emul) {
130130 .Cases("elf32btsmip", "elf32btsmipn32", {ELF32BEKind, EM_MIPS})
131131 .Cases("elf32ltsmip", "elf32ltsmipn32", {ELF32LEKind, EM_MIPS})
132132 .Case("elf32lriscv", {ELF32LEKind, EM_RISCV})
133 .Case("elf32ppc", {ELF32BEKind, EM_PPC})
133 .Cases("elf32ppc", "elf32ppclinux", {ELF32BEKind, EM_PPC})
134134 .Case("elf64btsmip", {ELF64BEKind, EM_MIPS})
135135 .Case("elf64ltsmip", {ELF64LEKind, EM_MIPS})
136136 .Case("elf64lriscv", {ELF64LEKind, EM_RISCV})
deps/lld/ELF/Options.td+1-1
......@@ -30,7 +30,7 @@ def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">;
3030def build_id: F<"build-id">, HelpText<"Alias for --build-id=fast">;
3131
3232def build_id_eq: J<"build-id=">, HelpText<"Generate build ID note">,
33 MetaVarName<"[fast,md5,sha,uuid,0x<hexstring>]">;
33 MetaVarName<"[fast,md5,sha1,uuid,0x<hexstring>]">;
3434
3535defm check_sections: B<"check-sections",
3636 "Check section addresses for overlaps (default)",
deps/lld/ELF/ScriptParser.cpp+2-1
......@@ -392,10 +392,11 @@ static std::pair<ELFKind, uint16_t> parseBfdName(StringRef S) {
392392 .Case("elf32-x86-64", {ELF32LEKind, EM_X86_64})
393393 .Case("elf64-aarch64", {ELF64LEKind, EM_AARCH64})
394394 .Case("elf64-littleaarch64", {ELF64LEKind, EM_AARCH64})
395 .Case("elf32-powerpc", {ELF32BEKind, EM_PPC})
395396 .Case("elf64-powerpc", {ELF64BEKind, EM_PPC64})
396397 .Case("elf64-powerpcle", {ELF64LEKind, EM_PPC64})
397398 .Case("elf64-x86-64", {ELF64LEKind, EM_X86_64})
398 .Case("elf32-tradbigmips", {ELF32BEKind, EM_MIPS})
399 .Cases("elf32-tradbigmips", "elf32-bigmips", {ELF32BEKind, EM_MIPS})
399400 .Case("elf32-ntradbigmips", {ELF32BEKind, EM_MIPS})
400401 .Case("elf32-tradlittlemips", {ELF32LEKind, EM_MIPS})
401402 .Case("elf32-ntradlittlemips", {ELF32LEKind, EM_MIPS})
deps/lld/docs/ReleaseNotes.rst+28-16
......@@ -5,18 +5,15 @@ lld 8.0.0 Release Notes
55.. contents::
66 :local:
77
8.. warning::
9 These are in-progress notes for the upcoming LLVM 8.0.0 release.
10 Release notes for previous releases can be found on
11 `the Download Page <https://releases.llvm.org/download.html>`_.
12
138Introduction
149============
1510
16This document contains the release notes for the lld linker, release 8.0.0.
17Here we describe the status of lld, including major improvements
18from the previous release. All lld releases may be downloaded
19from the `LLVM releases web site <https://llvm.org/releases/>`_.
11lld is a high-performance linker that supports ELF (Unix), COFF (Windows),
12Mach-O (macOS), MinGW and WebAssembly. lld is command-line-compatible with
13GNU linkers and Microsoft link.exe and is significantly faster than the
14system default linkers.
15
16lld 8.0.0 has lots of feature improvements and bug fixes.
2017
2118Non-comprehensive list of changes in this release
2219=================================================
......@@ -33,16 +30,36 @@ ELF Improvements
3330 non-superpages to a superpage if they are aligned to the superpage
3431 size. (`r342746 <https://reviews.llvm.org/rL342746>`_)
3532
33* lld now attempts to place a ``.note`` segment in the first page of a
34 generated file, so that you can find some important information
35 (``.note.gnu.build-id`` in particular) in a core file even if a core
36 file is truncated by ulimit.
37 (`r349524 <https://reviews.llvm.org/rL349524>`_)
38
39* lld now reports an error if ``_GLOBAL_OFFSET_TABLE_`` symbol is
40 defined by an input object file, as the symbol is supposed to be
41 synthesized by the linker.
42 (`r347854 <https://reviews.llvm.org/rL347854>`_)
43
3644* lld/Hexagon can now link Linux kernel and musl libc for Qualcomm
3745 Hexagon ISA.
3846
3947* Initial MSP430 ISA support has landed.
4048
41* The following flags have been added: ``-z interpose``, ``-z global``
42
4349* lld now uses the ``sigrie`` instruction as a trap instruction for
4450 MIPS targets.
4551
52* lld now creates a TLS segment for AArch64 with a slightly larger
53 alignment requirement, so that the loader makes a few bytes room
54 before each TLS segment at runtime. The aim of this change is to
55 make room to accomodate nonstandard Android TLS slots while keeping
56 the compatibility with the standard AArch64 ABI.
57 (`r350681 <https://reviews.llvm.org/rL350681>`_)
58
59* The following flags have been added: ``--call-graph-profile``,
60 ``--no-call-graph-profile``, ``--warn-ifunc-textrel``,
61 ``-z interpose``, ``-z global``, ``-z nodefaultlib``
62
4663COFF Improvements
4764-----------------
4865
......@@ -95,11 +112,6 @@ MinGW Improvements
95112 Previously, the ``--build-id`` option did not actually generate a build id
96113 unless ``--pdb`` was specified.
97114
98MachO Improvements
99------------------
100
101* Item 1.
102
103115WebAssembly Improvements
104116------------------------
105117
deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp+1
......@@ -622,6 +622,7 @@ void ArchHandler_x86_64::applyFixupFinal(
622622 // Fall into llvm_unreachable().
623623 break;
624624 }
625 llvm_unreachable("invalid x86_64 Reference Kind");
625626}
626627
627628void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref,
deps/lld/test/ELF/emulation-mips.s+3
......@@ -7,6 +7,9 @@
77# RUN: echo 'OUTPUT_FORMAT(elf32-tradbigmips)' > %tmips.script
88# RUN: ld.lld %tmips.script -e _start %tmips -o %t4mips
99# RUN: llvm-readobj -file-headers %t4mips | FileCheck --check-prefix=MIPS %s
10# RUN: echo 'OUTPUT_FORMAT(elf32-bigmips)' > %tmips2.script
11# RUN: ld.lld %tmips2.script -e _start %tmips -o %t5mips
12# RUN: llvm-readobj -file-headers %t5mips | FileCheck --check-prefix=MIPS %s
1013# MIPS: ElfHeader {
1114# MIPS-NEXT: Ident {
1215# MIPS-NEXT: Magic: (7F 45 4C 46)
deps/lld/test/ELF/emulation-ppc.s+37
......@@ -103,5 +103,42 @@
103103# PPC64LE-NEXT: StringTableSectionIndex:
104104# PPC64LE-NEXT: }
105105
106# RUN: llvm-mc -filetype=obj -triple=powerpc-unknown-linux %s -o %tppc32
107# RUN: ld.lld -m elf32ppc %tppc32 -o %t2ppc32
108# RUN: llvm-readobj -file-headers %t2ppc32 | FileCheck --check-prefix=PPC32 %s
109# RUN: ld.lld %tppc32 -o %t3ppc32
110# RUN: llvm-readobj -file-headers %t3ppc32 | FileCheck --check-prefix=PPC32 %s
111# RUN: echo 'OUTPUT_FORMAT(elf32-powerpc)' > %tppc32.script
112# RUN: ld.lld %tppc32.script %tppc32 -o %t4ppc32
113# RUN: llvm-readobj -file-headers %t4ppc32 | FileCheck --check-prefix=PPC32 %s
114# RUN: ld.lld -m elf32ppclinux %tppc32 -o %t5ppc32
115# RUN: llvm-readobj -file-headers %t5ppc32 | FileCheck --check-prefix=PPC32 %s
116
117# PPC32: ElfHeader {
118# PPC32-NEXT: Ident {
119# PPC32-NEXT: Magic: (7F 45 4C 46)
120# PPC32-NEXT: Class: 32-bit (0x1)
121# PPC32-NEXT: DataEncoding: BigEndian (0x2)
122# PPC32-NEXT: FileVersion: 1
123# PPC32-NEXT: OS/ABI: SystemV (0x0)
124# PPC32-NEXT: ABIVersion: 0
125# PPC32-NEXT: Unused: (00 00 00 00 00 00 00)
126# PPC32-NEXT: }
127# PPC32-NEXT: Type: Executable (0x2)
128# PPC32-NEXT: Machine: EM_PPC (0x14)
129# PPC32-NEXT: Version: 1
130# PPC32-NEXT: Entry:
131# PPC32-NEXT: ProgramHeaderOffset: 0x34
132# PPC32-NEXT: SectionHeaderOffset:
133# PPC32-NEXT: Flags [ (0x0)
134# PPC32-NEXT: ]
135# PPC32-NEXT: HeaderSize: 52
136# PPC32-NEXT: ProgramHeaderEntrySize: 32
137# PPC32-NEXT: ProgramHeaderCount:
138# PPC32-NEXT: SectionHeaderEntrySize: 40
139# PPC32-NEXT: SectionHeaderCount:
140# PPC32-NEXT: StringTableSectionIndex:
141# PPC32-NEXT: }
142
106143.globl _start
107144_start:
deps/lld/test/wasm/data-layout.ll+3-3
......@@ -85,10 +85,10 @@ target triple = "wasm32-unknown-unknown"
8585; RELOC: - Type: DATA
8686; RELOC-NEXT: Relocations:
8787; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
88; RELOC-NEXT: Index: 6
88; RELOC-NEXT: Index: 3
8989; RELOC-NEXT: Offset: 0x00000018
9090; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
91; RELOC-NEXT: Index: 3
91; RELOC-NEXT: Index: 4
9292; RELOC-NEXT: Offset: 0x0000002E
9393; RELOC-NEXT: Addend: 4
9494; RELOC-NEXT: Segments:
......@@ -148,7 +148,7 @@ target triple = "wasm32-unknown-unknown"
148148; RELOC-NEXT: Flags: [ ]
149149; RELOC-NEXT: Segment: 2
150150; RELOC-NEXT: Size: 4
151; RELOC: - Index: 6
151; RELOC-NEXT: - Index: 3
152152; RELOC-NEXT: Kind: DATA
153153; RELOC-NEXT: Name: hello_str
154154; RELOC-NEXT: Flags: [ ]
deps/lld/test/wasm/import-module.ll created+21
......@@ -0,0 +1,21 @@
1; RUN: llc -filetype=obj %s -o %t.o
2; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o
3; RUN: obj2yaml %t.wasm | FileCheck %s
4
5target triple = "wasm32-unknown-unknown-wasm"
6
7define void @_start() {
8 call void @foo();
9 ret void
10}
11
12declare void @foo() #0
13
14attributes #0 = { "wasm-import-module"="bar" }
15
16; CHECK: - Type: IMPORT
17; CHECK-NEXT: Imports:
18; CHECK-NEXT: - Module: bar
19; CHECK-NEXT: Field: foo
20; CHECK-NEXT: Kind: FUNCTION
21; CHECK-NEXT: SigIndex: 0
deps/lld/test/wasm/import-names.ll created+27
......@@ -0,0 +1,27 @@
1; RUN: llc -filetype=obj %s -o %t.o
2; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o
3; RUN: obj2yaml %t.wasm | FileCheck %s
4
5target triple = "wasm32-unknown-unknown"
6
7declare void @f0() #0
8
9define void @_start() {
10 call void @f0()
11 ret void
12}
13
14attributes #0 = { "wasm-import-module"="somewhere" "wasm-import-name"="something" }
15
16; CHECK: - Type: IMPORT
17; CHECK-NEXT: Imports:
18; CHECK-NEXT: - Module: somewhere
19; CHECK-NEXT: Field: something
20; CHECK-NEXT: Kind: FUNCTION
21; CHECK-NEXT: SigIndex: 0
22
23; CHECK: - Type: CUSTOM
24; CHECK-NEXT: Name: name
25; CHECK-NEXT: FunctionNames:
26; CHECK-NEXT: - Index: 0
27; CHECK-NEXT: Name: f0
deps/lld/test/wasm/init-fini.ll+43-43
......@@ -163,64 +163,64 @@ entry:
163163; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
164164; RELOC-NEXT: Function: 7
165165; RELOC-NEXT: - Index: 6
166; RELOC-NEXT: Kind: DATA
167; RELOC-NEXT: Name: __dso_handle
168; RELOC-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN, UNDEFINED ]
169; RELOC-NEXT: - Index: 7
170; RELOC-NEXT: Kind: FUNCTION
171; RELOC-NEXT: Name: externDtor
172; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN, UNDEFINED ]
173; RELOC-NEXT: Function: 0
174; RELOC-NEXT: - Index: 8
175; RELOC-NEXT: Kind: FUNCTION
176; RELOC-NEXT: Name: externCtor
177; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN, UNDEFINED ]
178; RELOC-NEXT: Function: 1
179; RELOC-NEXT: - Index: 9
180; RELOC-NEXT: Kind: FUNCTION
181; RELOC-NEXT: Name: myctor
182; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
183; RELOC-NEXT: Function: 14
184; RELOC-NEXT: - Index: 10
185; RELOC-NEXT: Kind: FUNCTION
186; RELOC-NEXT: Name: mydtor
187; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
188; RELOC-NEXT: Function: 15
189; RELOC-NEXT: - Index: 11
190; RELOC-NEXT: Kind: GLOBAL
191; RELOC-NEXT: Name: __stack_pointer
192; RELOC-NEXT: Flags: [ UNDEFINED ]
193; RELOC-NEXT: Global: 0
194; RELOC-NEXT: - Index: 12
166195; RELOC-NEXT: Kind: FUNCTION
167196; RELOC-NEXT: Name: .Lcall_dtors.101
168197; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
169198; RELOC-NEXT: Function: 8
170; RELOC-NEXT: - Index: 7
199; RELOC-NEXT: - Index: 13
171200; RELOC-NEXT: Kind: FUNCTION
172201; RELOC-NEXT: Name: .Lregister_call_dtors.101
173202; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
174203; RELOC-NEXT: Function: 9
175; RELOC-NEXT: - Index: 8
176; RELOC-NEXT: Kind: DATA
177; RELOC-NEXT: Name: __dso_handle
178; RELOC-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN, UNDEFINED ]
179; RELOC-NEXT: - Index: 9
204; RELOC-NEXT: - Index: 14
180205; RELOC-NEXT: Kind: FUNCTION
181206; RELOC-NEXT: Name: .Lcall_dtors.1001
182207; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
183208; RELOC-NEXT: Function: 10
184; RELOC-NEXT: - Index: 10
209; RELOC-NEXT: - Index: 15
185210; RELOC-NEXT: Kind: FUNCTION
186211; RELOC-NEXT: Name: .Lregister_call_dtors.1001
187212; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
188213; RELOC-NEXT: Function: 11
189; RELOC-NEXT: - Index: 11
214; RELOC-NEXT: - Index: 16
190215; RELOC-NEXT: Kind: FUNCTION
191216; RELOC-NEXT: Name: .Lcall_dtors.4000
192217; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
193218; RELOC-NEXT: Function: 12
194; RELOC-NEXT: - Index: 12
195; RELOC-NEXT: Kind: FUNCTION
196; RELOC-NEXT: Name: externDtor
197; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN, UNDEFINED ]
198; RELOC-NEXT: Function: 0
199; RELOC-NEXT: - Index: 13
219; RELOC-NEXT: - Index: 17
200220; RELOC-NEXT: Kind: FUNCTION
201221; RELOC-NEXT: Name: .Lregister_call_dtors.4000
202222; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
203223; RELOC-NEXT: Function: 13
204; RELOC-NEXT: - Index: 14
205; RELOC-NEXT: Kind: FUNCTION
206; RELOC-NEXT: Name: externCtor
207; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN, UNDEFINED ]
208; RELOC-NEXT: Function: 1
209; RELOC-NEXT: - Index: 15
210; RELOC-NEXT: Kind: FUNCTION
211; RELOC-NEXT: Name: myctor
212; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
213; RELOC-NEXT: Function: 14
214; RELOC-NEXT: - Index: 16
215; RELOC-NEXT: Kind: FUNCTION
216; RELOC-NEXT: Name: mydtor
217; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
218; RELOC-NEXT: Function: 15
219; RELOC-NEXT: - Index: 17
220; RELOC-NEXT: Kind: GLOBAL
221; RELOC-NEXT: Name: __stack_pointer
222; RELOC-NEXT: Flags: [ UNDEFINED ]
223; RELOC-NEXT: Global: 0
224224; RELOC-NEXT: - Index: 18
225225; RELOC-NEXT: Kind: FUNCTION
226226; RELOC-NEXT: Name: .Lcall_dtors.101
......@@ -251,36 +251,36 @@ entry:
251251; RELOC-NEXT: Name: .Lregister_call_dtors.2002
252252; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
253253; RELOC-NEXT: Function: 21
254; RELOC-NEXT: InitFunctions:
254; RELOC-NEXT: InitFunctions:
255255; RELOC-NEXT: - Priority: 101
256256; RELOC-NEXT: Symbol: 0
257257; RELOC-NEXT: - Priority: 101
258258; RELOC-NEXT: Symbol: 1
259259; RELOC-NEXT: - Priority: 101
260; RELOC-NEXT: Symbol: 7
260; RELOC-NEXT: Symbol: 13
261261; RELOC-NEXT: - Priority: 101
262; RELOC-NEXT: Symbol: 15
262; RELOC-NEXT: Symbol: 9
263263; RELOC-NEXT: - Priority: 101
264264; RELOC-NEXT: Symbol: 19
265265; RELOC-NEXT: - Priority: 202
266; RELOC-NEXT: Symbol: 15
266; RELOC-NEXT: Symbol: 9
267267; RELOC-NEXT: - Priority: 202
268268; RELOC-NEXT: Symbol: 21
269269; RELOC-NEXT: - Priority: 1001
270270; RELOC-NEXT: Symbol: 0
271271; RELOC-NEXT: - Priority: 1001
272; RELOC-NEXT: Symbol: 10
273; RELOC-NEXT: - Priority: 2002
274272; RELOC-NEXT: Symbol: 15
275273; RELOC-NEXT: - Priority: 2002
274; RELOC-NEXT: Symbol: 9
275; RELOC-NEXT: - Priority: 2002
276276; RELOC-NEXT: Symbol: 23
277277; RELOC-NEXT: - Priority: 4000
278; RELOC-NEXT: Symbol: 14
278; RELOC-NEXT: Symbol: 8
279279; RELOC-NEXT: - Priority: 4000
280; RELOC-NEXT: Symbol: 13
280; RELOC-NEXT: Symbol: 17
281281; RELOC-NEXT: - Type: CUSTOM
282282; RELOC-NEXT: Name: name
283; RELOC-NEXT: FunctionNames:
283; RELOC-NEXT: FunctionNames:
284284; RELOC-NEXT: - Index: 0
285285; RELOC-NEXT: Name: externDtor
286286; RELOC-NEXT: - Index: 1
deps/lld/test/wasm/locals-duplicate.test+73-73
......@@ -270,40 +270,40 @@
270270; RELOC-NEXT: - Type: CODE
271271; RELOC-NEXT: Relocations:
272272; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
273; RELOC-NEXT: Index: 4
273; RELOC-NEXT: Index: 18
274274; RELOC-NEXT: Offset: 0x00000013
275275; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
276; RELOC-NEXT: Index: 6
276; RELOC-NEXT: Index: 3
277277; RELOC-NEXT: Offset: 0x0000001C
278278; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
279; RELOC-NEXT: Index: 8
279; RELOC-NEXT: Index: 19
280280; RELOC-NEXT: Offset: 0x00000025
281281; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
282; RELOC-NEXT: Index: 0
282; RELOC-NEXT: Index: 16
283283; RELOC-NEXT: Offset: 0x0000002E
284284; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
285; RELOC-NEXT: Index: 1
285; RELOC-NEXT: Index: 0
286286; RELOC-NEXT: Offset: 0x00000037
287287; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
288; RELOC-NEXT: Index: 2
288; RELOC-NEXT: Index: 17
289289; RELOC-NEXT: Offset: 0x00000040
290290; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
291; RELOC-NEXT: Index: 16
291; RELOC-NEXT: Index: 10
292292; RELOC-NEXT: Offset: 0x00000058
293293; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
294; RELOC-NEXT: Index: 18
294; RELOC-NEXT: Index: 22
295295; RELOC-NEXT: Offset: 0x00000061
296296; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
297; RELOC-NEXT: Index: 20
297; RELOC-NEXT: Index: 23
298298; RELOC-NEXT: Offset: 0x0000006A
299299; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
300; RELOC-NEXT: Index: 12
300; RELOC-NEXT: Index: 8
301301; RELOC-NEXT: Offset: 0x00000073
302302; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
303; RELOC-NEXT: Index: 13
303; RELOC-NEXT: Index: 20
304304; RELOC-NEXT: Offset: 0x0000007C
305305; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
306; RELOC-NEXT: Index: 14
306; RELOC-NEXT: Index: 21
307307; RELOC-NEXT: Offset: 0x00000085
308308; RELOC-NEXT: Functions:
309309; RELOC-NEXT: - Index: 0
......@@ -386,133 +386,133 @@
386386; RELOC-NEXT: SymbolTable:
387387; RELOC-NEXT: - Index: 0
388388; RELOC-NEXT: Kind: FUNCTION
389; RELOC-NEXT: Name: colliding_func1
390; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
391; RELOC-NEXT: Function: 0
392; RELOC-NEXT: - Index: 1
393; RELOC-NEXT: Kind: FUNCTION
394389; RELOC-NEXT: Name: colliding_func2
395390; RELOC-NEXT: Flags: [ ]
396391; RELOC-NEXT: Function: 1
397; RELOC-NEXT: - Index: 2
398; RELOC-NEXT: Kind: FUNCTION
399; RELOC-NEXT: Name: colliding_func3
400; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
401; RELOC-NEXT: Function: 2
402; RELOC-NEXT: - Index: 3
392; RELOC-NEXT: - Index: 1
403393; RELOC-NEXT: Kind: FUNCTION
404394; RELOC-NEXT: Name: get_global1A
405395; RELOC-NEXT: Flags: [ ]
406396; RELOC-NEXT: Function: 3
407; RELOC-NEXT: - Index: 4
408; RELOC-NEXT: Kind: DATA
409; RELOC-NEXT: Name: colliding_global1
410; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
411; RELOC-NEXT: Segment: 0
412; RELOC-NEXT: Size: 4
413; RELOC-NEXT: - Index: 5
397; RELOC-NEXT: - Index: 2
414398; RELOC-NEXT: Kind: FUNCTION
415399; RELOC-NEXT: Name: get_global2A
416400; RELOC-NEXT: Flags: [ ]
417401; RELOC-NEXT: Function: 4
418; RELOC-NEXT: - Index: 6
402; RELOC-NEXT: - Index: 3
419403; RELOC-NEXT: Kind: DATA
420404; RELOC-NEXT: Name: colliding_global2
421405; RELOC-NEXT: Flags: [ ]
422406; RELOC-NEXT: Segment: 1
423407; RELOC-NEXT: Size: 4
424; RELOC-NEXT: - Index: 7
408; RELOC-NEXT: - Index: 4
425409; RELOC-NEXT: Kind: FUNCTION
426410; RELOC-NEXT: Name: get_global3A
427411; RELOC-NEXT: Flags: [ ]
428412; RELOC-NEXT: Function: 5
429; RELOC-NEXT: - Index: 8
430; RELOC-NEXT: Kind: DATA
431; RELOC-NEXT: Name: colliding_global3
432; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
433; RELOC-NEXT: Segment: 2
434; RELOC-NEXT: Size: 4
435; RELOC-NEXT: - Index: 9
413; RELOC-NEXT: - Index: 5
436414; RELOC-NEXT: Kind: FUNCTION
437415; RELOC-NEXT: Name: get_func1A
438416; RELOC-NEXT: Flags: [ ]
439417; RELOC-NEXT: Function: 6
440; RELOC-NEXT: - Index: 10
418; RELOC-NEXT: - Index: 6
441419; RELOC-NEXT: Kind: FUNCTION
442420; RELOC-NEXT: Name: get_func2A
443421; RELOC-NEXT: Flags: [ ]
444422; RELOC-NEXT: Function: 7
445; RELOC-NEXT: - Index: 11
423; RELOC-NEXT: - Index: 7
446424; RELOC-NEXT: Kind: FUNCTION
447425; RELOC-NEXT: Name: get_func3A
448426; RELOC-NEXT: Flags: [ ]
449427; RELOC-NEXT: Function: 8
450; RELOC-NEXT: - Index: 12
428; RELOC-NEXT: - Index: 8
451429; RELOC-NEXT: Kind: FUNCTION
452430; RELOC-NEXT: Name: colliding_func1
453431; RELOC-NEXT: Flags: [ ]
454432; RELOC-NEXT: Function: 9
455; RELOC-NEXT: - Index: 13
456; RELOC-NEXT: Kind: FUNCTION
457; RELOC-NEXT: Name: colliding_func2
458; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
459; RELOC-NEXT: Function: 10
460; RELOC-NEXT: - Index: 14
461; RELOC-NEXT: Kind: FUNCTION
462; RELOC-NEXT: Name: colliding_func3
463; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
464; RELOC-NEXT: Function: 11
465; RELOC-NEXT: - Index: 15
433; RELOC-NEXT: - Index: 9
466434; RELOC-NEXT: Kind: FUNCTION
467435; RELOC-NEXT: Name: get_global1B
468436; RELOC-NEXT: Flags: [ ]
469437; RELOC-NEXT: Function: 12
470; RELOC-NEXT: - Index: 16
438; RELOC-NEXT: - Index: 10
471439; RELOC-NEXT: Kind: DATA
472440; RELOC-NEXT: Name: colliding_global1
473441; RELOC-NEXT: Flags: [ ]
474442; RELOC-NEXT: Segment: 0
475443; RELOC-NEXT: Offset: 4
476444; RELOC-NEXT: Size: 4
477; RELOC-NEXT: - Index: 17
445; RELOC-NEXT: - Index: 11
478446; RELOC-NEXT: Kind: FUNCTION
479447; RELOC-NEXT: Name: get_global2B
480448; RELOC-NEXT: Flags: [ ]
481449; RELOC-NEXT: Function: 13
482; RELOC-NEXT: - Index: 18
483; RELOC-NEXT: Kind: DATA
484; RELOC-NEXT: Name: colliding_global2
485; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
486; RELOC-NEXT: Segment: 1
487; RELOC-NEXT: Offset: 4
488; RELOC-NEXT: Size: 4
489; RELOC-NEXT: - Index: 19
450; RELOC-NEXT: - Index: 12
490451; RELOC-NEXT: Kind: FUNCTION
491452; RELOC-NEXT: Name: get_global3B
492453; RELOC-NEXT: Flags: [ ]
493454; RELOC-NEXT: Function: 14
494; RELOC-NEXT: - Index: 20
495; RELOC-NEXT: Kind: DATA
496; RELOC-NEXT: Name: colliding_global3
497; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
498; RELOC-NEXT: Segment: 2
499; RELOC-NEXT: Offset: 4
500; RELOC-NEXT: Size: 4
501; RELOC-NEXT: - Index: 21
455; RELOC-NEXT: - Index: 13
502456; RELOC-NEXT: Kind: FUNCTION
503457; RELOC-NEXT: Name: get_func1B
504458; RELOC-NEXT: Flags: [ ]
505459; RELOC-NEXT: Function: 15
506; RELOC-NEXT: - Index: 22
460; RELOC-NEXT: - Index: 14
507461; RELOC-NEXT: Kind: FUNCTION
508462; RELOC-NEXT: Name: get_func2B
509463; RELOC-NEXT: Flags: [ ]
510464; RELOC-NEXT: Function: 16
511; RELOC-NEXT: - Index: 23
465; RELOC-NEXT: - Index: 15
512466; RELOC-NEXT: Kind: FUNCTION
513467; RELOC-NEXT: Name: get_func3B
514468; RELOC-NEXT: Flags: [ ]
515469; RELOC-NEXT: Function: 17
470; RELOC-NEXT: - Index: 16
471; RELOC-NEXT: Kind: FUNCTION
472; RELOC-NEXT: Name: colliding_func1
473; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
474; RELOC-NEXT: Function: 0
475; RELOC-NEXT: - Index: 17
476; RELOC-NEXT: Kind: FUNCTION
477; RELOC-NEXT: Name: colliding_func3
478; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
479; RELOC-NEXT: Function: 2
480; RELOC-NEXT: - Index: 18
481; RELOC-NEXT: Kind: DATA
482; RELOC-NEXT: Name: colliding_global1
483; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
484; RELOC-NEXT: Segment: 0
485; RELOC-NEXT: Size: 4
486; RELOC-NEXT: - Index: 19
487; RELOC-NEXT: Kind: DATA
488; RELOC-NEXT: Name: colliding_global3
489; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
490; RELOC-NEXT: Segment: 2
491; RELOC-NEXT: Size: 4
492; RELOC-NEXT: - Index: 20
493; RELOC-NEXT: Kind: FUNCTION
494; RELOC-NEXT: Name: colliding_func2
495; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
496; RELOC-NEXT: Function: 10
497; RELOC-NEXT: - Index: 21
498; RELOC-NEXT: Kind: FUNCTION
499; RELOC-NEXT: Name: colliding_func3
500; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
501; RELOC-NEXT: Function: 11
502; RELOC-NEXT: - Index: 22
503; RELOC-NEXT: Kind: DATA
504; RELOC-NEXT: Name: colliding_global2
505; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
506; RELOC-NEXT: Segment: 1
507; RELOC-NEXT: Offset: 4
508; RELOC-NEXT: Size: 4
509; RELOC-NEXT: - Index: 23
510; RELOC-NEXT: Kind: DATA
511; RELOC-NEXT: Name: colliding_global3
512; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
513; RELOC-NEXT: Segment: 2
514; RELOC-NEXT: Offset: 4
515; RELOC-NEXT: Size: 4
516516; RELOC-NEXT: SegmentInfo:
517517; RELOC-NEXT: - Index: 0
518518; RELOC-NEXT: Name: .bss.colliding_global1
deps/lld/test/wasm/lto/relocatable-undefined.ll created+36
......@@ -0,0 +1,36 @@
1; RUN: llvm-as %s -o %t.o
2; RUN: wasm-ld -r -o %t.wasm %t.o
3; RUN: obj2yaml %t.wasm | FileCheck %s
4
5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6target triple = "wasm32-unknown-unknown"
7
8@missing_data = external global i32
9declare i32 @missing_func() local_unnamed_addr
10
11define i32 @foo() {
12entry:
13 %0 = call i32 @missing_func()
14 %1 = load i32, i32* @missing_data, align 4
15 ret i32 %1
16}
17
18
19; CHECK: - Type: CUSTOM
20; CHECK-NEXT: Name: linking
21; CHECK-NEXT: Version: 2
22; CHECK-NEXT: SymbolTable:
23; CHECK-NEXT: - Index: 0
24; CHECK-NEXT: Kind: FUNCTION
25; CHECK-NEXT: Name: missing_func
26; CHECK-NEXT: Flags: [ UNDEFINED ]
27; CHECK-NEXT: Function: 0
28; CHECK-NEXT: - Index: 1
29; CHECK-NEXT: Kind: FUNCTION
30; CHECK-NEXT: Name: foo
31; CHECK-NEXT: Flags: [ ]
32; CHECK-NEXT: Function: 1
33; CHECK-NEXT: - Index: 2
34; CHECK-NEXT: Kind: DATA
35; CHECK-NEXT: Name: missing_data
36; CHECK-NEXT: Flags: [ UNDEFINED ]
deps/lld/test/wasm/weak-alias.ll+14-14
......@@ -187,13 +187,13 @@ entry:
187187; RELOC-NEXT: - Type: CODE
188188; RELOC-NEXT: Relocations:
189189; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
190; RELOC-NEXT: Index: 4
190; RELOC-NEXT: Index: 1
191191; RELOC-NEXT: Offset: 0x00000004
192192; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
193; RELOC-NEXT: Index: 1
193; RELOC-NEXT: Index: 2
194194; RELOC-NEXT: Offset: 0x00000013
195195; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
196; RELOC-NEXT: Index: 4
196; RELOC-NEXT: Index: 1
197197; RELOC-NEXT: Offset: 0x0000001C
198198; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB
199199; RELOC-NEXT: Index: 6
......@@ -202,10 +202,10 @@ entry:
202202; RELOC-NEXT: Index: 6
203203; RELOC-NEXT: Offset: 0x00000032
204204; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
205; RELOC-NEXT: Index: 4
205; RELOC-NEXT: Index: 1
206206; RELOC-NEXT: Offset: 0x0000003A
207207; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
208; RELOC-NEXT: Index: 4
208; RELOC-NEXT: Index: 1
209209; RELOC-NEXT: Offset: 0x00000043
210210; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB
211211; RELOC-NEXT: Index: 6
......@@ -217,10 +217,10 @@ entry:
217217; RELOC-NEXT: Index: 6
218218; RELOC-NEXT: Offset: 0x00000068
219219; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
220; RELOC-NEXT: Index: 1
220; RELOC-NEXT: Index: 2
221221; RELOC-NEXT: Offset: 0x00000070
222222; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
223; RELOC-NEXT: Index: 1
223; RELOC-NEXT: Index: 2
224224; RELOC-NEXT: Offset: 0x00000079
225225; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB
226226; RELOC-NEXT: Index: 6
......@@ -259,24 +259,24 @@ entry:
259259; RELOC-NEXT: Function: 0
260260; RELOC-NEXT: - Index: 1
261261; RELOC-NEXT: Kind: FUNCTION
262; RELOC-NEXT: Name: alias_fn
263; RELOC-NEXT: Flags: [ BINDING_WEAK ]
264; RELOC-NEXT: Function: 1
265; RELOC-NEXT: - Index: 2
266; RELOC-NEXT: Kind: FUNCTION
262267; RELOC-NEXT: Name: direct_fn
263268; RELOC-NEXT: Flags: [ ]
264269; RELOC-NEXT: Function: 1
265; RELOC-NEXT: - Index: 2
270; RELOC-NEXT: - Index: 3
266271; RELOC-NEXT: Kind: FUNCTION
267272; RELOC-NEXT: Name: call_direct
268273; RELOC-NEXT: Flags: [ ]
269274; RELOC-NEXT: Function: 2
270; RELOC-NEXT: - Index: 3
275; RELOC-NEXT: - Index: 4
271276; RELOC-NEXT: Kind: FUNCTION
272277; RELOC-NEXT: Name: call_alias
273278; RELOC-NEXT: Flags: [ ]
274279; RELOC-NEXT: Function: 3
275; RELOC-NEXT: - Index: 4
276; RELOC-NEXT: Kind: FUNCTION
277; RELOC-NEXT: Name: alias_fn
278; RELOC-NEXT: Flags: [ BINDING_WEAK ]
279; RELOC-NEXT: Function: 1
280280; RELOC-NEXT: - Index: 5
281281; RELOC-NEXT: Kind: FUNCTION
282282; RELOC-NEXT: Name: call_alias_ptr
deps/lld/wasm/Driver.cpp+3-1
......@@ -434,7 +434,9 @@ static Symbol *handleUndefined(StringRef Name) {
434434static UndefinedGlobal *
435435createUndefinedGlobal(StringRef Name, llvm::wasm::WasmGlobalType *Type) {
436436 auto *Sym =
437 cast<UndefinedGlobal>(Symtab->addUndefinedGlobal(Name, 0, nullptr, Type));
437 cast<UndefinedGlobal>(Symtab->addUndefinedGlobal(Name, Name,
438 DefaultModule, 0,
439 nullptr, Type));
438440 Config->AllowUndefinedSymbols.insert(Sym->getName());
439441 Sym->IsUsedInRegularObj = true;
440442 return Sym;
deps/lld/wasm/InputChunks.cpp+3-3
......@@ -23,7 +23,7 @@ using namespace llvm::support::endian;
2323using namespace lld;
2424using namespace lld::wasm;
2525
26static StringRef ReloctTypeToString(uint8_t RelocType) {
26static StringRef reloctTypeToString(uint8_t RelocType) {
2727 switch (RelocType) {
2828#define WASM_RELOC(NAME, REL) \
2929 case REL: \
......@@ -77,7 +77,7 @@ void InputChunk::verifyRelocTargets() const {
7777 warn("expected LEB at relocation site be 5-byte padded");
7878 uint32_t ExpectedValue = File->calcExpectedValue(Rel);
7979 if (ExpectedValue != ExistingValue)
80 warn("unexpected existing value for " + ReloctTypeToString(Rel.Type) +
80 warn("unexpected existing value for " + reloctTypeToString(Rel.Type) +
8181 ": existing=" + Twine(ExistingValue) +
8282 " expected=" + Twine(ExpectedValue));
8383 }
......@@ -103,7 +103,7 @@ void InputChunk::writeTo(uint8_t *Buf) const {
103103 for (const WasmRelocation &Rel : Relocations) {
104104 uint8_t *Loc = Buf + Rel.Offset + Off;
105105 uint32_t Value = File->calcNewValue(Rel);
106 LLVM_DEBUG(dbgs() << "apply reloc: type=" << ReloctTypeToString(Rel.Type)
106 LLVM_DEBUG(dbgs() << "apply reloc: type=" << reloctTypeToString(Rel.Type)
107107 << " addend=" << Rel.Addend << " index=" << Rel.Index
108108 << " value=" << Value << " offset=" << Rel.Offset
109109 << "\n");
deps/lld/wasm/InputFiles.cpp+8-3
......@@ -377,11 +377,15 @@ Symbol *ObjFile::createUndefined(const WasmSymbol &Sym) {
377377
378378 switch (Sym.Info.Kind) {
379379 case WASM_SYMBOL_TYPE_FUNCTION:
380 return Symtab->addUndefinedFunction(Name, Flags, this, Sym.Signature);
380 return Symtab->addUndefinedFunction(Name, Sym.Info.ImportName,
381 Sym.Info.ImportModule, Flags, this,
382 Sym.Signature);
381383 case WASM_SYMBOL_TYPE_DATA:
382384 return Symtab->addUndefinedData(Name, Flags, this);
383385 case WASM_SYMBOL_TYPE_GLOBAL:
384 return Symtab->addUndefinedGlobal(Name, Flags, this, Sym.GlobalType);
386 return Symtab->addUndefinedGlobal(Name, Sym.Info.ImportName,
387 Sym.Info.ImportModule, Flags, this,
388 Sym.GlobalType);
385389 case WASM_SYMBOL_TYPE_SECTION:
386390 llvm_unreachable("section symbols cannot be undefined");
387391 }
......@@ -445,7 +449,8 @@ static Symbol *createBitcodeSymbol(const lto::InputFile::Symbol &ObjSym,
445449
446450 if (ObjSym.isUndefined()) {
447451 if (ObjSym.isExecutable())
448 return Symtab->addUndefinedFunction(Name, Flags, &F, nullptr);
452 return Symtab->addUndefinedFunction(Name, Name, DefaultModule, Flags, &F,
453 nullptr);
449454 return Symtab->addUndefinedData(Name, Flags, &F);
450455 }
451456
deps/lld/wasm/LTO.cpp+3-2
......@@ -79,8 +79,9 @@ BitcodeCompiler::~BitcodeCompiler() = default;
7979
8080static void undefine(Symbol *S) {
8181 if (auto F = dyn_cast<DefinedFunction>(S))
82 replaceSymbol<UndefinedFunction>(F, F->getName(), 0, F->getFile(),
83 F->Signature);
82 replaceSymbol<UndefinedFunction>(F, F->getName(), F->getName(),
83 DefaultModule, 0,
84 F->getFile(), F->Signature);
8485 else if (isa<DefinedData>(S))
8586 replaceSymbol<UndefinedData>(S, S->getName(), 0, S->getFile());
8687 else
deps/lld/wasm/LTO.h+1
......@@ -23,6 +23,7 @@
2323
2424#include "lld/Common/LLVM.h"
2525#include "llvm/ADT/SmallString.h"
26#include "Writer.h"
2627#include <memory>
2728#include <vector>
2829
deps/lld/wasm/MarkLive.cpp+1-1
......@@ -85,7 +85,7 @@ void lld::wasm::markLive() {
8585 // equal to null pointer, only reachable via direct call).
8686 if (Reloc.Type == R_WEBASSEMBLY_TABLE_INDEX_SLEB ||
8787 Reloc.Type == R_WEBASSEMBLY_TABLE_INDEX_I32) {
88 FunctionSymbol *FuncSym = cast<FunctionSymbol>(Sym);
88 auto *FuncSym = cast<FunctionSymbol>(Sym);
8989 if (FuncSym->hasTableIndex() && FuncSym->getTableIndex() == 0)
9090 continue;
9191 }
deps/lld/wasm/SymbolTable.cpp+9-5
......@@ -314,8 +314,9 @@ Symbol *SymbolTable::addDefinedEvent(StringRef Name, uint32_t Flags,
314314 return S;
315315}
316316
317Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags,
318 InputFile *File,
317Symbol *SymbolTable::addUndefinedFunction(StringRef Name, StringRef ImportName,
318 StringRef ImportModule,
319 uint32_t Flags, InputFile *File,
319320 const WasmSignature *Sig) {
320321 LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name <<
321322 " [" << (Sig ? toString(*Sig) : "none") << "]\n");
......@@ -325,7 +326,8 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags,
325326 std::tie(S, WasInserted) = insert(Name, File);
326327
327328 if (WasInserted)
328 replaceSymbol<UndefinedFunction>(S, Name, Flags, File, Sig);
329 replaceSymbol<UndefinedFunction>(S, Name, ImportName, ImportModule, Flags,
330 File, Sig);
329331 else if (auto *Lazy = dyn_cast<LazySymbol>(S))
330332 Lazy->fetch();
331333 else
......@@ -351,7 +353,8 @@ Symbol *SymbolTable::addUndefinedData(StringRef Name, uint32_t Flags,
351353 return S;
352354}
353355
354Symbol *SymbolTable::addUndefinedGlobal(StringRef Name, uint32_t Flags,
356Symbol *SymbolTable::addUndefinedGlobal(StringRef Name, StringRef ImportName,
357 StringRef ImportModule, uint32_t Flags,
355358 InputFile *File,
356359 const WasmGlobalType *Type) {
357360 LLVM_DEBUG(dbgs() << "addUndefinedGlobal: " << Name << "\n");
......@@ -361,7 +364,8 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef Name, uint32_t Flags,
361364 std::tie(S, WasInserted) = insert(Name, File);
362365
363366 if (WasInserted)
364 replaceSymbol<UndefinedGlobal>(S, Name, Flags, File, Type);
367 replaceSymbol<UndefinedGlobal>(S, Name, ImportName, ImportModule, Flags,
368 File, Type);
365369 else if (auto *Lazy = dyn_cast<LazySymbol>(S))
366370 Lazy->fetch();
367371 else if (S->isDefined())
deps/lld/wasm/SymbolTable.h+6-4
......@@ -59,11 +59,13 @@ public:
5959 Symbol *addDefinedEvent(StringRef Name, uint32_t Flags, InputFile *File,
6060 InputEvent *E);
6161
62 Symbol *addUndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File,
63 const WasmSignature *Signature);
62 Symbol *addUndefinedFunction(StringRef Name, StringRef ImportName,
63 StringRef ImportModule, uint32_t Flags,
64 InputFile *File, const WasmSignature *Signature);
6465 Symbol *addUndefinedData(StringRef Name, uint32_t Flags, InputFile *File);
65 Symbol *addUndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
66 const WasmGlobalType *Type);
66 Symbol *addUndefinedGlobal(StringRef Name, StringRef ImportName,
67 StringRef ImportModule, uint32_t Flags,
68 InputFile *File, const WasmGlobalType *Type);
6769
6870 void addLazy(ArchiveFile *F, const llvm::object::Archive::Symbol *Sym);
6971
deps/lld/wasm/Symbols.h+15-4
......@@ -149,13 +149,19 @@ public:
149149
150150class UndefinedFunction : public FunctionSymbol {
151151public:
152 UndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File = nullptr,
152 UndefinedFunction(StringRef Name, StringRef ImportName,
153 StringRef ImportModule, uint32_t Flags,
154 InputFile *File = nullptr,
153155 const WasmSignature *Type = nullptr)
154 : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type) {}
156 : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type),
157 ImportName(ImportName), ImportModule(ImportModule) {}
155158
156159 static bool classof(const Symbol *S) {
157160 return S->kind() == UndefinedFunctionKind;
158161 }
162
163 StringRef ImportName;
164 StringRef ImportModule;
159165};
160166
161167class SectionSymbol : public Symbol {
......@@ -261,13 +267,18 @@ public:
261267
262268class UndefinedGlobal : public GlobalSymbol {
263269public:
264 UndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File = nullptr,
270 UndefinedGlobal(StringRef Name, StringRef ImportName, StringRef ImportModule,
271 uint32_t Flags, InputFile *File = nullptr,
265272 const WasmGlobalType *Type = nullptr)
266 : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File, Type) {}
273 : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File, Type),
274 ImportName(ImportName), ImportModule(ImportModule) {}
267275
268276 static bool classof(const Symbol *S) {
269277 return S->kind() == UndefinedGlobalKind;
270278 }
279
280 StringRef ImportName;
281 StringRef ImportModule;
271282};
272283
273284// Wasm events are features that suspend the current execution and transfer the
deps/lld/wasm/Writer.cpp+64-42
......@@ -39,8 +39,9 @@ using namespace llvm::wasm;
3939using namespace lld;
4040using namespace lld::wasm;
4141
42static constexpr int kStackAlignment = 16;
43static constexpr const char *kFunctionTableName = "__indirect_function_table";
42static constexpr int StackAlignment = 16;
43static constexpr const char *FunctionTableName = "__indirect_function_table";
44const char *lld::wasm::DefaultModule = "env";
4445
4546namespace {
4647
......@@ -155,7 +156,7 @@ void Writer::createImportSection() {
155156
156157 if (Config->ImportMemory) {
157158 WasmImport Import;
158 Import.Module = "env";
159 Import.Module = DefaultModule;
159160 Import.Field = "memory";
160161 Import.Kind = WASM_EXTERNAL_MEMORY;
161162 Import.Memory.Flags = 0;
......@@ -172,8 +173,8 @@ void Writer::createImportSection() {
172173 if (Config->ImportTable) {
173174 uint32_t TableSize = TableBase + IndirectFunctions.size();
174175 WasmImport Import;
175 Import.Module = "env";
176 Import.Field = kFunctionTableName;
176 Import.Module = DefaultModule;
177 Import.Field = FunctionTableName;
177178 Import.Kind = WASM_EXTERNAL_TABLE;
178179 Import.Table.ElemType = WASM_TYPE_FUNCREF;
179180 Import.Table.Limits = {0, TableSize, 0};
......@@ -182,8 +183,17 @@ void Writer::createImportSection() {
182183
183184 for (const Symbol *Sym : ImportedSymbols) {
184185 WasmImport Import;
185 Import.Module = "env";
186 Import.Field = Sym->getName();
186 if (auto *F = dyn_cast<UndefinedFunction>(Sym)) {
187 Import.Field = F->ImportName;
188 Import.Module = F->ImportModule;
189 } else if (auto *G = dyn_cast<UndefinedGlobal>(Sym)) {
190 Import.Field = G->ImportName;
191 Import.Module = G->ImportModule;
192 } else {
193 Import.Field = Sym->getName();
194 Import.Module = DefaultModule;
195 }
196
187197 if (auto *FunctionSym = dyn_cast<FunctionSymbol>(Sym)) {
188198 Import.Kind = WASM_EXTERNAL_FUNCTION;
189199 Import.SigIndex = lookupType(*FunctionSym->Signature);
......@@ -441,6 +451,13 @@ static uint32_t getWasmFlags(const Symbol *Sym) {
441451 Flags |= WASM_SYMBOL_VISIBILITY_HIDDEN;
442452 if (Sym->isUndefined())
443453 Flags |= WASM_SYMBOL_UNDEFINED;
454 if (auto *F = dyn_cast<UndefinedFunction>(Sym)) {
455 if (F->getName() != F->ImportName)
456 Flags |= WASM_SYMBOL_EXPLICIT_NAME;
457 } else if (auto *G = dyn_cast<UndefinedGlobal>(Sym)) {
458 if (G->getName() != G->ImportName)
459 Flags |= WASM_SYMBOL_EXPLICIT_NAME;
460 }
444461 return Flags;
445462}
446463
......@@ -506,15 +523,18 @@ void Writer::createLinkingSection() {
506523
507524 if (auto *F = dyn_cast<FunctionSymbol>(Sym)) {
508525 writeUleb128(Sub.OS, F->getFunctionIndex(), "index");
509 if (Sym->isDefined())
526 if (Sym->isDefined() ||
527 (Flags & WASM_SYMBOL_EXPLICIT_NAME) != 0)
510528 writeStr(Sub.OS, Sym->getName(), "sym name");
511529 } else if (auto *G = dyn_cast<GlobalSymbol>(Sym)) {
512530 writeUleb128(Sub.OS, G->getGlobalIndex(), "index");
513 if (Sym->isDefined())
531 if (Sym->isDefined() ||
532 (Flags & WASM_SYMBOL_EXPLICIT_NAME) != 0)
514533 writeStr(Sub.OS, Sym->getName(), "sym name");
515534 } else if (auto *E = dyn_cast<EventSymbol>(Sym)) {
516535 writeUleb128(Sub.OS, E->getEventIndex(), "index");
517 if (Sym->isDefined())
536 if (Sym->isDefined() ||
537 (Flags & WASM_SYMBOL_EXPLICIT_NAME) != 0)
518538 writeStr(Sub.OS, Sym->getName(), "sym name");
519539 } else if (isa<DataSymbol>(Sym)) {
520540 writeStr(Sub.OS, Sym->getName(), "sym name");
......@@ -663,9 +683,9 @@ void Writer::layoutMemory() {
663683 auto PlaceStack = [&]() {
664684 if (Config->Relocatable || Config->Shared)
665685 return;
666 MemoryPtr = alignTo(MemoryPtr, kStackAlignment);
667 if (Config->ZStackSize != alignTo(Config->ZStackSize, kStackAlignment))
668 error("stack size must be " + Twine(kStackAlignment) + "-byte aligned");
686 MemoryPtr = alignTo(MemoryPtr, StackAlignment);
687 if (Config->ZStackSize != alignTo(Config->ZStackSize, StackAlignment))
688 error("stack size must be " + Twine(StackAlignment) + "-byte aligned");
669689 log("mem: stack size = " + Twine(Config->ZStackSize));
670690 log("mem: stack base = " + Twine(MemoryPtr));
671691 MemoryPtr += Config->ZStackSize;
......@@ -814,7 +834,7 @@ void Writer::calculateExports() {
814834 Exports.push_back(WasmExport{"memory", WASM_EXTERNAL_MEMORY, 0});
815835
816836 if (!Config->Relocatable && Config->ExportTable)
817 Exports.push_back(WasmExport{kFunctionTableName, WASM_EXTERNAL_TABLE, 0});
837 Exports.push_back(WasmExport{FunctionTableName, WASM_EXTERNAL_TABLE, 0});
818838
819839 unsigned FakeGlobalIndex = NumImportedGlobals + InputGlobals.size();
820840
......@@ -858,40 +878,42 @@ void Writer::assignSymtab() {
858878 StringMap<uint32_t> SectionSymbolIndices;
859879
860880 unsigned SymbolIndex = SymtabEntries.size();
861 for (ObjFile *File : Symtab->ObjectFiles) {
862 LLVM_DEBUG(dbgs() << "Symtab entries: " << File->getName() << "\n");
863 for (Symbol *Sym : File->getSymbols()) {
864 if (Sym->getFile() != File)
865 continue;
866
867 if (auto *S = dyn_cast<SectionSymbol>(Sym)) {
868 StringRef Name = S->getName();
869 if (CustomSectionMapping.count(Name) == 0)
870 continue;
871
872 auto SSI = SectionSymbolIndices.find(Name);
873 if (SSI != SectionSymbolIndices.end()) {
874 Sym->setOutputSymbolIndex(SSI->second);
875 continue;
876 }
877881
878 SectionSymbolIndices[Name] = SymbolIndex;
879 CustomSectionSymbols[Name] = cast<SectionSymbol>(Sym);
882 auto AddSymbol = [&](Symbol *Sym) {
883 if (auto *S = dyn_cast<SectionSymbol>(Sym)) {
884 StringRef Name = S->getName();
885 if (CustomSectionMapping.count(Name) == 0)
886 return;
880887
881 Sym->markLive();
888 auto SSI = SectionSymbolIndices.find(Name);
889 if (SSI != SectionSymbolIndices.end()) {
890 Sym->setOutputSymbolIndex(SSI->second);
891 return;
882892 }
883893
884 // (Since this is relocatable output, GC is not performed so symbols must
885 // be live.)
886 assert(Sym->isLive());
887 Sym->setOutputSymbolIndex(SymbolIndex++);
888 SymtabEntries.emplace_back(Sym);
894 SectionSymbolIndices[Name] = SymbolIndex;
895 CustomSectionSymbols[Name] = cast<SectionSymbol>(Sym);
896
897 Sym->markLive();
889898 }
890 }
891899
892 // For the moment, relocatable output doesn't contain any synthetic functions,
893 // so no need to look through the Symtab for symbols not referenced by
894 // Symtab->ObjectFiles.
900 // (Since this is relocatable output, GC is not performed so symbols must
901 // be live.)
902 assert(Sym->isLive());
903 Sym->setOutputSymbolIndex(SymbolIndex++);
904 SymtabEntries.emplace_back(Sym);
905 };
906
907 for (Symbol *Sym : Symtab->getSymbols())
908 if (!Sym->isLazy())
909 AddSymbol(Sym);
910
911 for (ObjFile *File : Symtab->ObjectFiles) {
912 LLVM_DEBUG(dbgs() << "Local symtab entries: " << File->getName() << "\n");
913 for (Symbol *Sym : File->getSymbols())
914 if (Sym->isLocal())
915 AddSymbol(Sym);
916 }
895917}
896918
897919uint32_t Writer::lookupType(const WasmSignature &Sig) {
deps/lld/wasm/Writer.h+2
......@@ -15,6 +15,8 @@ namespace wasm {
1515
1616void writeResult();
1717
18extern const char *DefaultModule;
19
1820} // namespace wasm
1921} // namespace lld
2022