[PATCH] D103557: [WebAssembly] Generate R_FUNCTION_OFFSET relocs in debuginfo sections

Derek Schuff via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 15 18:08:07 PDT 2021


dschuff created this revision.
Herald added subscribers: hiraditya, jgravelle-google, sbc100.
dschuff updated this revision to Diff 349385.
dschuff added a comment.
dschuff updated this revision to Diff 349420.
dschuff updated this revision to Diff 350738.
dschuff updated this revision to Diff 350739.
dschuff updated this revision to Diff 350740.
dschuff updated this revision to Diff 359179.
dschuff retitled this revision from "Fix for PR50408" to "[WebAssembly] Generate R_FUNCTION_OFFSET relocs in debuginfo sections".
dschuff edited the summary of this revision.
Herald added subscribers: ecnelises, sunfish.
dschuff updated this revision to Diff 359182.
dschuff added reviewers: sbc100, aardappel.
dschuff published this revision for review.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

fix diff


dschuff added a comment.

- exclude functions from section-symbolizing


dschuff added a comment.

Add test


dschuff added a comment.

fix diff


dschuff added a comment.

rebase


dschuff added a comment.

@sbc I think this patch functionality (i.e. pass the section to be fixed-up into `getRelocType`, and make the reloc type  be WASM_FUNCTION_OFFSET_I32 if the section is a debuginfo section) gives the reasonable-looking behavior for the object file on the problematic tests.
However the linker seems to be turning into `0xffffff`

Here's a complete example using dwarf 4 rather than dwarf 5 since wasm-emscripten-finalize is choking on .debug_addr still:

  ds at ancho:/s/emr/emscripten-releases/localtests (main)$ cat PR50408.cc
  // Compile with -g
  #if MAIN
  char a();
  template <typename, char b()>
  void f() { b(); }
  void g() { f<char, a>(); }
  #else
  char a() { return 'a'; }
  #endif
  ds at ancho:/s/emr/emscripten-releases/localtests (main)$ /s/emr/install/emscripten/em++ PR50408.cc -DMAIN -c -g -gdwarf-4 -o PR50408.o
  ds at ancho:/s/emr/emscripten-releases/localtests (main)$ /s/emr/install/emscripten/em++ PR50408.cc  -c -g -gdwarf-4 -o PR50408_a.o
  ds at ancho:/s/emr/emscripten-releases/localtests (main)$ /s/emr/install/emscripten/em++ -g PR50408.o PR50408_a.o -o PR50408.js
  ds at ancho:/s/emr/emscripten-releases/localtests (main)$ /s/emr/install/bin/llvm-dwarfdump -debug-info PR50408.o
  PR50408.o:      file format WASM
  
  .debug_info contents:
  0x00000000: Compile Unit: length = 0x00000080, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x00000084)
  
  <snip>
  
  0x00000061:     DW_TAG_template_value_parameter
                    DW_AT_type    (0x00000079 "char()*")
                    DW_AT_name    ("b")
                    DW_AT_location        (DW_OP_addr 0x0, DW_OP_stack_value)
  
  ds at ancho:/s/emr/emscripten-releases/localtests (main)$ /s/emr/install/bin/llvm-dwarfdump -debug-info PR50408.wasm
  PR50408.wasm:   file format WASM
  
  .debug_info contents:
  0x00000000: Compile Unit: length = 0x00000080, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x00000084)
  
  <snip>
  
  0x00000061:     DW_TAG_template_value_parameter
                    DW_AT_type    (0x00000079 "char()*")
                    DW_AT_name    ("b")
                    DW_AT_location        (DW_OP_addr 0xffffffff, DW_OP_stack_value)

So maybe the linker isn't properly handling that use of WASM_FUNCTION_OFFSET_I32 when used with a function instead of a section symbo.


dschuff added a comment.

- exclude functions from section-symbolizing
- Add test
- fix up map-file test
- commit random prints
- clean up debug printfs
- remove debuginfo-relocs


dschuff added a comment.

- add asm test



================
Comment at: llvm/lib/MC/WasmObjectWriter.cpp:507
+             : SymA->isTable()    ? "table\n"
+                                  : "???\n");
+  //<< SymA->getType().getValue() << "\n";
----------------
@sbc100 from here, testing with Andy's example I found that we are getting some fixups where SymA has type data (or no type?) but the relocation is clearly intended to be against a function symbol (it has the name of a function and is a R_WASM_FUNCTION_OFFSET reloc). Also the SECTION_OFFSET relocs with target symbols in the .debug_str section are all nameless symbols. I don't really understand yet why either of these are the way they are.


Debug info sections need R_FUNCTION_OFFSET_I32 relocs (with FK_Data_4 fixup kinds) to refer to functions (instead of R_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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103557

Files:
  lld/test/wasm/debuginfo-relocs.s
  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
  llvm/test/MC/WebAssembly/debuginfo-relocs.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103557.359182.patch
Type: text/x-patch
Size: 14331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210716/ae18129b/attachment.bin>


More information about the llvm-commits mailing list