[WebAssembly] Fix crash with LTO + relocatable + undefined symbols

Change the way we create the symbol table to be closer to how its done
on ELF.  Now the output symbol table matches the internal symtab order
and includes local and undefined symbols.

Fixes PR40204

Differential Revision: https://reviews.llvm.org/D56947

llvm-svn: 352645
This commit is contained in:
Sam Clegg 2019-01-30 18:55:15 +00:00
parent edb874b231
commit 89e4dcb4be
6 changed files with 204 additions and 166 deletions

View File

@ -85,10 +85,10 @@ target triple = "wasm32-unknown-unknown"
; RELOC: - Type: DATA
; RELOC-NEXT: Relocations:
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
; RELOC-NEXT: Index: 6
; RELOC-NEXT: Index: 3
; RELOC-NEXT: Offset: 0x00000018
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
; RELOC-NEXT: Index: 3
; RELOC-NEXT: Index: 4
; RELOC-NEXT: Offset: 0x0000002E
; RELOC-NEXT: Addend: 4
; RELOC-NEXT: Segments:
@ -148,7 +148,7 @@ target triple = "wasm32-unknown-unknown"
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Segment: 2
; RELOC-NEXT: Size: 4
; RELOC: - Index: 6
; RELOC-NEXT: - Index: 3
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: hello_str
; RELOC-NEXT: Flags: [ ]

View File

@ -163,64 +163,64 @@ entry:
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: Function: 7
; RELOC-NEXT: - Index: 6
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.101
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 8
; RELOC-NEXT: - Index: 7
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.101
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 9
; RELOC-NEXT: - Index: 8
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: __dso_handle
; RELOC-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN, UNDEFINED ]
; RELOC-NEXT: - Index: 9
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.1001
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 10
; RELOC-NEXT: - Index: 10
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.1001
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 11
; RELOC-NEXT: - Index: 11
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.4000
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 12
; RELOC-NEXT: - Index: 12
; RELOC-NEXT: - Index: 7
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: externDtor
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN, UNDEFINED ]
; RELOC-NEXT: Function: 0
; RELOC-NEXT: - Index: 13
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.4000
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 13
; RELOC-NEXT: - Index: 14
; RELOC-NEXT: - Index: 8
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: externCtor
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN, UNDEFINED ]
; RELOC-NEXT: Function: 1
; RELOC-NEXT: - Index: 15
; RELOC-NEXT: - Index: 9
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: myctor
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: Function: 14
; RELOC-NEXT: - Index: 16
; RELOC-NEXT: - Index: 10
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: mydtor
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: Function: 15
; RELOC-NEXT: - Index: 17
; RELOC-NEXT: - Index: 11
; RELOC-NEXT: Kind: GLOBAL
; RELOC-NEXT: Name: __stack_pointer
; RELOC-NEXT: Flags: [ UNDEFINED ]
; RELOC-NEXT: Global: 0
; RELOC-NEXT: - Index: 12
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.101
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 8
; RELOC-NEXT: - Index: 13
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.101
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 9
; RELOC-NEXT: - Index: 14
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.1001
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 10
; RELOC-NEXT: - Index: 15
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.1001
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 11
; RELOC-NEXT: - Index: 16
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.4000
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 12
; RELOC-NEXT: - Index: 17
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.4000
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 13
; RELOC-NEXT: - Index: 18
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.101
@ -251,36 +251,36 @@ entry:
; RELOC-NEXT: Name: .Lregister_call_dtors.2002
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 21
; RELOC-NEXT: InitFunctions:
; RELOC-NEXT: InitFunctions:
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: Symbol: 0
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: Symbol: 1
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: Symbol: 7
; RELOC-NEXT: Symbol: 13
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: Symbol: 15
; RELOC-NEXT: Symbol: 9
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: Symbol: 19
; RELOC-NEXT: - Priority: 202
; RELOC-NEXT: Symbol: 15
; RELOC-NEXT: Symbol: 9
; RELOC-NEXT: - Priority: 202
; RELOC-NEXT: Symbol: 21
; RELOC-NEXT: - Priority: 1001
; RELOC-NEXT: Symbol: 0
; RELOC-NEXT: - Priority: 1001
; RELOC-NEXT: Symbol: 10
; RELOC-NEXT: - Priority: 2002
; RELOC-NEXT: Symbol: 15
; RELOC-NEXT: - Priority: 2002
; RELOC-NEXT: Symbol: 9
; RELOC-NEXT: - Priority: 2002
; RELOC-NEXT: Symbol: 23
; RELOC-NEXT: - Priority: 4000
; RELOC-NEXT: Symbol: 14
; RELOC-NEXT: Symbol: 8
; RELOC-NEXT: - Priority: 4000
; RELOC-NEXT: Symbol: 13
; RELOC-NEXT: Symbol: 17
; RELOC-NEXT: - Type: CUSTOM
; RELOC-NEXT: Name: name
; RELOC-NEXT: FunctionNames:
; RELOC-NEXT: FunctionNames:
; RELOC-NEXT: - Index: 0
; RELOC-NEXT: Name: externDtor
; RELOC-NEXT: - Index: 1

