Skip to content

Commit

Permalink
[WebAssembly] Add explicit symbol table
Browse files Browse the repository at this point in the history
This change modified lld to in response the llvm change which
moved to a more explicit symbol table in the object format.

Based on patches by Nicholas Wilson:
 1. https://reviews.llvm.org/D41955
 2. https://reviews.llvm.org/D42585

The primary difference that we see in the test output is that
for relocatable (-r) output we now have symbol table which
replaces exports/imports and globals.

See: WebAssembly/tool-conventions#38
Differential Revision: https://reviews.llvm.org/D43264

llvm-svn: 325861
  • Loading branch information
sbc100 committed Feb 23, 2018
1 parent 6c899ba commit 9310297
Show file tree
Hide file tree
Showing 26 changed files with 1,897 additions and 853 deletions.
4 changes: 2 additions & 2 deletions lld/test/wasm/alias.ll
Expand Up @@ -58,10 +58,10 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: start_alias
; CHECK-NEXT: - Name: _start
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: _start
; CHECK-NEXT: - Name: start_alias
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: __heap_base
Expand Down
10 changes: 7 additions & 3 deletions lld/test/wasm/archive.ll
Expand Up @@ -9,7 +9,7 @@
; CHECK-UNDEFINED: undefined symbol: missing_func

; RUN: echo 'missing_func' > %t.imports
; RUN: wasm-ld --check-signatures %t.a %t.o -o %t.wasm
; RUN: wasm-ld --check-signatures -r %t.a %t.o -o %t.wasm

; RUN: llvm-nm -a %t.wasm | FileCheck %s

Expand All @@ -25,12 +25,16 @@ entry:
ret void
}

; Verify that multually dependant object files in an archive is handled
; correctly.
; Verify that mutually dependant object files in an archive is handled
; correctly. Since we're using llvm-nm, we must link with --relocatable.
;
; TODO(ncw): Update LLD so that the symbol table is written out for
; non-relocatable output (with an option to strip it)

; CHECK: 00000003 T _start
; CHECK-NEXT: 00000001 T bar
; CHECK-NEXT: 00000002 T foo
; CHECK-NEXT: U missing_func

; Verify that symbols from unused objects don't appear in the symbol table
; CHECK-NOT: hello
Expand Down
44 changes: 27 additions & 17 deletions lld/test/wasm/data-layout.ll
Expand Up @@ -46,25 +46,10 @@ target triple = "wasm32-unknown-unknown-wasm"
; RUN: wasm-ld --check-signatures --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: Index: 5
; RELOC-NEXT: Offset: 0x00000018
; RELOC-NEXT: Segments:
; RELOC-NEXT: - SectionOffset: 6
Expand Down Expand Up @@ -92,6 +77,31 @@ target triple = "wasm32-unknown-unknown-wasm"
; RELOC-NEXT: Value: 28
; RELOC-NEXT: Content: 68656C6C6F0A00

; RELOC: - Type: CUSTOM
; RELOC: - Type: CUSTOM
; RELOC-NEXT: Name: linking
; RELOC-NEXT: DataSize: 35
; RELOC-NEXT: SymbolTable:
; RELOC-NEXT: - Index: 0
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: foo
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: Segment: 0
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 1
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: aligned_bar
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: Segment: 1
; RELOC-NEXT: Size: 4
; RELOC-NEXT: - Index: 2
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: external_ref
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Segment: 2
; RELOC-NEXT: Size: 4
; RELOC: - Index: 5
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: hello_str
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Segment: 3
; RELOC-NEXT: Size: 7
125 changes: 94 additions & 31 deletions lld/test/wasm/init-fini.ll
Expand Up @@ -107,66 +107,129 @@ entry:

