From: Sam Clegg Date: Fri, 30 Oct 2020 03:37:16 +0000 (-0700) Subject: [lld][WebAssembly] Give better warnings on bad relocation sites X-Git-Tag: llvmorg-13-init~7571 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d1409df8792ac1200244a1d0eccff81e1b2b70b;p=platform%2Fupstream%2Fllvm.git [lld][WebAssembly] Give better warnings on bad relocation sites Differential Revision: https://reviews.llvm.org/D90443 --- diff --git a/lld/test/wasm/bad-reloc.yaml b/lld/test/wasm/bad-reloc.yaml new file mode 100644 index 0000000..dfab2c6 --- /dev/null +++ b/lld/test/wasm/bad-reloc.yaml @@ -0,0 +1,75 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: not wasm-ld --fatal-warnings -o out.wasm %t.o 2>&1 | FileCheck %s +# +# CHECK: bad-reloc.yaml.tmp.o:(_start): unexpected existing value for R_WASM_MEMORY_ADDR_LEB: existing=1 expected=0 +# +# The code section bellow has been modified such that the target of the +# relocation is 8180808000 (LEB of 1) rather than 8080808000 (LEB = 0) + +--- !WASM +FileHeader: + Version: 0x00000001 +Sections: + - Type: TYPE + Signatures: + - Index: 0 + ParamTypes: [] + ReturnTypes: + - I32 + - Type: IMPORT + Imports: + - Module: env + Field: __linear_memory + Kind: MEMORY + Memory: + Initial: 0x00000001 + - Module: env + Field: __indirect_function_table + Kind: TABLE + Table: + Index: 0 + ElemType: FUNCREF + Limits: + Initial: 0x00000000 + - Type: FUNCTION + FunctionTypes: [ 0 ] + - Type: DATACOUNT + Count: 1 + - Type: CODE + Relocations: + - Type: R_WASM_MEMORY_ADDR_LEB + Index: 1 + Offset: 0x00000007 + Functions: + - Index: 0 + Locals: [] + Body: 4100280281808080002802000B + - Type: DATA + Segments: + - SectionOffset: 6 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 0 + Content: '00000000' + - Type: CUSTOM + Name: linking + Version: 2 + SymbolTable: + - Index: 0 + Kind: FUNCTION + Name: _start + Flags: [ VISIBILITY_HIDDEN ] + Function: 0 + - Index: 1 + Kind: DATA + Name: bar + Flags: [ VISIBILITY_HIDDEN ] + Segment: 0 + Size: 4 + SegmentInfo: + - Index: 0 + Name: .bss.bar + Alignment: 2 + Flags: [ ] + diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp index 0db4d9d..ddbdb90 100644 --- a/lld/wasm/InputChunks.cpp +++ b/lld/wasm/InputChunks.cpp @@ -109,9 +109,9 @@ void InputChunk::verifyRelocTargets() const { rel.Type != R_WASM_GLOBAL_INDEX_I32) { auto expectedValue = file->calcExpectedValue(rel); if (expectedValue != existingValue) - warn("unexpected existing value for " + relocTypeToString(rel.Type) + - ": existing=" + Twine(existingValue) + - " expected=" + Twine(expectedValue)); + warn(toString(this) + ": unexpected existing value for " + + relocTypeToString(rel.Type) + ": existing=" + + Twine(existingValue) + " expected=" + Twine(expectedValue)); } } }