Skip to content

Commit 9d1409d

Browse files
committed
[lld][WebAssembly] Give better warnings on bad relocation sites
Differential Revision: https://reviews.llvm.org/D90443
1 parent 2e31727 commit 9d1409d

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

lld/test/wasm/bad-reloc.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# RUN: yaml2obj %s -o %t.o
2+
# RUN: not wasm-ld --fatal-warnings -o out.wasm %t.o 2>&1 | FileCheck %s
3+
#
4+
# CHECK: bad-reloc.yaml.tmp.o:(_start): unexpected existing value for R_WASM_MEMORY_ADDR_LEB: existing=1 expected=0
5+
#
6+
# The code section bellow has been modified such that the target of the
7+
# relocation is 8180808000 (LEB of 1) rather than 8080808000 (LEB = 0)
8+
9+
--- !WASM
10+
FileHeader:
11+
Version: 0x00000001
12+
Sections:
13+
- Type: TYPE
14+
Signatures:
15+
- Index: 0
16+
ParamTypes: []
17+
ReturnTypes:
18+
- I32
19+
- Type: IMPORT
20+
Imports:
21+
- Module: env
22+
Field: __linear_memory
23+
Kind: MEMORY
24+
Memory:
25+
Initial: 0x00000001
26+
- Module: env
27+
Field: __indirect_function_table
28+
Kind: TABLE
29+
Table:
30+
Index: 0
31+
ElemType: FUNCREF
32+
Limits:
33+
Initial: 0x00000000
34+
- Type: FUNCTION
35+
FunctionTypes: [ 0 ]
36+
- Type: DATACOUNT
37+
Count: 1
38+
- Type: CODE
39+
Relocations:
40+
- Type: R_WASM_MEMORY_ADDR_LEB
41+
Index: 1
42+
Offset: 0x00000007
43+
Functions:
44+
- Index: 0
45+
Locals: []
46+
Body: 4100280281808080002802000B
47+
- Type: DATA
48+
Segments:
49+
- SectionOffset: 6
50+
InitFlags: 0
51+
Offset:
52+
Opcode: I32_CONST
53+
Value: 0
54+
Content: '00000000'
55+
- Type: CUSTOM
56+
Name: linking
57+
Version: 2
58+
SymbolTable:
59+
- Index: 0
60+
Kind: FUNCTION
61+
Name: _start
62+
Flags: [ VISIBILITY_HIDDEN ]
63+
Function: 0
64+
- Index: 1
65+
Kind: DATA
66+
Name: bar
67+
Flags: [ VISIBILITY_HIDDEN ]
68+
Segment: 0
69+
Size: 4
70+
SegmentInfo:
71+
- Index: 0
72+
Name: .bss.bar
73+
Alignment: 2
74+
Flags: [ ]
75+

lld/wasm/InputChunks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ void InputChunk::verifyRelocTargets() const {
109109
rel.Type != R_WASM_GLOBAL_INDEX_I32) {
110110
auto expectedValue = file->calcExpectedValue(rel);
111111
if (expectedValue != existingValue)
112-
warn("unexpected existing value for " + relocTypeToString(rel.Type) +
113-
": existing=" + Twine(existingValue) +
114-
" expected=" + Twine(expectedValue));
112+
warn(toString(this) + ": unexpected existing value for " +
113+
relocTypeToString(rel.Type) + ": existing=" +
114+
Twine(existingValue) + " expected=" + Twine(expectedValue));
115115
}
116116
}
117117
}

0 commit comments

Comments
 (0)