View File

@ -270,40 +270,40 @@
; RELOC-NEXT: - Type: CODE
; RELOC-NEXT: Relocations:
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
; RELOC-NEXT: Index: 4
; RELOC-NEXT: Index: 18
; RELOC-NEXT: Offset: 0x00000013
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
; RELOC-NEXT: Index: 6
; RELOC-NEXT: Index: 3
; RELOC-NEXT: Offset: 0x0000001C
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
; RELOC-NEXT: Index: 8
; RELOC-NEXT: Index: 19
; RELOC-NEXT: Offset: 0x00000025
; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
; RELOC-NEXT: Index: 0
; RELOC-NEXT: Index: 16
; RELOC-NEXT: Offset: 0x0000002E
; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
; RELOC-NEXT: Index: 1
; RELOC-NEXT: Index: 0
; RELOC-NEXT: Offset: 0x00000037
; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
; RELOC-NEXT: Index: 2
; RELOC-NEXT: Index: 17
; RELOC-NEXT: Offset: 0x00000040
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
; RELOC-NEXT: Index: 16
; RELOC-NEXT: Index: 10
; RELOC-NEXT: Offset: 0x00000058
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
; RELOC-NEXT: Index: 18
; RELOC-NEXT: Index: 22
; RELOC-NEXT: Offset: 0x00000061
; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
; RELOC-NEXT: Index: 20
; RELOC-NEXT: Index: 23
; RELOC-NEXT: Offset: 0x0000006A
; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
; RELOC-NEXT: Index: 12
; RELOC-NEXT: Index: 8
; RELOC-NEXT: Offset: 0x00000073
; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
; RELOC-NEXT: Index: 13
; RELOC-NEXT: Index: 20
; RELOC-NEXT: Offset: 0x0000007C
; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
; RELOC-NEXT: Index: 14
; RELOC-NEXT: Index: 21
; RELOC-NEXT: Offset: 0x00000085
; RELOC-NEXT: Functions:
; RELOC-NEXT: - Index: 0
@ -386,133 +386,133 @@
; RELOC-NEXT: SymbolTable:
; RELOC-NEXT: - Index: 0
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func1
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 0
; RELOC-NEXT: - Index: 1
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func2
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 1
; RELOC-NEXT: - Index: 2
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func3
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 2
; RELOC-NEXT: - Index: 3
; RELOC-NEXT: - Index: 1
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_global1A
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 3
; RELOC-NEXT: - Index: 4
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: colliding_global1
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Segment: 0
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 5
; RELOC-NEXT: - Index: 2
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_global2A
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 4
; RELOC-NEXT: - Index: 6
; RELOC-NEXT: - Index: 3
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: colliding_global2
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Segment: 1
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 7
; RELOC-NEXT: - Index: 4
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_global3A
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 5
; RELOC-NEXT: - Index: 8
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: colliding_global3
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Segment: 2
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 9
; RELOC-NEXT: - Index: 5
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func1A
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 6
; RELOC-NEXT: - Index: 10
; RELOC-NEXT: - Index: 6
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func2A
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 7
; RELOC-NEXT: - Index: 11
; RELOC-NEXT: - Index: 7
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func3A
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 8
; RELOC-NEXT: - Index: 12
; RELOC-NEXT: - Index: 8
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func1
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 9
; RELOC-NEXT: - Index: 13
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func2
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 10
; RELOC-NEXT: - Index: 14
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func3
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 11
; RELOC-NEXT: - Index: 15
; RELOC-NEXT: - Index: 9
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_global1B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 12
; RELOC-NEXT: - Index: 16
; RELOC-NEXT: - Index: 10
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: colliding_global1
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Segment: 0
; RELOC-NEXT: Offset: 4
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 17
; RELOC-NEXT: - Index: 11
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_global2B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 13
; RELOC-NEXT: - Index: 12
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_global3B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 14
; RELOC-NEXT: - Index: 13
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func1B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 15
; RELOC-NEXT: - Index: 14
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func2B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 16
; RELOC-NEXT: - Index: 15
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func3B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 17
; RELOC-NEXT: - Index: 16
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func1
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 0
; RELOC-NEXT: - Index: 17
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func3
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 2
; RELOC-NEXT: - Index: 18
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: colliding_global1
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Segment: 0
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 19
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: colliding_global3
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Segment: 2
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 20
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func2
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 10
; RELOC-NEXT: - Index: 21
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: colliding_func3
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 11
; RELOC-NEXT: - Index: 22
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: colliding_global2
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Segment: 1
; RELOC-NEXT: Offset: 4
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 19
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_global3B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 14
; RELOC-NEXT: - Index: 20
; RELOC-NEXT: - Index: 23
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: colliding_global3
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Segment: 2
; RELOC-NEXT: Offset: 4
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 21
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func1B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 15
; RELOC-NEXT: - Index: 22
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func2B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 16
; RELOC-NEXT: - Index: 23
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: get_func3B
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 17
; RELOC-NEXT: SegmentInfo:
; RELOC-NEXT: - Index: 0
; RELOC-NEXT: Name: .bss.colliding_global1