; RELOC: Name: linking
; RELOC-NEXT: DataSize: 0
; RELOC-NEXT: SymbolInfo:
; RELOC-NEXT: - Name: __dso_handle
; RELOC-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ]
; RELOC-NEXT: - Name: func1
; RELOC-NEXT: SymbolTable:
; RELOC-NEXT: - Index: 0
; RELOC-NEXT: Kind: DATA
; RELOC-NEXT: Name: __dso_handle
; RELOC-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN, UNDEFINED ]
; RELOC-NEXT: - Index: 1
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: func1
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: - Name: func2
; RELOC-NEXT: Function: 0
; RELOC-NEXT: - Index: 2
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: func2
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: - Name: func3
; RELOC-NEXT: Function: 1
; RELOC-NEXT: - Index: 3
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: func3
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: - Name: func4
; RELOC-NEXT: Function: 2
; RELOC-NEXT: - Index: 4
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: func4
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: - Name: _start
; RELOC-NEXT: Function: 3
; RELOC-NEXT: - Index: 5
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: __cxa_atexit
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: Function: 4
; RELOC-NEXT: - Index: 6
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: _start
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: - Name: .Lcall_dtors.101
; RELOC-NEXT: Function: 5
; RELOC-NEXT: - Index: 7
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.101
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: .Lregister_call_dtors.101
; RELOC-NEXT: Function: 6
; RELOC-NEXT: - Index: 8
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.101
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: .Lcall_dtors.1001
; RELOC-NEXT: Function: 7
; RELOC-NEXT: - Index: 9
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.1001
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: .Lregister_call_dtors.1001
; RELOC-NEXT: Function: 8
; RELOC-NEXT: - Index: 10
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.1001
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: myctor
; RELOC-NEXT: Function: 9
; 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: myctor
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: - Name: mydtor
; RELOC-NEXT: Function: 10
; RELOC-NEXT: - Index: 13
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: mydtor
; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
; RELOC-NEXT: - Name: .Lcall_dtors.101.1
; RELOC-NEXT: Function: 11
; RELOC-NEXT: - Index: 14
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.101
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: .Lregister_call_dtors.101.1
; RELOC-NEXT: Function: 12
; RELOC-NEXT: - Index: 15
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.101
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: .Lcall_dtors.202
; RELOC-NEXT: Function: 13
; RELOC-NEXT: - Index: 16
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.202
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: .Lregister_call_dtors.202
; RELOC-NEXT: Function: 14
; RELOC-NEXT: - Index: 17
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.202
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: .Lcall_dtors.2002
; RELOC-NEXT: Function: 15
; RELOC-NEXT: - Index: 18
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lcall_dtors.2002
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: - Name: .Lregister_call_dtors.2002
; RELOC-NEXT: Function: 16
; RELOC-NEXT: - Index: 19
; RELOC-NEXT: Kind: FUNCTION
; RELOC-NEXT: Name: .Lregister_call_dtors.2002
; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
; RELOC-NEXT: Function: 17
; RELOC-NEXT: InitFunctions:
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: FunctionIndex: 0
; RELOC-NEXT: Symbol: 1
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: FunctionIndex: 1
; RELOC-NEXT: Symbol: 2
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: FunctionIndex: 7
; RELOC-NEXT: Symbol: 8
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: FunctionIndex: 10
; RELOC-NEXT: Symbol: 12
; RELOC-NEXT: - Priority: 101
; RELOC-NEXT: FunctionIndex: 13
; RELOC-NEXT: Symbol: 15
; RELOC-NEXT: - Priority: 202
; RELOC-NEXT: FunctionIndex: 10
; RELOC-NEXT: Symbol: 12
; RELOC-NEXT: - Priority: 202
; RELOC-NEXT: FunctionIndex: 15
; RELOC-NEXT: Symbol: 17
; RELOC-NEXT: - Priority: 1001
; RELOC-NEXT: FunctionIndex: 0
; RELOC-NEXT: Symbol: 1
; RELOC-NEXT: - Priority: 1001
; RELOC-NEXT: FunctionIndex: 9
; RELOC-NEXT: Symbol: 10
; RELOC-NEXT: - Priority: 2002
; RELOC-NEXT: FunctionIndex: 10
; RELOC-NEXT: Symbol: 12
; RELOC-NEXT: - Priority: 2002
; RELOC-NEXT: FunctionIndex: 17
; RELOC-NEXT: Symbol: 19
; RELOC-NEXT: - Type: CUSTOM
; RELOC-NEXT: Name: name
; RELOC-NEXT: FunctionNames:
Expand Down

0 comments on commit 9310297

Please sign in to comment.