This is an archive of the discontinued LLVM Phabricator instance.

[DWARF][RISCV] Add support for RISC-V relocations needed for debug info
ClosedPublic

Authored by luismarques on May 17 2019, 6:31 AM.

Details

Summary

When code relaxation is enabled many RISC-V fixups are not resolved but instead relocations are emitted. This happens even for DWARF debug sections. Therefore, to properly support the parsing of DWARF debug info we need to be able to resolve RISC-V relocations. This patch adds:

  • Support for RISC-V relocations in RelocationResolver
  • DWARF support for two relocations per object file offset
  • DWARF changes to support relocations in more DIE fields

The two relocations per offset change is needed because some RISC-V relocations (used for label differences) come in pairs.

Relocations can also be emitted for DWARF fields where relocations were not yet evaluated. Adding relocation support for some of these fields is essencial. On the other hand, LLVM currently emits RISC-V relocations for fixups that could be safely evaluated, since they can never be affected by code relaxations. This patch also adds relocation support for the fields affected by those extraneous relocations (the DWARF unit entry Length, and the DWARF debug line entry TotalLength and PrologueLength), for testing purposes. The current plan is to remove those three relocation support changes from the final patch, but that will depend on the merge of a patch to prevent the emission of the extraneous relocations (see for instance https://reviews.llvm.org/D61584).

Diff Detail

Repository
rL LLVM

Event Timeline

luismarques created this revision.May 17 2019, 6:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2019, 6:31 AM

Could you provide test cases for this patch?

Could you provide test cases for this patch?

Yes, I'm going to add tests to this patch soon. Thanks!

  • Adds relocation support for a few more fields, needed for DWARF 5 support;
  • Adds a test.

lld uses RelocAddrEntry as well. You'll need to check-lld

MaskRay added inline comments.May 27 2019, 1:48 AM
test/DebugInfo/RISCV/dwarf-riscv-relocs.ll
3 ↗(On Diff #201470)

--source or -S. In these binary utilities (llvm-objdump,llvm-objcopy,...), -long-option is discouraged.

MaskRay added inline comments.May 27 2019, 1:51 AM
test/DebugInfo/RISCV/dwarf-riscv-relocs.ll
2 ↗(On Diff #201470)

llvm-readobj -r instead of llvm-objdump -r. objdump is not suitable for various non-disassembly tasks because its format is weird.

99 ↗(On Diff #201470)

This ident info may be replaced with something else..

  • The test dumps the relocations using llvm-readobj instead of llvm-objdump.
  • Changes the objdump flag, from -source to --source.

@MaskRay I had already patched, built and tested LLD against this patch, but the LLD changes were not included in this patch because LLD was checked-out as a separate repo. It's just a ctor change, as seen bellow. I can't update that right now, as I'm on the move. If you think it's necessary I will update the Phabricator patch to also include those changes for official review, at a later date.

diff --git a/ELF/DWARF.cpp b/ELF/DWARF.cpp
index 6b90a038e..e8310a48a 100644
--- a/ELF/DWARF.cpp
+++ b/ELF/DWARF.cpp
@@ -110,8 +110,9 @@ LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
 
   DataRefImpl D;
   D.p = getAddend<ELFT>(Rel);
-  return RelocAddrEntry{SecIndex, RelocationRef(D, nullptr),
-                        LLDRelocationResolver<RelTy>::Resolve, Val};
+  return RelocAddrEntry{SecIndex, RelocationRef(D, nullptr), Val,
+                        Optional<object::RelocationRef>(), 0,
+                        LLDRelocationResolver<RelTy>::Resolve};
 }

Also use the --long-options in llvm-dwarfdump.

luismarques marked 2 inline comments as done.May 30 2019, 4:59 AM

This patch does not handle .eh_frame and .debug_frame. I know that it could not generate debug frame information in the current upstream LLVM. In order to generate .eh_frame and .debug_frame for RISC-V architecture, D58335 and D61773 need to be landed first. So, I add related processing code for .eh_frame and .debug_frame in D58335.

lenary added a subscriber: lenary.Jul 11 2019, 6:29 AM
This revision was not accepted when it landed; it landed in state Needs Review.Jul 17 2019, 10:27 PM
This revision was automatically updated to reflect the committed changes.