File tree Expand file tree Collapse file tree 3 files changed +161
-4
lines changed Expand file tree Collapse file tree 3 files changed +161
-4
lines changed Original file line number Diff line number Diff line change @@ -1667,10 +1667,18 @@ Expected<StringRef> WasmObjectFile::getSymbolName(DataRefImpl Symb) const {
1667
1667
Expected<uint64_t > WasmObjectFile::getSymbolAddress (DataRefImpl Symb) const {
1668
1668
auto &Sym = getWasmSymbol (Symb);
1669
1669
if (Sym.Info .Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION &&
1670
- isDefinedFunctionIndex (Sym.Info .ElementIndex ))
1671
- return getDefinedFunction (Sym.Info .ElementIndex ).CodeSectionOffset ;
1672
- else
1673
- return getSymbolValue (Symb);
1670
+ isDefinedFunctionIndex (Sym.Info .ElementIndex )) {
1671
+ // For object files, use the section offset. The linker relies on this.
1672
+ // For linked files, use the file offset. This behavior matches the way
1673
+ // browsers print stack traces and is useful for binary size analysis.
1674
+ // (see https://webassembly.github.io/spec/web-api/index.html#conventions)
1675
+ uint32_t Adjustment = isRelocatableObject () || isSharedObject ()
1676
+ ? 0
1677
+ : Sections[CodeSection].Offset ;
1678
+ return getDefinedFunction (Sym.Info .ElementIndex ).CodeSectionOffset +
1679
+ Adjustment;
1680
+ }
1681
+ return getSymbolValue (Symb);
1674
1682
}
1675
1683
1676
1684
uint64_t WasmObjectFile::getWasmSymbolValue (const WasmSymbol &Sym) const {
Original file line number Diff line number Diff line change
1
+ # RUN: yaml2obj %s -o %t.wasm
2
+ # RUN: llvm-nm %t.wasm | FileCheck %s
3
+
4
+ # CHECK: 0000009f T my_func_export
5
+ # CHECK-NEXT: 0000002a D my_global_export
6
+ # CHECK-NEXT: 00000000 D my_table_export
7
+
8
+ --- !WASM
9
+ FileHeader :
10
+ Version : 0x1
11
+ Sections :
12
+ - Type : TYPE
13
+ Signatures :
14
+ - Index : 0
15
+ ParamTypes : []
16
+ ReturnTypes : []
17
+ - Type : IMPORT
18
+ Imports :
19
+ - Module : env
20
+ Field : foo
21
+ Kind : FUNCTION
22
+ SigIndex : 0
23
+ - Module : env
24
+ Field : bar
25
+ Kind : GLOBAL
26
+ GlobalType : I32
27
+ GlobalMutable : true
28
+ - Module : env
29
+ Field : memory
30
+ Kind : MEMORY
31
+ Memory :
32
+ Minimum : 0x1
33
+ - Type : FUNCTION
34
+ FunctionTypes : [ 0 ]
35
+ - Type : TABLE
36
+ Tables :
37
+ - Index : 0
38
+ ElemType : FUNCREF
39
+ Limits :
40
+ Flags : [ HAS_MAX ]
41
+ Minimum : 0x1
42
+ Maximum : 0x1
43
+ - Type : GLOBAL
44
+ Globals :
45
+ - Index : 1
46
+ Mutable : false
47
+ Type : I32
48
+ InitExpr :
49
+ Opcode : I32_CONST
50
+ Value : 42
51
+ - Type : EXPORT
52
+ Exports :
53
+ - Name : my_func_export
54
+ Kind : FUNCTION
55
+ Index : 1
56
+ - Name : my_global_export
57
+ Kind : GLOBAL
58
+ Index : 1
59
+ - Name : my_table_export
60
+ Kind : TABLE
61
+ Index : 0
62
+ - Type : CODE
63
+ Functions :
64
+ - Index : 1
65
+ Locals :
66
+ Body : 00
67
+ - Type : DATA
68
+ Segments :
69
+ - SectionOffset : 0
70
+ InitFlags : 0
71
+ Offset :
72
+ Opcode : I32_CONST
73
+ Value : 0
74
+ Content : ' '
Original file line number Diff line number Diff line change
1
+ # RUN: yaml2obj %s -o %t.wasm
2
+ # RUN: llvm-objdump -t %t.wasm | FileCheck %s
3
+ #
4
+ # CHECK: SYMBOL TABLE:
5
+ # CHECK-NEXT: 0000009f g F CODE my_func_export
6
+ # CHECK-NEXT: 0000002a g O DATA my_global_export
7
+ # CHECK-NEXT: 00000000 g TABLE my_table_export
8
+
9
+ --- !WASM
10
+ FileHeader :
11
+ Version : 0x1
12
+ Sections :
13
+ - Type : TYPE
14
+ Signatures :
15
+ - Index : 0
16
+ ParamTypes : []
17
+ ReturnTypes : []
18
+ - Type : IMPORT
19
+ Imports :
20
+ - Module : env
21
+ Field : foo
22
+ Kind : FUNCTION
23
+ SigIndex : 0
24
+ - Module : env
25
+ Field : bar
26
+ Kind : GLOBAL
27
+ GlobalType : I32
28
+ GlobalMutable : true
29
+ - Module : env
30
+ Field : memory
31
+ Kind : MEMORY
32
+ Memory :
33
+ Minimum : 0x1
34
+ - Type : FUNCTION
35
+ FunctionTypes : [ 0 ]
36
+ - Type : TABLE
37
+ Tables :
38
+ - Index : 0
39
+ ElemType : FUNCREF
40
+ Limits :
41
+ Flags : [ HAS_MAX ]
42
+ Minimum : 0x1
43
+ Maximum : 0x1
44
+ - Type : GLOBAL
45
+ Globals :
46
+ - Index : 1
47
+ Mutable : false
48
+ Type : I32
49
+ InitExpr :
50
+ Opcode : I32_CONST
51
+ Value : 42
52
+ - Type : EXPORT
53
+ Exports :
54
+ - Name : my_func_export
55
+ Kind : FUNCTION
56
+ Index : 1
57
+ - Name : my_global_export
58
+ Kind : GLOBAL
59
+ Index : 1
60
+ - Name : my_table_export
61
+ Kind : TABLE
62
+ Index : 0
63
+ - Type : CODE
64
+ Functions :
65
+ - Index : 1
66
+ Locals :
67
+ Body : 00
68
+ - Type : DATA
69
+ Segments :
70
+ - SectionOffset : 0
71
+ InitFlags : 0
72
+ Offset :
73
+ Opcode : I32_CONST
74
+ Value : 0
75
+ Content : ' '
You can’t perform that action at this time.
0 commit comments