2014-05-24 20:50:23 +08:00
|
|
|
//===-- AArch64MCExpr.cpp - AArch64 specific MC expression classes --------===//
|
2014-03-29 18:18:08 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the implementation of the assembly expression modifiers
|
|
|
|
// accepted by the AArch64 architecture (e.g. ":lo12:", ":gottprel_g1:", ...).
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "AArch64MCExpr.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2015-03-04 09:24:11 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2015-06-03 04:38:46 +08:00
|
|
|
#include "llvm/MC/MCSymbolELF.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/MC/MCValue.h"
|
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "aarch64symbolrefexpr"
|
|
|
|
|
2015-05-30 09:25:56 +08:00
|
|
|
const AArch64MCExpr *AArch64MCExpr::create(const MCExpr *Expr, VariantKind Kind,
|
2014-03-29 18:18:08 +08:00
|
|
|
MCContext &Ctx) {
|
2014-05-24 20:50:23 +08:00
|
|
|
return new (Ctx) AArch64MCExpr(Expr, Kind);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
StringRef AArch64MCExpr::getVariantKindName() const {
|
2014-03-29 18:18:08 +08:00
|
|
|
switch (static_cast<uint32_t>(getKind())) {
|
|
|
|
case VK_CALL: return "";
|
|
|
|
case VK_LO12: return ":lo12:";
|
|
|
|
case VK_ABS_G3: return ":abs_g3:";
|
|
|
|
case VK_ABS_G2: return ":abs_g2:";
|
2014-04-24 20:56:27 +08:00
|
|
|
case VK_ABS_G2_S: return ":abs_g2_s:";
|
2014-03-29 18:18:08 +08:00
|
|
|
case VK_ABS_G2_NC: return ":abs_g2_nc:";
|
|
|
|
case VK_ABS_G1: return ":abs_g1:";
|
2014-04-24 20:56:27 +08:00
|
|
|
case VK_ABS_G1_S: return ":abs_g1_s:";
|
2014-03-29 18:18:08 +08:00
|
|
|
case VK_ABS_G1_NC: return ":abs_g1_nc:";
|
|
|
|
case VK_ABS_G0: return ":abs_g0:";
|
2014-04-24 20:56:27 +08:00
|
|
|
case VK_ABS_G0_S: return ":abs_g0_s:";
|
2014-03-29 18:18:08 +08:00
|
|
|
case VK_ABS_G0_NC: return ":abs_g0_nc:";
|
|
|
|
case VK_DTPREL_G2: return ":dtprel_g2:";
|
|
|
|
case VK_DTPREL_G1: return ":dtprel_g1:";
|
|
|
|
case VK_DTPREL_G1_NC: return ":dtprel_g1_nc:";
|
|
|
|
case VK_DTPREL_G0: return ":dtprel_g0:";
|
|
|
|
case VK_DTPREL_G0_NC: return ":dtprel_g0_nc:";
|
2014-05-01 00:13:26 +08:00
|
|
|
case VK_DTPREL_HI12: return ":dtprel_hi12:";
|
2014-03-29 18:18:08 +08:00
|
|
|
case VK_DTPREL_LO12: return ":dtprel_lo12:";
|
|
|
|
case VK_DTPREL_LO12_NC: return ":dtprel_lo12_nc:";
|
|
|
|
case VK_TPREL_G2: return ":tprel_g2:";
|
|
|
|
case VK_TPREL_G1: return ":tprel_g1:";
|
|
|
|
case VK_TPREL_G1_NC: return ":tprel_g1_nc:";
|
|
|
|
case VK_TPREL_G0: return ":tprel_g0:";
|
|
|
|
case VK_TPREL_G0_NC: return ":tprel_g0_nc:";
|
2014-05-01 00:13:26 +08:00
|
|
|
case VK_TPREL_HI12: return ":tprel_hi12:";
|
2014-03-29 18:18:08 +08:00
|
|
|
case VK_TPREL_LO12: return ":tprel_lo12:";
|
|
|
|
case VK_TPREL_LO12_NC: return ":tprel_lo12_nc:";
|
|
|
|
case VK_TLSDESC_LO12: return ":tlsdesc_lo12:";
|
|
|
|
case VK_ABS_PAGE: return "";
|
[AArch64] ILP32 Backend Relocation Support
Remove "_NC" suffix and semantics from TLSDESC_LD{64,32}_LO12 and
TLSDESC_ADD_LO12 relocations
Rearrange ordering in AArch64.def to follow relocation encoding
Fix name:
R_AARCH64_P32_LD64_GOT_LO12_NC => R_AARCH64_P32_LD32_GOT_LO12_NC
Add support for several "TLS", "TLSGD", and "TLSLD" relocations for
ILP32
Fix return values from isNonILP32reloc
Add implementations for
R_AARCH64_ADR_PREL_PG_HI21_NC, R_AARCH64_P32_LD32_GOT_LO12_NC,
R_AARCH64_P32_TLSIE_LD32_GOTTPREL_LO12_NC,
R_AARCH64_P32_TLSDESC_LD32_LO12, R_AARCH64_LD64_GOT_LO12_NC,
*TLSLD_LDST128_DTPREL_LO12, *TLSLD_LDST128_DTPREL_LO12_NC,
*TLSLE_LDST128_TPREL_LO12, *TLSLE_LDST128_TPREL_LO12_NC
Modify error messages to give name of equivalent relocation in the
ABI not being used, along with better checking for non-existent
requested relocations.
Added assembler support for "pg_hi21_nc"
Relocation definitions added without implementations:
R_AARCH64_P32_TLSDESC_ADR_PREL21, R_AARCH64_P32_TLSGD_ADR_PREL21,
R_AARCH64_P32_TLSGD_ADD_LO12_NC, R_AARCH64_P32_TLSLD_ADR_PREL21,
R_AARCH64_P32_TLSLD_ADR_PAGE21, R_AARCH64_P32_TLSLD_ADD_LO12_NC,
R_AARCH64_P32_TLSLD_LD_PREL19, R_AARCH64_P32_TLSDESC_LD_PREL19,
R_AARCH64_P32_TLSGD_ADR_PAGE21, R_AARCH64_P32_TLS_DTPREL,
R_AARCH64_P32_TLS_DTPMOD, R_AARCH64_P32_TLS_TPREL,
R_AARCH64_P32_TLSDESC
Fix encoding:
R_AARCH64_P32_TLSDESC_ADR_PAGE21
Reviewers: Peter Smith
Patch by: Joel Jones (jjones@cavium.com)
Differential Revision: https://reviews.llvm.org/D32072
llvm-svn: 301980
2017-05-03 06:01:48 +08:00
|
|
|
case VK_ABS_PAGE_NC: return ":pg_hi21_nc:";
|
2014-03-29 18:18:08 +08:00
|
|
|
case VK_GOT_PAGE: return ":got:";
|
|
|
|
case VK_GOT_LO12: return ":got_lo12:";
|
|
|
|
case VK_GOTTPREL_PAGE: return ":gottprel:";
|
|
|
|
case VK_GOTTPREL_LO12_NC: return ":gottprel_lo12:";
|
|
|
|
case VK_GOTTPREL_G1: return ":gottprel_g1:";
|
|
|
|
case VK_GOTTPREL_G0_NC: return ":gottprel_g0_nc:";
|
|
|
|
case VK_TLSDESC: return "";
|
|
|
|
case VK_TLSDESC_PAGE: return ":tlsdesc:";
|
2018-03-02 04:42:28 +08:00
|
|
|
case VK_SECREL_LO12: return ":secrel_lo12:";
|
|
|
|
case VK_SECREL_HI12: return ":secrel_hi12:";
|
2014-03-29 18:18:08 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Invalid ELF symbol kind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 08:31:39 +08:00
|
|
|
void AArch64MCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
2014-03-29 18:18:08 +08:00
|
|
|
if (getKind() != VK_NONE)
|
|
|
|
OS << getVariantKindName();
|
2015-06-09 08:31:39 +08:00
|
|
|
Expr->print(OS, MAI);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-06-25 23:45:33 +08:00
|
|
|
void AArch64MCExpr::visitUsedExpr(MCStreamer &Streamer) const {
|
2014-06-25 23:29:54 +08:00
|
|
|
Streamer.visitUsedExpr(*getSubExpr());
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:07:05 +08:00
|
|
|
MCFragment *AArch64MCExpr::findAssociatedFragment() const {
|
2014-03-29 18:18:08 +08:00
|
|
|
llvm_unreachable("FIXME: what goes here?");
|
|
|
|
}
|
|
|
|
|
2015-05-30 09:25:56 +08:00
|
|
|
bool AArch64MCExpr::evaluateAsRelocatableImpl(MCValue &Res,
|
2015-09-22 19:15:07 +08:00
|
|
|
const MCAsmLayout *Layout,
|
|
|
|
const MCFixup *Fixup) const {
|
2015-05-30 09:25:56 +08:00
|
|
|
if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup))
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Res =
|
|
|
|
MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
|
|
|
|
switch (Expr->getKind()) {
|
|
|
|
case MCExpr::Target:
|
|
|
|
llvm_unreachable("Can't handle nested target expression");
|
|
|
|
break;
|
|
|
|
case MCExpr::Constant:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCExpr::Binary: {
|
|
|
|
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
|
|
|
|
fixELFSymbolsInTLSFixupsImpl(BE->getLHS(), Asm);
|
|
|
|
fixELFSymbolsInTLSFixupsImpl(BE->getRHS(), Asm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCExpr::SymbolRef: {
|
|
|
|
// We're known to be under a TLS fixup, so any symbol should be
|
|
|
|
// modified. There should be only one.
|
|
|
|
const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
|
2015-06-03 04:38:46 +08:00
|
|
|
cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCExpr::Unary:
|
|
|
|
fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
void AArch64MCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
|
2014-03-29 18:18:08 +08:00
|
|
|
switch (getSymbolLoc(Kind)) {
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
case VK_DTPREL:
|
|
|
|
case VK_GOTTPREL:
|
|
|
|
case VK_TPREL:
|
|
|
|
case VK_TLSDESC:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
|
|
|
|
}
|