diff options
| author | Sam Clegg <sbc@chromium.org> | 2019-08-20 18:39:24 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2019-08-20 18:39:24 +0000 |
| commit | cf2b8722d4e3bc4f0c106a5724778d56074e1ec7 (patch) | |
| tree | 6974d5751613018c217bf20e67a1b9e5c6f7a6c1 | |
| parent | fc4486c2472b84384d4a31d2436a91bdb9b29792 (diff) | |
| download | bcm5719-llvm-cf2b8722d4e3bc4f0c106a5724778d56074e1ec7.tar.gz bcm5719-llvm-cf2b8722d4e3bc4f0c106a5724778d56074e1ec7.zip | |
[WebAssembly][lld] Fix crash when applying relocations to debug sections
Debug sections are special in that they can contain relocations against
symbols that are not present in the final output (i.e. not live).
However it is also possible to have R_WASM_TABLE_INDEX relocations
against symbols that don't have a table index assigned (since they are
not address taken by actual code.
Fixes: https://github.com/emscripten-core/emscripten/issues/9023
Differential Revision: https://reviews.llvm.org/D66435
llvm-svn: 369423
| -rw-r--r-- | lld/test/wasm/debuginfo-relocs.s | 23 | ||||
| -rw-r--r-- | lld/wasm/InputChunks.cpp | 2 | ||||
| -rw-r--r-- | lld/wasm/InputFiles.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/MC/MCParser/WasmAsmParser.cpp | 1 |
4 files changed, 26 insertions, 2 deletions
diff --git a/lld/test/wasm/debuginfo-relocs.s b/lld/test/wasm/debuginfo-relocs.s new file mode 100644 index 00000000000..bece55f54ff --- /dev/null +++ b/lld/test/wasm/debuginfo-relocs.s @@ -0,0 +1,23 @@ +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s +# RUN: wasm-ld %t.o -o %t.wasm +# RUN: obj2yaml %t.wasm | FileCheck %s + +bar: + .functype bar () -> () + end_function + + .globl _start +_start: + .functype _start () -> () + call bar + end_function + + .section .debug_info,"",@ + .int32 bar + +# Even though `bar` is live in the final binary it doesn't have a table entry +# since its not address taken in the code. In this case any relocations in the +# debug sections see a address of zero. + +# CHECK: Name: .debug_info +# CHECK-NEXT: Payload: '00000000' diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp index d37b58a5dee..9bd75df80f5 100644 --- a/lld/wasm/InputChunks.cpp +++ b/lld/wasm/InputChunks.cpp @@ -100,7 +100,7 @@ void InputChunk::writeTo(uint8_t *buf) const { verifyRelocTargets(); #endif - LLVM_DEBUG(dbgs() << "applying relocations: " << getName() + LLVM_DEBUG(dbgs() << "applying relocations: " << toString(this) << " count=" << relocations.size() << "\n"); int32_t off = outputOffset - getInputSectionOffset(); diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 33ae3325c74..6ec4b9dcd01 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -166,7 +166,7 @@ uint32_t ObjFile::calcNewValue(const WasmRelocation &reloc) const { case R_WASM_TABLE_INDEX_I32: case R_WASM_TABLE_INDEX_SLEB: case R_WASM_TABLE_INDEX_REL_SLEB: - if (config->isPic && !getFunctionSymbol(reloc.Index)->hasTableIndex()) + if (!getFunctionSymbol(reloc.Index)->hasTableIndex()) return 0; return getFunctionSymbol(reloc.Index)->getTableIndex(); case R_WASM_MEMORY_ADDR_SLEB: diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp index 28d4459fecd..0c242aed706 100644 --- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp +++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp @@ -123,6 +123,7 @@ public: // See use of .init_array in WasmObjectWriter and // TargetLoweringObjectFileWasm .StartsWith(".init_array", SectionKind::getData()) + .StartsWith(".debug_", SectionKind::getMetadata()) .Default(Optional<SectionKind>()); if (!Kind.hasValue()) return Parser->Error(Lexer->getLoc(), "unknown section kind: " + Name); |

