Page MenuHomePhabricator

[RISCV] Emit relocation for uleb128
Needs ReviewPublic

Authored by kito-cheng on Jan 30 2023, 2:50 AM.

Details

Reviewers
asb
jrtc27
MaskRay
Summary

Support for the uleb128 related relocation[1], ULEB128 format has used
by DWARF and exception handling table, which used ULEB128 to record data
and the distance of two symbols, however the linker relaxation might
change the symbol address, so we need to insert relocations for those
data to make sure they are still correct after linker relaxation.

NOTE: DO NOT merge this until corresponding psABI PR has merged.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/361

Diff Detail

Unit TestsFailed

TimeTest
70 msx64 debian > Flang.Examples::feature-list-class.f90
Script: -- : 'RUN: at line 4'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/flang-new -fc1 -load /var/lib/buildkite-agent/builds/llvm-project/build/lib/flangFeatureList.so -plugin feature-list /var/lib/buildkite-agent/builds/llvm-project/flang/test/Examples/feature-list-class.f90 2>&1 | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/flang/test/Examples/feature-list-class.f90
50 msx64 debian > Flang.Examples::feature-list-functions.f90
Script: -- : 'RUN: at line 4'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/flang-new -fc1 -load /var/lib/buildkite-agent/builds/llvm-project/build/lib/flangFeatureList.so -plugin feature-list /var/lib/buildkite-agent/builds/llvm-project/flang/test/Examples/feature-list-functions.f90 2>&1 | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/flang/test/Examples/feature-list-functions.f90

Event Timeline

kito-cheng created this revision.Jan 30 2023, 2:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2023, 2:50 AM
kito-cheng requested review of this revision.Jan 30 2023, 2:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2023, 2:50 AM

Changes:

  • Add testcase.
craig.topper added inline comments.
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
222

Looks like most other places in RISCV use MCFixupKind(RISCV::fixup_riscv_set_uleb128) instead of the static_cast.

jrtc27 added inline comments.Jan 30 2023, 8:49 PM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
210

encodeULEB128 takes a uint64_t

214

Why not just use encodeULEB128's PadTo and encode 0?

MaskRay added inline comments.Jan 30 2023, 11:29 PM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
204

delete the blank line. The prevailing LLVM style does not prefer inserting a blank line after a declaration.

214

-1ll is not tested. This needs a test with llvm-readelf -x $name or llvm-objdump -s dumping the section content.

llvm/test/MC/RISCV/fixups-expr.s
30 ↗(On Diff #493308)

Suggest: create a new file for .uleb128. Add a test where .uleb128 precedes the label definition (it currently crashes).

Add a test with labels defined relative to two different sections.

I don't have a very strong opinion about whether non-local symbols should be allowed. For psABI, it may be safer to start with more restriction.

craig.topper added inline comments.Wed, Mar 8, 2:54 PM
llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
57

59 has been claimed by R_RISCV_PLT32 now.

kito-cheng marked an inline comment as done.

Changes:

  • Update relocation number to 60 and 61.
  • Move testcase to fixups-expr-uleb128.s
  • Reserved enough bytes when the symbol can't evaluated at assembly time.
kito-cheng marked 5 inline comments as done.Thu, Mar 23, 1:12 AM
kito-cheng added inline comments.
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
210

evaluateAsAbsolute take int64_t &...added a check to make sure that won't overflow.