View File

@ -0,0 +1,36 @@
; RUN: llvm-as %s -o %t.o
; RUN: wasm-ld -r -o %t.wasm %t.o
; RUN: obj2yaml %t.wasm | FileCheck %s
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown"
@missing_data = external global i32
declare i32 @missing_func() local_unnamed_addr
define i32 @foo() {
entry:
%0 = call i32 @missing_func()
%1 = load i32, i32* @missing_data, align 4
ret i32 %1
}
; CHECK: - Type: CUSTOM
; CHECK-NEXT: Name: linking
; CHECK-NEXT: Version: 2
; CHECK-NEXT: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Name: missing_func
; CHECK-NEXT: Flags: [ UNDEFINED ]
; CHECK-NEXT: Function: 0
; CHECK-NEXT: - Index: 1
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Name: foo
; CHECK-NEXT: Flags: [ ]
; CHECK-NEXT: Function: 1
; CHECK-NEXT: - Index: 2
; CHECK-NEXT: Kind: DATA
; CHECK-NEXT: Name: missing_data
; CHECK-NEXT: Flags: [ UNDEFINED ]

View File

@ -187,13 +187,13 @@ entry:
; RELOC-NEXT: - Type: CODE
; RELOC-NEXT: Relocations:
; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
; RELOC-NEXT: Index: 4
; RELOC-NEXT: Index: 1
; RELOC-NEXT: Offset: 0x00000004
; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
; RELOC-NEXT: Index: 1
; RELOC-NEXT: Index: 2
; RELOC-NEXT: Offset: 0x00000013
; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
; RELOC-NEXT: Index: 4
; RELOC-NEXT: Index: 1
; RELOC-NEXT: Offset: 0x0000001C
; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB
; RELOC-NEXT: Index: 6
@ -202,10 +202,10 @@ entry:
; RELOC-NEXT: Index: 6
; RELOC-NEXT: Offset: 0x00000032
; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
; RELOC-NEXT: Index: 4
; RELOC-NEXT: Index: 1
; RELOC-NEXT: Offset: 0x0000003A
; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
; RELOC-NEXT: Index: 4
; RELOC-NEXT: Index: 1
; RELOC-NEXT: Offset: 0x00000043
; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB
; RELOC-NEXT: Index: 6
@ -217,10 +217,10 @@ entry:
; RELOC-NEXT: Index: 6
; RELOC-NEXT: Offset: 0x00000068
; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
; RELOC-NEXT: Index: 1
; RELOC-NEXT: Index: 2
; RELOC-NEXT: Offset: 0x00000070
; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
; RELOC-NEXT: Index: 1
; RELOC-NEXT: Index: 2
; RELOC-NEXT: Offset: 0x00000079
; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB
; RELOC-NEXT: Index: 6
@ -259,24 +259,24 @@ entry:
; RELOC-NEXT: Function: 0
; RELOC-NEXT: - Index: 1
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: alias_fn
; RELOC-NEXT: Flags: [ BINDING_WEAK ]
; RELOC-NEXT: Function: 1
; RELOC-NEXT: - Index: 2
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: direct_fn
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 1
; RELOC-NEXT: - Index: 2
; RELOC-NEXT: - Index: 3
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: call_direct
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 2
; RELOC-NEXT: - Index: 3
; RELOC-NEXT: - Index: 4
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: call_alias
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 3
; RELOC-NEXT: - Index: 4
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: alias_fn
; RELOC-NEXT: Flags: [ BINDING_WEAK ]
; RELOC-NEXT: Function: 1
; RELOC-NEXT: - Index: 5
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: call_alias_ptr

