Skip to content

Revert "AsmPrinter: Remove ELF's special lowerRelativeReference for unnamed_addr function" #133935

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
lowerSymbolDifference(const MCSymbol *LHS, const MCSymbol *RHS,
int64_t Addend,
std::optional<int64_t> PCRelativeOffset) const;
const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
const GlobalValue *RHS, int64_t Addend,
std::optional<int64_t> PCRelativeOffset,
const TargetMachine &TM) const override;

const MCExpr *lowerDSOLocalEquivalent(const MCSymbol *LHS,
const MCSymbol *RHS, int64_t Addend,
Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,24 @@ const MCExpr *TargetLoweringObjectFileELF::lowerSymbolDifference(
return Res;
}

const MCExpr *TargetLoweringObjectFileELF::lowerRelativeReference(
const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
std::optional<int64_t> PCRelativeOffset, 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 lowerSymbolDifference(TM.getSymbol(LHS), TM.getSymbol(RHS), Addend,
PCRelativeOffset);
}

// Reference the PLT entry of a function, optionally with a subtrahend (`RHS`).
const MCExpr *TargetLoweringObjectFileELF::lowerDSOLocalEquivalent(
const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +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-vtable-4
; CHECK-NEXT: .long fn2-vtable-4
; CHECK-NEXT: .long fn1(prel31)-vtable-4
; CHECK-NEXT: .long fn2(prel31)-vtable-4
; CHECK-NEXT: .long fn3-vtable-4
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ 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 fn1-vtable-4
; CHECK-NEXT: .word fn2-vtable-4
; CHECK-NEXT: .word %pltpcrel(fn1)
; CHECK-NEXT: .word %pltpcrel(fn2+4)
; CHECK-NEXT: .word fn3-vtable-4
; CHECK-NEXT: .word global4-vtable-4
; CHECK-NEXT: .size vtable, 20
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ 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: .long 0
; CHECK-NEXT: .long fn1-vtable-4
; CHECK-NEXT: .long fn2-vtable-4
; CHECK-NEXT: .long fn1@PLT-vtable-4
; CHECK-NEXT: .long fn2@PLT-vtable-4
; CHECK-NEXT: .long fn3-vtable-4
; CHECK-NEXT: .long global4-vtable-4
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ declare void @fn2() unnamed_addr
declare void @fn3()

; CHECK: .long 0
; CHECK-NEXT: .long fn1-vtable-4
; CHECK-NEXT: .long fn2-vtable-4
; CHECK-NEXT: .long fn1@PLT-vtable-4
; CHECK-NEXT: .long fn2@PLT-vtable-4
; CHECK-NEXT: .long fn3-vtable-4
Loading