Skip to content

Commit ca09e08

Browse files
authored
[Symbolizer][WebAssembly] Use wasm-specific getSymbolSize (#82083)
getSymbolSize was recently added to WasmObjectFile and has correct sizes for most symbol types. This makes llvm-symbolizer correctly symbolize addresses in the middle of the symbol. When reworking the test I also noticed that the DWARF info seems to be wrong for the first instruction in each function. I noted that in the test comments but didn't attempt to fix here.
1 parent 6e6bf9f commit ca09e08

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

llvm/lib/Object/SymbolSize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ llvm::object::computeSymbolSizes(const ObjectFile &O) {
6565
return Ret;
6666
}
6767

68+
if (const auto *E = dyn_cast<WasmObjectFile>(&O)) {
69+
for (SymbolRef Sym : E->symbols()) {
70+
Ret.push_back({Sym, E->getSymbolSize(Sym)});
71+
}
72+
return Ret;
73+
}
74+
6875
// Collect sorted symbol addresses. Include dummy addresses for the end
6976
// of each section.
7077
std::vector<SymEntry> Addresses;
Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,59 @@
11
# REQUIRES: webassembly-registered-target
22
# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj %s -o %t.o -g
3+
# RUN: llvm-symbolizer --basenames --output-style=GNU -e %t.o 1 2 3 4 5 6 7 8 9 10 11 12 13 | FileCheck %s
34

45
foo:
56
.functype foo () -> ()
67
nop
8+
return
79
end_function
810

911
bar:
1012
.functype bar (i32) -> (i32)
1113
local.get 0
14+
nop
1215
return
1316
end_function
1417

15-
# RUN: llvm-symbolizer -e %t.o 3 4 7 8 | FileCheck %s
16-
## Byte 1 is the function length and 2 is the locals declaration.
17-
## Currently no line corresponds to them.
18-
## TODO: create a loc for .functype?
1918

20-
## Test 2 functions to ensure wasm's function-sections system works.
21-
# CHECK: wasm-basic.s:6:0
22-
# CHECK: wasm-basic.s:7:0
23-
# CHECK: wasm-basic.s:11:0
24-
# CHECK: wasm-basic.s:11:0
19+
## Symbols start from (including) the function length and should cover all the
20+
## way to the next symbol start.
21+
## TODO: create a loc for .functype? It could go with the local declarations.
22+
23+
## Byte 1 is the function length, has no loc but the symbol table considers it
24+
## the start of the function
25+
# CHECK: foo
26+
# CHECK-NEXT: ??:0
27+
## Byte 2 is the local declaration, but for some reason DWARF is marking it as line 7.
28+
## TODO: figure out why.
29+
# CHECK-NEXT: foo
30+
# CHECK-NEXT: wasm-basic.s:7
31+
## Byte 3 is actually the nop, line 7
32+
# CHECK-NEXT: foo
33+
# CHECK-NEXT: wasm-basic.s:7
34+
## Byte 4 is the return, line 8
35+
# CHECK-NEXT: foo
36+
# CHECK-NEXT: wasm-basic.s:8
37+
## Byte 5 is the end_function, line 9
38+
# CHECK-NEXT: foo
39+
# CHECK-NEXT: wasm-basic.s:9
40+
## Byte 6 is bar's function length, symbol table considers it part of bar
41+
# CHECK-NEXT: bar
42+
# CHECK-NEXT: ??:0
43+
## Byte 7 bar's local declaration, but DWARF marks it as line 13, like above
44+
# CHECK-NEXT: bar
45+
# CHECK-NEXT: wasm-basic.s:13
46+
## Byte 8 and 9 are actually the local.get on line 13
47+
# CHECK-NEXT: bar
48+
# CHECK-NEXT: wasm-basic.s:13
49+
# CHECK-NEXT: bar
50+
# CHECK-NEXT: wasm-basic.s:13
51+
## Byte 10 is the nop
52+
# CHECK-NEXT: bar
53+
# CHECK-NEXT: wasm-basic.s:14
54+
## Byte b is the return
55+
# CHECK-NEXT: bar
56+
# CHECK-NEXT: wasm-basic.s:15
57+
## Byte c is end_function
58+
# CHECK-NEXT: bar
59+
# CHECK-NEXT: wasm-basic.s:16

0 commit comments

Comments
 (0)