-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[RISCV] Add Vendor Reloc and Fallback Names #116974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-binary-utilities @llvm/pr-subscribers-backend-risc-v Author: Sam Elliott (lenary) ChangesThe trunk psABI document specifies that The testcase shows that these parse in Full diff: https://github.com/llvm/llvm-project/pull/116974.diff 2 Files Affected:
diff --git a/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def b/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
index d4be34e3b37e5e..2d7ee0814fe4a1 100644
--- a/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
+++ b/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
@@ -61,3 +61,68 @@ ELF_RELOC(R_RISCV_TLSDESC_HI20, 62)
ELF_RELOC(R_RISCV_TLSDESC_LOAD_LO12, 63)
ELF_RELOC(R_RISCV_TLSDESC_ADD_LO12, 64)
ELF_RELOC(R_RISCV_TLSDESC_CALL, 65)
+ELF_RELOC(R_RISCV_VENDOR, 191)
+ELF_RELOC(R_RISCV_CUSTOM192, 192)
+ELF_RELOC(R_RISCV_CUSTOM193, 193)
+ELF_RELOC(R_RISCV_CUSTOM194, 194)
+ELF_RELOC(R_RISCV_CUSTOM195, 195)
+ELF_RELOC(R_RISCV_CUSTOM196, 196)
+ELF_RELOC(R_RISCV_CUSTOM197, 197)
+ELF_RELOC(R_RISCV_CUSTOM198, 198)
+ELF_RELOC(R_RISCV_CUSTOM199, 199)
+ELF_RELOC(R_RISCV_CUSTOM200, 200)
+ELF_RELOC(R_RISCV_CUSTOM201, 201)
+ELF_RELOC(R_RISCV_CUSTOM202, 202)
+ELF_RELOC(R_RISCV_CUSTOM203, 203)
+ELF_RELOC(R_RISCV_CUSTOM204, 204)
+ELF_RELOC(R_RISCV_CUSTOM205, 205)
+ELF_RELOC(R_RISCV_CUSTOM206, 206)
+ELF_RELOC(R_RISCV_CUSTOM207, 207)
+ELF_RELOC(R_RISCV_CUSTOM208, 208)
+ELF_RELOC(R_RISCV_CUSTOM209, 209)
+ELF_RELOC(R_RISCV_CUSTOM210, 210)
+ELF_RELOC(R_RISCV_CUSTOM211, 211)
+ELF_RELOC(R_RISCV_CUSTOM212, 212)
+ELF_RELOC(R_RISCV_CUSTOM213, 213)
+ELF_RELOC(R_RISCV_CUSTOM214, 214)
+ELF_RELOC(R_RISCV_CUSTOM215, 215)
+ELF_RELOC(R_RISCV_CUSTOM216, 216)
+ELF_RELOC(R_RISCV_CUSTOM217, 217)
+ELF_RELOC(R_RISCV_CUSTOM218, 218)
+ELF_RELOC(R_RISCV_CUSTOM219, 219)
+ELF_RELOC(R_RISCV_CUSTOM220, 220)
+ELF_RELOC(R_RISCV_CUSTOM221, 221)
+ELF_RELOC(R_RISCV_CUSTOM222, 222)
+ELF_RELOC(R_RISCV_CUSTOM223, 223)
+ELF_RELOC(R_RISCV_CUSTOM224, 224)
+ELF_RELOC(R_RISCV_CUSTOM225, 225)
+ELF_RELOC(R_RISCV_CUSTOM226, 226)
+ELF_RELOC(R_RISCV_CUSTOM227, 227)
+ELF_RELOC(R_RISCV_CUSTOM228, 228)
+ELF_RELOC(R_RISCV_CUSTOM229, 229)
+ELF_RELOC(R_RISCV_CUSTOM230, 230)
+ELF_RELOC(R_RISCV_CUSTOM231, 231)
+ELF_RELOC(R_RISCV_CUSTOM232, 232)
+ELF_RELOC(R_RISCV_CUSTOM233, 233)
+ELF_RELOC(R_RISCV_CUSTOM234, 234)
+ELF_RELOC(R_RISCV_CUSTOM235, 235)
+ELF_RELOC(R_RISCV_CUSTOM236, 236)
+ELF_RELOC(R_RISCV_CUSTOM237, 237)
+ELF_RELOC(R_RISCV_CUSTOM238, 238)
+ELF_RELOC(R_RISCV_CUSTOM239, 239)
+ELF_RELOC(R_RISCV_CUSTOM240, 240)
+ELF_RELOC(R_RISCV_CUSTOM241, 241)
+ELF_RELOC(R_RISCV_CUSTOM242, 242)
+ELF_RELOC(R_RISCV_CUSTOM243, 243)
+ELF_RELOC(R_RISCV_CUSTOM244, 244)
+ELF_RELOC(R_RISCV_CUSTOM245, 245)
+ELF_RELOC(R_RISCV_CUSTOM246, 246)
+ELF_RELOC(R_RISCV_CUSTOM247, 247)
+ELF_RELOC(R_RISCV_CUSTOM248, 248)
+ELF_RELOC(R_RISCV_CUSTOM249, 249)
+ELF_RELOC(R_RISCV_CUSTOM250, 250)
+ELF_RELOC(R_RISCV_CUSTOM251, 251)
+ELF_RELOC(R_RISCV_CUSTOM252, 252)
+ELF_RELOC(R_RISCV_CUSTOM253, 253)
+ELF_RELOC(R_RISCV_CUSTOM254, 254)
+ELF_RELOC(R_RISCV_CUSTOM255, 255)
diff --git a/llvm/test/MC/RISCV/custom_reloc.s b/llvm/test/MC/RISCV/custom_reloc.s
new file mode 100644
index 00000000000000..3058cffe4b5914
--- /dev/null
+++ b/llvm/test/MC/RISCV/custom_reloc.s
@@ -0,0 +1,43 @@
+# RUN: llvm-mc -triple riscv32 < %s \
+# RUN: | FileCheck -check-prefix=CHECK-ASM %s
+# RUN: llvm-mc -triple riscv64 < %s \
+# RUN: | FileCheck -check-prefix=CHECK-ASM %s
+
+# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
+# RUN: | llvm-objdump -dr -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
+# RUN: | llvm-objdump -dr -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-OBJ %s
+
+ # CHECK-ASM: .text
+
+ # If `.set` is used instead, the relocation expression will be evaluated.
+ # This leaves an undef, global symbol called VENDOR_NAME, which I'm not happy
+ # about.
+ .global VENDOR_NAME
+
+ # CHECK-OBJ: <.text>:
+
+ nop
+ # CHECK-ASM: nop
+ # CHECK-OBJ: addi zero, zero, 0x0
+
+ .reloc ., R_RISCV_VENDOR, VENDOR_NAME
+ .reloc ., R_RISCV_CUSTOM192, my_foo + 1
+ addi a0, a0, 0
+ # CHECK-ASM: [[L1:.L[^:]+]]:
+ # CHECK-ASM-NEXT: .reloc [[L1]], R_RISCV_VENDOR, VENDOR_NAME
+ # CHECK-ASM-NEXT: [[L2:.L[^:]+]]:
+ # CHECK-ASM-NEXT: .reloc [[L2]], R_RISCV_CUSTOM192, my_foo+1
+ # CHECK-ASM-NEXT: mv a0, a0
+
+ # CHECK-OBJ: addi a0, a0, 0
+ # CHECK-OBJ-NEXT: R_RISCV_VENDOR VENDOR_NAME
+ # CHECK-OBJ-NEXT: R_RISCV_CUSTOM192 my_foo+0x1
+
+ nop
+ # CHECK-ASM: nop
+ # CHECK-OBJ: addi zero, zero, 0x0
+
+
|
@llvm/pr-subscribers-mc Author: Sam Elliott (lenary) ChangesThe trunk psABI document specifies that The testcase shows that these parse in Full diff: https://github.com/llvm/llvm-project/pull/116974.diff 2 Files Affected:
diff --git a/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def b/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
index d4be34e3b37e5e..2d7ee0814fe4a1 100644
--- a/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
+++ b/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
@@ -61,3 +61,68 @@ ELF_RELOC(R_RISCV_TLSDESC_HI20, 62)
ELF_RELOC(R_RISCV_TLSDESC_LOAD_LO12, 63)
ELF_RELOC(R_RISCV_TLSDESC_ADD_LO12, 64)
ELF_RELOC(R_RISCV_TLSDESC_CALL, 65)
+ELF_RELOC(R_RISCV_VENDOR, 191)
+ELF_RELOC(R_RISCV_CUSTOM192, 192)
+ELF_RELOC(R_RISCV_CUSTOM193, 193)
+ELF_RELOC(R_RISCV_CUSTOM194, 194)
+ELF_RELOC(R_RISCV_CUSTOM195, 195)
+ELF_RELOC(R_RISCV_CUSTOM196, 196)
+ELF_RELOC(R_RISCV_CUSTOM197, 197)
+ELF_RELOC(R_RISCV_CUSTOM198, 198)
+ELF_RELOC(R_RISCV_CUSTOM199, 199)
+ELF_RELOC(R_RISCV_CUSTOM200, 200)
+ELF_RELOC(R_RISCV_CUSTOM201, 201)
+ELF_RELOC(R_RISCV_CUSTOM202, 202)
+ELF_RELOC(R_RISCV_CUSTOM203, 203)
+ELF_RELOC(R_RISCV_CUSTOM204, 204)
+ELF_RELOC(R_RISCV_CUSTOM205, 205)
+ELF_RELOC(R_RISCV_CUSTOM206, 206)
+ELF_RELOC(R_RISCV_CUSTOM207, 207)
+ELF_RELOC(R_RISCV_CUSTOM208, 208)
+ELF_RELOC(R_RISCV_CUSTOM209, 209)
+ELF_RELOC(R_RISCV_CUSTOM210, 210)
+ELF_RELOC(R_RISCV_CUSTOM211, 211)
+ELF_RELOC(R_RISCV_CUSTOM212, 212)
+ELF_RELOC(R_RISCV_CUSTOM213, 213)
+ELF_RELOC(R_RISCV_CUSTOM214, 214)
+ELF_RELOC(R_RISCV_CUSTOM215, 215)
+ELF_RELOC(R_RISCV_CUSTOM216, 216)
+ELF_RELOC(R_RISCV_CUSTOM217, 217)
+ELF_RELOC(R_RISCV_CUSTOM218, 218)
+ELF_RELOC(R_RISCV_CUSTOM219, 219)
+ELF_RELOC(R_RISCV_CUSTOM220, 220)
+ELF_RELOC(R_RISCV_CUSTOM221, 221)
+ELF_RELOC(R_RISCV_CUSTOM222, 222)
+ELF_RELOC(R_RISCV_CUSTOM223, 223)
+ELF_RELOC(R_RISCV_CUSTOM224, 224)
+ELF_RELOC(R_RISCV_CUSTOM225, 225)
+ELF_RELOC(R_RISCV_CUSTOM226, 226)
+ELF_RELOC(R_RISCV_CUSTOM227, 227)
+ELF_RELOC(R_RISCV_CUSTOM228, 228)
+ELF_RELOC(R_RISCV_CUSTOM229, 229)
+ELF_RELOC(R_RISCV_CUSTOM230, 230)
+ELF_RELOC(R_RISCV_CUSTOM231, 231)
+ELF_RELOC(R_RISCV_CUSTOM232, 232)
+ELF_RELOC(R_RISCV_CUSTOM233, 233)
+ELF_RELOC(R_RISCV_CUSTOM234, 234)
+ELF_RELOC(R_RISCV_CUSTOM235, 235)
+ELF_RELOC(R_RISCV_CUSTOM236, 236)
+ELF_RELOC(R_RISCV_CUSTOM237, 237)
+ELF_RELOC(R_RISCV_CUSTOM238, 238)
+ELF_RELOC(R_RISCV_CUSTOM239, 239)
+ELF_RELOC(R_RISCV_CUSTOM240, 240)
+ELF_RELOC(R_RISCV_CUSTOM241, 241)
+ELF_RELOC(R_RISCV_CUSTOM242, 242)
+ELF_RELOC(R_RISCV_CUSTOM243, 243)
+ELF_RELOC(R_RISCV_CUSTOM244, 244)
+ELF_RELOC(R_RISCV_CUSTOM245, 245)
+ELF_RELOC(R_RISCV_CUSTOM246, 246)
+ELF_RELOC(R_RISCV_CUSTOM247, 247)
+ELF_RELOC(R_RISCV_CUSTOM248, 248)
+ELF_RELOC(R_RISCV_CUSTOM249, 249)
+ELF_RELOC(R_RISCV_CUSTOM250, 250)
+ELF_RELOC(R_RISCV_CUSTOM251, 251)
+ELF_RELOC(R_RISCV_CUSTOM252, 252)
+ELF_RELOC(R_RISCV_CUSTOM253, 253)
+ELF_RELOC(R_RISCV_CUSTOM254, 254)
+ELF_RELOC(R_RISCV_CUSTOM255, 255)
diff --git a/llvm/test/MC/RISCV/custom_reloc.s b/llvm/test/MC/RISCV/custom_reloc.s
new file mode 100644
index 00000000000000..3058cffe4b5914
--- /dev/null
+++ b/llvm/test/MC/RISCV/custom_reloc.s
@@ -0,0 +1,43 @@
+# RUN: llvm-mc -triple riscv32 < %s \
+# RUN: | FileCheck -check-prefix=CHECK-ASM %s
+# RUN: llvm-mc -triple riscv64 < %s \
+# RUN: | FileCheck -check-prefix=CHECK-ASM %s
+
+# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
+# RUN: | llvm-objdump -dr -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
+# RUN: | llvm-objdump -dr -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-OBJ %s
+
+ # CHECK-ASM: .text
+
+ # If `.set` is used instead, the relocation expression will be evaluated.
+ # This leaves an undef, global symbol called VENDOR_NAME, which I'm not happy
+ # about.
+ .global VENDOR_NAME
+
+ # CHECK-OBJ: <.text>:
+
+ nop
+ # CHECK-ASM: nop
+ # CHECK-OBJ: addi zero, zero, 0x0
+
+ .reloc ., R_RISCV_VENDOR, VENDOR_NAME
+ .reloc ., R_RISCV_CUSTOM192, my_foo + 1
+ addi a0, a0, 0
+ # CHECK-ASM: [[L1:.L[^:]+]]:
+ # CHECK-ASM-NEXT: .reloc [[L1]], R_RISCV_VENDOR, VENDOR_NAME
+ # CHECK-ASM-NEXT: [[L2:.L[^:]+]]:
+ # CHECK-ASM-NEXT: .reloc [[L2]], R_RISCV_CUSTOM192, my_foo+1
+ # CHECK-ASM-NEXT: mv a0, a0
+
+ # CHECK-OBJ: addi a0, a0, 0
+ # CHECK-OBJ-NEXT: R_RISCV_VENDOR VENDOR_NAME
+ # CHECK-OBJ-NEXT: R_RISCV_CUSTOM192 my_foo+0x1
+
+ nop
+ # CHECK-ASM: nop
+ # CHECK-OBJ: addi zero, zero, 0x0
+
+
|
Is the expectation that downstream tools support |
I have a solution for Broadly, my intention is to add another header, A lot more reworking of llvm-objdump will be required to support printing out the right name depending on the vendor relocation - in the meantime, it will print out I'm trying to juggle my priorities fairly carefully, and have had to make the hard decision to prioritise the linker implementation of my specification, rather than reworking llvm-objdump, so until I can get to it (likely after 20.0) I think downstream implementations will just have to keep some modifications to I hope this is a reasonable/acceptable way forwards? |
@jrtc27 ping? What do you think of the approach I outlined? |
So, for CHERI-RISC-V, we predate the existence of R_RISCV_VENDOR by many years and thus just use the custom reloc encodings directly with no namespacing. Fixing that isn't worth doing because we're on the path to standardisation, which will yield the necessary relocations existing in the standard range. So your ELF_RISCV_NONSTANDARD_RELOC wouldn't help us, but might be the right shape for "proper" vendor relocations. Which may mean that it's our responsibility to deal with downstream if we're not doing things what is now the "proper" way. |
Ok, so I guess in that case, if we can land this, downstream you would just comment out some of the Once we get I can understand not wanting to regress downstream, and it is mostly a CHERI problem that upstream doesn't care about, but maybe with this sketched out, we can proceed on merging this patch upstream? |
Yeah I've convinced myself that I have no issue with you moving ahead with this upstream. If this becomes a problem we can revisit the conversation at that later date. |
Cool. In that case, please may you approve the PR? |
llvm/test/MC/RISCV/custom_reloc.s
Outdated
nop | ||
# CHECK-ASM: nop | ||
# CHECK-OBJ: addi zero, zero, 0x0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete trailing blank lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
llvm/test/MC/RISCV/custom_reloc.s
Outdated
# RUN: llvm-mc -triple riscv64 < %s \ | ||
# RUN: | FileCheck -check-prefix=CHECK-ASM %s | ||
|
||
# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
< %s
=> %s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
llvm/test/MC/RISCV/custom_reloc.s
Outdated
# If `.set` is used instead, the relocation expression will be evaluated. | ||
# This leaves an undef, global symbol called VENDOR_NAME, which I'm not happy | ||
# about. | ||
.global VENDOR_NAME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can drop this .globl
. Symbols only referenced by .reloc
directives are emitted to .symtab as undefined symbols.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
The trunk psABI document specifies that R_RISCV_VENDOR is 191, and that relocations 192-255 should be printed as R_RISCV_CUSTOM<enum val> in the absence of better information.
a9eeb16
to
6d81b67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the force push, I have some branches stacked on this in my local repo which I wanted to update too.
llvm/test/MC/RISCV/custom_reloc.s
Outdated
# RUN: llvm-mc -triple riscv64 < %s \ | ||
# RUN: | FileCheck -check-prefix=CHECK-ASM %s | ||
|
||
# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
llvm/test/MC/RISCV/custom_reloc.s
Outdated
# If `.set` is used instead, the relocation expression will be evaluated. | ||
# This leaves an undef, global symbol called VENDOR_NAME, which I'm not happy | ||
# about. | ||
.global VENDOR_NAME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
llvm/test/MC/RISCV/custom_reloc.s
Outdated
nop | ||
# CHECK-ASM: nop | ||
# CHECK-OBJ: addi zero, zero, 0x0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ping? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if jrtc27 is happy
The trunk psABI document specifies that
R_RISCV_VENDOR
is 191, and that relocations 192-255 should be printed asR_RISCV_CUSTOM<enum val>
in the absence of better information.The testcase shows that these parse in
.reloc
directives, and also print correctly from both the assembler and objdump. There is almost certainly a better way to test this.