[llvm] AsmPrinter: Remove ELF's special lowerRelativeReference for unnamed_addr function (PR #132684)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 31 20:43:52 PDT 2025
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/132684
>From d6d27a6e94a73342a9b21257b40e17b124d3040f Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Mon, 24 Mar 2025 00:28:34 -0700
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
=?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
.../CodeGen/TargetLoweringObjectFileImpl.h | 4 ----
.../CodeGen/TargetLoweringObjectFileImpl.cpp | 20 -------------------
.../CodeGen/X86/x86-64-plt-relative-reloc.ll | 5 +++--
.../CodeGen/X86/x86-plt-relative-reloc.ll | 4 ++--
4 files changed, 5 insertions(+), 28 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
index 76571690eeda0..293aa9d1faf7d 100644
--- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -112,10 +112,6 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
MCSection *getStaticDtorSection(unsigned Priority,
const MCSymbol *KeySym) const override;
- const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
- const GlobalValue *RHS,
- const TargetMachine &TM) const override;
-
const MCExpr *lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv,
const TargetMachine &TM) const override;
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 0e44acdd1dccc..0f6d0001087d9 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1174,26 +1174,6 @@ MCSection *TargetLoweringObjectFileELF::getStaticDtorSection(
KeySym);
}
-const MCExpr *TargetLoweringObjectFileELF::lowerRelativeReference(
- const GlobalValue *LHS, const GlobalValue *RHS,
- const TargetMachine &TM) const {
- // We may only use a PLT-relative relocation to refer to unnamed_addr
- // functions.
- if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
- return nullptr;
-
- // Basic correctness checks.
- if (LHS->getType()->getPointerAddressSpace() != 0 ||
- RHS->getType()->getPointerAddressSpace() != 0 || LHS->isThreadLocal() ||
- RHS->isThreadLocal())
- return nullptr;
-
- return MCBinaryExpr::createSub(
- MCSymbolRefExpr::create(TM.getSymbol(LHS), PLTRelativeSpecifier,
- getContext()),
- MCSymbolRefExpr::create(TM.getSymbol(RHS), getContext()), getContext());
-}
-
const MCExpr *TargetLoweringObjectFileELF::lowerDSOLocalEquivalent(
const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const {
assert(supportDSOLocalEquivalentLowering());
diff --git a/llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll b/llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll
index f949c83efd03f..02b012cf18199 100644
--- a/llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll
+++ b/llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll
@@ -12,8 +12,9 @@ declare void @fn2() unnamed_addr
declare void @fn3()
@global4 = external unnamed_addr global i8
+;; Generate a PC-relative relocation, which might be rejected by the linker if the referenced symbol is preemptible.
; CHECK: .long 0
-; CHECK-NEXT: .long (fn1 at PLT-vtable)-4
-; CHECK-NEXT: .long (fn2 at PLT-vtable)-4
+; CHECK-NEXT: .long (fn1-vtable)-4
+; CHECK-NEXT: .long (fn2-vtable)-4
; CHECK-NEXT: .long (fn3-vtable)-4
; CHECK-NEXT: .long (global4-vtable)-4
diff --git a/llvm/test/CodeGen/X86/x86-plt-relative-reloc.ll b/llvm/test/CodeGen/X86/x86-plt-relative-reloc.ll
index 8c86cd29d1c81..ea5dd5b5a83a1 100644
--- a/llvm/test/CodeGen/X86/x86-plt-relative-reloc.ll
+++ b/llvm/test/CodeGen/X86/x86-plt-relative-reloc.ll
@@ -11,6 +11,6 @@ declare void @fn2() unnamed_addr
declare void @fn3()
; CHECK: .long 0
-; CHECK-NEXT: .long (fn1 at PLT-vtable)-4
-; CHECK-NEXT: .long (fn2 at PLT-vtable)-4
+; CHECK-NEXT: .long (fn1-vtable)-4
+; CHECK-NEXT: .long (fn2-vtable)-4
; CHECK-NEXT: .long (fn3-vtable)-4
>From 5118497a8af90444612c98abd5d68f6dc2788c18 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Mon, 31 Mar 2025 20:39:11 -0700
Subject: [PATCH 2/3] update tests
Created using spr 1.3.5-bogner
---
.../CodeGen/ARM/{plt-relative-reloc.ll => relative-reloc.ll} | 1 +
.../RISCV/{plt-relative-reloc.ll => relative-reloc.ll} | 5 +++--
.../X86/{x86-plt-relative-reloc.ll => relative-reloc-32.ll} | 0
.../{x86-64-plt-relative-reloc.ll => relative-reloc-64.ll} | 2 +-
4 files changed, 5 insertions(+), 3 deletions(-)
rename llvm/test/CodeGen/ARM/{plt-relative-reloc.ll => relative-reloc.ll} (87%)
rename llvm/test/CodeGen/RISCV/{plt-relative-reloc.ll => relative-reloc.ll} (84%)
rename llvm/test/CodeGen/X86/{x86-plt-relative-reloc.ll => relative-reloc-32.ll} (100%)
rename llvm/test/CodeGen/X86/{x86-64-plt-relative-reloc.ll => relative-reloc-64.ll} (89%)
diff --git a/llvm/test/CodeGen/ARM/plt-relative-reloc.ll b/llvm/test/CodeGen/ARM/relative-reloc.ll
similarity index 87%
rename from llvm/test/CodeGen/ARM/plt-relative-reloc.ll
rename to llvm/test/CodeGen/ARM/relative-reloc.ll
index ede891900e6d0..7badfb566baaf 100644
--- a/llvm/test/CodeGen/ARM/plt-relative-reloc.ll
+++ b/llvm/test/CodeGen/ARM/relative-reloc.ll
@@ -10,6 +10,7 @@ declare void @fn1() unnamed_addr
declare void @fn2() unnamed_addr
declare void @fn3()
+;; Create a PC-relative relocation that the linker might decline if the addend symbol is preemptible.
; CHECK: .long 0
; CHECK-NEXT: .long fn1(prel31)-vtable-4
; CHECK-NEXT: .long fn2(prel31)-vtable-4
diff --git a/llvm/test/CodeGen/RISCV/plt-relative-reloc.ll b/llvm/test/CodeGen/RISCV/relative-reloc.ll
similarity index 84%
rename from llvm/test/CodeGen/RISCV/plt-relative-reloc.ll
rename to llvm/test/CodeGen/RISCV/relative-reloc.ll
index d2dceb773b2e9..6c94b9fce9308 100644
--- a/llvm/test/CodeGen/RISCV/plt-relative-reloc.ll
+++ b/llvm/test/CodeGen/RISCV/relative-reloc.ll
@@ -12,10 +12,11 @@ declare void @fn2() unnamed_addr
declare void @fn3()
@global4 = external unnamed_addr global i8
+;; Create a PC-relative relocation that the linker might decline if the addend symbol is preemptible.
; CHECK: vtable:
; CHECK-NEXT: .word 0 # 0x0
-; CHECK-NEXT: .word %pltpcrel(fn1)
-; CHECK-NEXT: .word %pltpcrel(fn2+4)
+; CHECK-NEXT: .word fn1-vtable-4
+; CHECK-NEXT: .word fn2-vtable-4
; CHECK-NEXT: .word fn3-vtable-4
; CHECK-NEXT: .word global4-vtable-4
; CHECK-NEXT: .size vtable, 20
diff --git a/llvm/test/CodeGen/X86/x86-plt-relative-reloc.ll b/llvm/test/CodeGen/X86/relative-reloc-32.ll
similarity index 100%
rename from llvm/test/CodeGen/X86/x86-plt-relative-reloc.ll
rename to llvm/test/CodeGen/X86/relative-reloc-32.ll
diff --git a/llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll b/llvm/test/CodeGen/X86/relative-reloc-64.ll
similarity index 89%
rename from llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll
rename to llvm/test/CodeGen/X86/relative-reloc-64.ll
index 8e98ecd8400a0..6f88edfa075b8 100644
--- a/llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll
+++ b/llvm/test/CodeGen/X86/relative-reloc-64.ll
@@ -12,7 +12,7 @@ declare void @fn2() unnamed_addr
declare void @fn3()
@global4 = external unnamed_addr global i8
-;; Generate a PC-relative relocation, which might be rejected by the linker if the referenced symbol is preemptible.
+;; Create a PC-relative relocation that the linker might decline if the addend symbol is preemptible.
; CHECK: .long 0
; CHECK-NEXT: .long fn1-vtable-4
; CHECK-NEXT: .long fn2-vtable-4
>From 845d1851abf6651a6828b5e3dcc75604186eef6b Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Mon, 31 Mar 2025 20:43:34 -0700
Subject: [PATCH 3/3] update ARM
Created using spr 1.3.5-bogner
---
llvm/test/CodeGen/ARM/relative-reloc.ll | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/CodeGen/ARM/relative-reloc.ll b/llvm/test/CodeGen/ARM/relative-reloc.ll
index 7badfb566baaf..65053726e66bf 100644
--- a/llvm/test/CodeGen/ARM/relative-reloc.ll
+++ b/llvm/test/CodeGen/ARM/relative-reloc.ll
@@ -12,6 +12,6 @@ declare void @fn3()
;; Create a PC-relative relocation that the linker might decline if the addend symbol is preemptible.
; CHECK: .long 0
-; CHECK-NEXT: .long fn1(prel31)-vtable-4
-; CHECK-NEXT: .long fn2(prel31)-vtable-4
+; CHECK-NEXT: .long fn1-vtable-4
+; CHECK-NEXT: .long fn2-vtable-4
; CHECK-NEXT: .long fn3-vtable-4
More information about the llvm-commits
mailing list