View File

@ -903,40 +903,42 @@ void Writer::assignSymtab() {
StringMap<uint32_t> SectionSymbolIndices;
unsigned SymbolIndex = SymtabEntries.size();
for (ObjFile *File : Symtab->ObjectFiles) {
LLVM_DEBUG(dbgs() << "Symtab entries: " << File->getName() << "\n");
for (Symbol *Sym : File->getSymbols()) {
if (Sym->getFile() != File)
continue;
if (auto *S = dyn_cast<SectionSymbol>(Sym)) {
StringRef Name = S->getName();
if (CustomSectionMapping.count(Name) == 0)
continue;
auto AddSymbol = [&](Symbol *Sym) {
if (auto *S = dyn_cast<SectionSymbol>(Sym)) {
StringRef Name = S->getName();
if (CustomSectionMapping.count(Name) == 0)
return;
auto SSI = SectionSymbolIndices.find(Name);
if (SSI != SectionSymbolIndices.end()) {
Sym->setOutputSymbolIndex(SSI->second);
continue;
}
SectionSymbolIndices[Name] = SymbolIndex;
CustomSectionSymbols[Name] = cast<SectionSymbol>(Sym);
Sym->markLive();
auto SSI = SectionSymbolIndices.find(Name);
if (SSI != SectionSymbolIndices.end()) {
Sym->setOutputSymbolIndex(SSI->second);
return;
}
// (Since this is relocatable output, GC is not performed so symbols must
// be live.)
assert(Sym->isLive());
Sym->setOutputSymbolIndex(SymbolIndex++);
SymtabEntries.emplace_back(Sym);
}
}
SectionSymbolIndices[Name] = SymbolIndex;
CustomSectionSymbols[Name] = cast<SectionSymbol>(Sym);
// For the moment, relocatable output doesn't contain any synthetic functions,
// so no need to look through the Symtab for symbols not referenced by
// Symtab->ObjectFiles.
Sym->markLive();
}
// (Since this is relocatable output, GC is not performed so symbols must
// be live.)
assert(Sym->isLive());
Sym->setOutputSymbolIndex(SymbolIndex++);
SymtabEntries.emplace_back(Sym);
};
for (Symbol *Sym : Symtab->getSymbols())
if (!Sym->isLazy())
AddSymbol(Sym);
for (ObjFile *File : Symtab->ObjectFiles) {
LLVM_DEBUG(dbgs() << "Local symtab entries: " << File->getName() << "\n");
for (Symbol *Sym : File->getSymbols())
if (Sym->isLocal())
AddSymbol(Sym);
}
}
uint32_t Writer::lookupType(const WasmSignature &Sig) {