[PATCH] D143226: [MC][CodeGen] Define R_RISCV_PLT32 and lower dso_local_equivalent to it
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 22 17:28:32 PST 2023
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcdb9a0c086a5: [MC][CodeGen] Define R_RISCV_PLT32 and lower dso_local_equivalent to it (authored by leonardchan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143226/new/
https://reviews.llvm.org/D143226
Files:
llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
llvm/test/CodeGen/RISCV/dso_local_equivalent.ll
llvm/test/MC/RISCV/elf-reloc-plt32.s
Index: llvm/test/MC/RISCV/elf-reloc-plt32.s
===================================================================
--- /dev/null
+++ llvm/test/MC/RISCV/elf-reloc-plt32.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -triple=riscv64 -filetype=obj %s -o - \
+# RUN: | llvm-readobj -r - | FileCheck %s
+# RUN: llvm-mc -triple=riscv32 -filetype=obj %s -o - \
+# RUN: | llvm-readobj -r - | FileCheck %s
+
+.data
+.word extern_func at PLT - . + 4
+
+# CHECK: Section ({{.*}}) .rela.data {
+# CHECK-NEXT: 0x0 R_RISCV_PLT32 extern_func 0x4
+# CHECK-NEXT: }
Index: llvm/test/CodeGen/RISCV/dso_local_equivalent.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/dso_local_equivalent.ll
@@ -0,0 +1,12 @@
+; RUN: llc -mtriple=riscv64 < %s | FileCheck %s --match-full-lines
+; RUN: llc -mtriple=riscv32 < %s | FileCheck %s --match-full-lines
+
+declare void @extern_func()
+
+; CHECK-LABEL: const:
+; CHECK-NEXT: .word extern_func at PLT-const
+
+;; Note that for riscv32, the ptrtoint will actually upcast the ptr it to an
+;; oversized 64-bit pointer that eventually gets truncated. This isn't needed
+;; for riscv32, but this unifies the RV64 and RV32 test cases.
+ at const = dso_local constant i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @extern_func to i64), i64 ptrtoint (ptr @const to i64)) to i32)
Index: llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp
@@ -18,6 +18,8 @@
const TargetMachine &TM) {
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
+ PLTRelativeVariantKind = MCSymbolRefExpr::VK_PLT;
+
SmallDataSection = getContext().getELFSection(
".sdata", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
@@ -13,6 +13,7 @@
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCObjectWriter.h"
+#include "llvm/MC/MCValue.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
@@ -61,7 +62,9 @@
return ELF::R_RISCV_NONE;
case FK_Data_4:
case FK_PCRel_4:
- return ELF::R_RISCV_32_PCREL;
+ return Target.getAccessVariant() == MCSymbolRefExpr::VK_PLT
+ ? ELF::R_RISCV_PLT32
+ : ELF::R_RISCV_32_PCREL;
case RISCV::fixup_riscv_pcrel_hi20:
return ELF::R_RISCV_PCREL_HI20;
case RISCV::fixup_riscv_pcrel_lo12_i:
Index: llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
===================================================================
--- llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
+++ llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
@@ -54,3 +54,4 @@
ELF_RELOC(R_RISCV_SET32, 56)
ELF_RELOC(R_RISCV_32_PCREL, 57)
ELF_RELOC(R_RISCV_IRELATIVE, 58)
+ELF_RELOC(R_RISCV_PLT32, 59)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143226.499683.patch
Type: text/x-patch
Size: 3290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230223/743a5965/attachment.bin>
More information about the llvm-commits
mailing list