[WebAssembly] Support debug info for TLS + global in PIC mode
authorHeejin Ahn <aheejin@gmail.com>
Thu, 2 Mar 2023 06:53:51 +0000 (22:53 -0800)
committerHeejin Ahn <aheejin@gmail.com>
Sat, 18 Mar 2023 03:16:48 +0000 (20:16 -0700)
commite1f830bde8bad22d375bc92f2084e9055059cc77
tree426afa80c53aa793a163cc5ca38586067f3c6a27
parent6d33affac05a7f30f8b3761a66f81fe63b9f44e1
[WebAssembly] Support debug info for TLS + global in PIC mode

This adds debug info support for
- `thread_local` global variables, both in non-PIC and PIC modes
- (non-thread_local) Global variables in PIC mode

The former needs to read the value from an offset relative to
`__tls_base` and the latter an offset from `__memory_base`. The code for
doing this overlaps with some of the existing code to add
`__stack_pointer` global, so this adds a new member function to add a
a global in `TI_GLOBAL_RELOC` mode and use it in all three places.

Split DWARF support is currently patchy at best, because the index for
`__tls_base` is not fixed after dynamic linking. The preexisting split
DWARF support for `__stack_pointer` relies on that in practice it is
always index 0. This does similar hardcoding for `__tls_base` and
`__memory_base`, but `__tls_base`'s index in dynamic linking is not
fixed now (See
https://github.com/llvm/llvm-project/blob/19afbfe33156d211fa959dadeea46cd17b9c723c/lld/wasm/Driver.cpp#L786-L823
for details), TLS + dynamic linking will not work at the moment.

Fixes https://bugs.chromium.org/p/chromium/issues/detail?id=1416702.

Reviewed By: dschuff

Differential Revision: https://reviews.llvm.org/D145626
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/test/DebugInfo/WebAssembly/tls_pic_globals.ll [new file with mode: 0644]