[WebAssembly] Generate R_WASM_FUNCTION_OFFSET relocs in debuginfo sections
authorDerek Schuff <dschuff@chromium.org>
Wed, 2 Jun 2021 21:37:22 +0000 (14:37 -0700)
committerDerek Schuff <dschuff@chromium.org>
Mon, 19 Jul 2021 21:02:33 +0000 (14:02 -0700)
commitad1f5457d2d89efa49a722404a5f0b744b7a64d1
treed2dbe1dfbccd534da3d5c49ac161e8a7f2001452
parent55e2d2060a367a293710f44fd61a03d797d4aade
[WebAssembly] Generate R_WASM_FUNCTION_OFFSET relocs in debuginfo sections

Debug info sections need R_WASM_FUNCTION_OFFSET_I32 relocs (with FK_Data_4 fixup
kinds) to refer to functions (instead of R_WASM_TABLE_INDEX as is used in data
sections). Usually this is done in a convoluted way, with unnamed temp data
symbols which target the start of the function, in which case
WasmObjectWriter::recordRelocation converts it to use the section symbol
instead. However in some cases the function can actually be undefined; in this
case the dwarf generator uses the function symbol (a named undefined function
symbol) instead. In that case the section-symbol transform doesn't work and we
need to generate the correct reloc type a different way. In this change
WebAssemblyWasmObjectWriter::getRelocType takes the fixup section type into
account to choose the correct reloc type.

Fixes PR50408
Differential Revision: https://reviews.llvm.org/D103557
lld/test/wasm/debuginfo-relocs.s [deleted file]
lld/test/wasm/map-file.s
llvm/include/llvm/MC/MCWasmObjectWriter.h
llvm/lib/MC/WasmObjectWriter.cpp
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
llvm/test/MC/WebAssembly/debug-template-param.ll [new file with mode: 0644]
llvm/test/MC/WebAssembly/debuginfo-relocs.s [new file with mode: 0644]