[llvm-branch-commits] [RISCV] Replace @plt/@gotpcrel in data directives with %plt %gotpcrel (PR #132569)

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Mar 23 13:30:52 PDT 2025


================
@@ -18,6 +18,6 @@
 .globl _start
 _start:
 .data
-  .word foo at PLT - .
-  .word foo at PLT - . + 1
-  .word foo at PLT - . - 1
+  .word %plt(foo - .)
----------------
MaskRay wrote:

The IR doesn't model the current location (DOT). Instead, It computes `SymA-SymB+offset`.
`SymB` might not be the current location, but it and the current location must be in the same section.

Let's use `llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll` (legacy; but slightly better than `dso_local_equivalent.ll`):

```
@vtable = constant [5 x i32] [i32 0,
    i32 trunc (i64 sub (i64 ptrtoint (ptr @fn1 to i64), i64 ptrtoint (ptr getelementptr ([5 x i32], ptr @vtable, i32 0, i32 1) to i64)) to i32),
    i32 trunc (i64 sub (i64 ptrtoint (ptr @fn2 to i64), i64 ptrtoint (ptr getelementptr ([5 x i32], ptr @vtable, i32 0, i32 1) to i64)) to i32),
    i32 trunc (i64 sub (i64 ptrtoint (ptr @fn3 to i64), i64 ptrtoint (ptr getelementptr ([5 x i32], ptr @vtable, i32 0, i32 1) to i64)) to i32),
    i32 trunc (i64 sub (i64 ptrtoint (ptr @global4 to i64), i64 ptrtoint (ptr getelementptr ([5 x i32], ptr @vtable, i32 0, i32 1) to i64)) to i32)
]
```

If we need to emit `%pltpcrel`, we will have to change `AsmPrinter::lowerConstant` to know the base GlobalVariable, which might be possible...

https://github.com/llvm/llvm-project/pull/132569


More information about the llvm-branch-commits mailing list