[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
This commit is contained in:
Sam Clegg
2019-08-20 18:39:24 +00:00
parent fc4486c247
commit cf2b8722d4
4 changed files with 26 additions and 2 deletions

View File

@@ -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: