Skip to content

Commit 83c3ec1

Browse files
committed
[MC] Move isMemtag test to AArch64
And introduce MCValue::getAddSym & MCValue::getSubSym to simplify code. We do not utilize the MCSymbol argument of needsRelocateWithSymbol as it will go away in the future.
1 parent c39d393 commit 83c3ec1

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

llvm/include/llvm/MC/MCValue.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class MCValue {
4545
const MCSymbolRefExpr *getSymB() const { return SymB; }
4646
uint32_t getRefKind() const { return RefKind; }
4747

48+
const MCSymbol *getAddSym() const {
49+
return SymA ? &SymA->getSymbol() : nullptr;
50+
}
51+
const MCSymbol *getSubSym() const {
52+
return SymB ? &SymB->getSymbol() : nullptr;
53+
}
54+
4855
/// Is this an absolute (as opposed to relocatable) value.
4956
bool isAbsolute() const { return !SymA && !SymB; }
5057

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,15 +1271,6 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
12711271
TargetObjectWriter->getEMachine() == ELF::EM_PPC64);
12721272
}
12731273

1274-
// For memory-tagged symbols, ensure that the relocation uses the symbol. For
1275-
// tagged symbols, we emit an empty relocation (R_AARCH64_NONE) in a special
1276-
// section (SHT_AARCH64_MEMTAG_GLOBALS_STATIC) to indicate to the linker that
1277-
// this global needs to be tagged. In addition, the linker needs to know
1278-
// whether to emit a special addend when relocating `end` symbols, and this
1279-
// can only be determined by the attributes of the symbol itself.
1280-
if (Sym->isMemtag())
1281-
return true;
1282-
12831274
unsigned Binding = Sym->getBinding();
12841275
switch(Binding) {
12851276
default:

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/MC/MCELFObjectWriter.h"
2020
#include "llvm/MC/MCFixup.h"
2121
#include "llvm/MC/MCObjectWriter.h"
22+
#include "llvm/MC/MCSymbolELF.h"
2223
#include "llvm/MC/MCValue.h"
2324
#include "llvm/Support/ErrorHandling.h"
2425
#include <cassert>
@@ -543,6 +544,15 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
543544
bool AArch64ELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
544545
const MCSymbol &,
545546
unsigned) const {
547+
// For memory-tagged symbols, ensure that the relocation uses the symbol. For
548+
// tagged symbols, we emit an empty relocation (R_AARCH64_NONE) in a special
549+
// section (SHT_AARCH64_MEMTAG_GLOBALS_STATIC) to indicate to the linker that
550+
// this global needs to be tagged. In addition, the linker needs to know
551+
// whether to emit a special addend when relocating `end` symbols, and this
552+
// can only be determined by the attributes of the symbol itself.
553+
if (Val.getAddSym() && cast<MCSymbolELF>(Val.getAddSym())->isMemtag())
554+
return true;
555+
546556
if ((Val.getRefKind() & AArch64MCExpr::VK_GOT) == AArch64MCExpr::VK_GOT)
547557
return true;
548558
return is_contained({MCSymbolRefExpr::VK_GOTPCREL, MCSymbolRefExpr::VK_PLT},

0 commit comments

Comments
 (0)