mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-23 00:20:25 +00:00
Add a MCObjectFormat class so that code common to all targets that use a
single object format can be shared. This also adds support for mov zed+(bar-foo), %eax on ELF and COFF targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116675 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -43,6 +43,8 @@ private:
|
|||||||
protected:
|
protected:
|
||||||
explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
|
explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
|
||||||
|
|
||||||
|
bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
|
||||||
|
bool InSet) const;
|
||||||
public:
|
public:
|
||||||
/// @name Accessors
|
/// @name Accessors
|
||||||
/// @{
|
/// @{
|
||||||
|
|||||||
52
include/llvm/MC/MCObjectFormat.h
Normal file
52
include/llvm/MC/MCObjectFormat.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
//===-- llvm/MC/MCObjectFormat.h - Object Format Info -----------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_MC_MCOBJECTFORMAT_H
|
||||||
|
#define LLVM_MC_MCOBJECTFORMAT_H
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
class MCSymbol;
|
||||||
|
|
||||||
|
class MCObjectFormat {
|
||||||
|
public:
|
||||||
|
/// isAbsolute - Check if A - B is an absolute value
|
||||||
|
///
|
||||||
|
/// \param InSet - True if this expression is in a set. For example:
|
||||||
|
/// a:
|
||||||
|
/// ...
|
||||||
|
/// b:
|
||||||
|
/// tmp = a - b
|
||||||
|
/// .long tmp
|
||||||
|
/// \param A - LHS
|
||||||
|
/// \param B - RHS
|
||||||
|
virtual bool isAbsolute(bool InSet, const MCSymbol &A,
|
||||||
|
const MCSymbol &B) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MCELFObjectFormat : public MCObjectFormat {
|
||||||
|
public:
|
||||||
|
virtual bool isAbsolute(bool InSet, const MCSymbol &A,
|
||||||
|
const MCSymbol &B) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MCMachOObjectFormat : public MCObjectFormat {
|
||||||
|
public:
|
||||||
|
virtual bool isAbsolute(bool InSet, const MCSymbol &A,
|
||||||
|
const MCSymbol &B) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MCCOFFObjectFormat : public MCObjectFormat {
|
||||||
|
public:
|
||||||
|
virtual bool isAbsolute(bool InSet, const MCSymbol &A,
|
||||||
|
const MCSymbol &B) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End llvm namespace
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -16,6 +16,7 @@ namespace llvm {
|
|||||||
class MCDataFragment;
|
class MCDataFragment;
|
||||||
class MCFixup;
|
class MCFixup;
|
||||||
class MCInst;
|
class MCInst;
|
||||||
|
class MCObjectFormat;
|
||||||
class MCObjectWriter;
|
class MCObjectWriter;
|
||||||
class MCSection;
|
class MCSection;
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -33,7 +34,6 @@ protected: // Can only create subclasses.
|
|||||||
/// TheTarget - The Target that this machine was created for.
|
/// TheTarget - The Target that this machine was created for.
|
||||||
const Target &TheTarget;
|
const Target &TheTarget;
|
||||||
|
|
||||||
unsigned HasAbsolutizedSet : 1;
|
|
||||||
unsigned HasReliableSymbolDifference : 1;
|
unsigned HasReliableSymbolDifference : 1;
|
||||||
unsigned HasScatteredSymbols : 1;
|
unsigned HasScatteredSymbols : 1;
|
||||||
|
|
||||||
@@ -42,23 +42,12 @@ public:
|
|||||||
|
|
||||||
const Target &getTarget() const { return TheTarget; }
|
const Target &getTarget() const { return TheTarget; }
|
||||||
|
|
||||||
|
virtual const MCObjectFormat &getObjectFormat() const = 0;
|
||||||
|
|
||||||
/// createObjectWriter - Create a new MCObjectWriter instance for use by the
|
/// createObjectWriter - Create a new MCObjectWriter instance for use by the
|
||||||
/// assembler backend to emit the final object file.
|
/// assembler backend to emit the final object file.
|
||||||
virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
|
virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
|
||||||
|
|
||||||
/// hasAbsolutizedSet - Check whether this target "absolutizes"
|
|
||||||
/// assignments. That is, given code like:
|
|
||||||
/// a:
|
|
||||||
/// ...
|
|
||||||
/// b:
|
|
||||||
/// tmp = a - b
|
|
||||||
/// .long tmp
|
|
||||||
/// will the value of 'tmp' be a relocatable expression, or the assembly time
|
|
||||||
/// value of L0 - L1. This distinction is only relevant for platforms that
|
|
||||||
/// support scattered symbols, since in the absence of scattered symbols (a -
|
|
||||||
/// b) cannot change after assembly.
|
|
||||||
bool hasAbsolutizedSet() const { return HasAbsolutizedSet; }
|
|
||||||
|
|
||||||
/// hasReliableSymbolDifference - Check whether this target implements
|
/// hasReliableSymbolDifference - Check whether this target implements
|
||||||
/// accurate relocations for differences between symbols. If not, differences
|
/// accurate relocations for differences between symbols. If not, differences
|
||||||
/// between symbols will always be relocatable expressions and any references
|
/// between symbols will always be relocatable expressions and any references
|
||||||
@@ -68,7 +57,7 @@ public:
|
|||||||
/// This should always be true (since it results in fewer relocations with no
|
/// This should always be true (since it results in fewer relocations with no
|
||||||
/// loss of functionality), but is currently supported as a way to maintain
|
/// loss of functionality), but is currently supported as a way to maintain
|
||||||
/// exact object compatibility with Darwin 'as' (on non-x86_64). It should
|
/// exact object compatibility with Darwin 'as' (on non-x86_64). It should
|
||||||
/// eventually should be eliminated. See also \see hasAbsolutizedSet.
|
/// eventually should be eliminated.
|
||||||
bool hasReliableSymbolDifference() const {
|
bool hasReliableSymbolDifference() const {
|
||||||
return HasReliableSymbolDifference;
|
return HasReliableSymbolDifference;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ add_llvm_library(LLVMMC
|
|||||||
MCMachOStreamer.cpp
|
MCMachOStreamer.cpp
|
||||||
MCNullStreamer.cpp
|
MCNullStreamer.cpp
|
||||||
MCObjectStreamer.cpp
|
MCObjectStreamer.cpp
|
||||||
|
MCObjectFormat.cpp
|
||||||
MCObjectWriter.cpp
|
MCObjectWriter.cpp
|
||||||
MCSection.cpp
|
MCSection.cpp
|
||||||
MCSectionCOFF.cpp
|
MCSectionCOFF.cpp
|
||||||
|
|||||||
@@ -472,22 +472,11 @@ void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *F, ELFSymbolData &MSD,
|
|||||||
const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(ESize);
|
const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(ESize);
|
||||||
|
|
||||||
if (BE->EvaluateAsRelocatable(Res, &Layout)) {
|
if (BE->EvaluateAsRelocatable(Res, &Layout)) {
|
||||||
uint64_t AddressA = 0;
|
const llvm::MCSymbolRefExpr *A = Res.getSymA();
|
||||||
uint64_t AddressB = 0;
|
const llvm::MCSymbolRefExpr *B = Res.getSymA();
|
||||||
const MCSymbol &SymA = Res.getSymA()->getSymbol();
|
assert(!A || !A->getSymbol().isDefined());
|
||||||
const MCSymbol &SymB = Res.getSymB()->getSymbol();
|
assert(!B || !B->getSymbol().isDefined());
|
||||||
|
Size = Res.getConstant();
|
||||||
if (SymA.isDefined()) {
|
|
||||||
MCSymbolData &A = Layout.getAssembler().getSymbolData(SymA);
|
|
||||||
AddressA = Layout.getSymbolAddress(&A);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SymB.isDefined()) {
|
|
||||||
MCSymbolData &B = Layout.getAssembler().getSymbolData(SymB);
|
|
||||||
AddressB = Layout.getSymbolAddress(&B);
|
|
||||||
}
|
|
||||||
|
|
||||||
Size = AddressA - AddressB;
|
|
||||||
}
|
}
|
||||||
} else if (ESize->getKind() == MCExpr::Constant) {
|
} else if (ESize->getKind() == MCExpr::Constant) {
|
||||||
Size = static_cast<const MCConstantExpr *>(ESize)->getValue();
|
Size = static_cast<const MCConstantExpr *>(ESize)->getValue();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "llvm/MC/MCAsmLayout.h"
|
#include "llvm/MC/MCAsmLayout.h"
|
||||||
#include "llvm/MC/MCAssembler.h"
|
#include "llvm/MC/MCAssembler.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
|
#include "llvm/MC/MCObjectFormat.h"
|
||||||
#include "llvm/MC/MCSymbol.h"
|
#include "llvm/MC/MCSymbol.h"
|
||||||
#include "llvm/MC/MCValue.h"
|
#include "llvm/MC/MCValue.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
@@ -237,7 +238,8 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool EvaluateSymbolicAdd(const MCValue &LHS,const MCSymbolRefExpr *RHS_A,
|
static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, bool InSet,
|
||||||
|
const MCValue &LHS,const MCSymbolRefExpr *RHS_A,
|
||||||
const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst,
|
const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst,
|
||||||
MCValue &Res) {
|
MCValue &Res) {
|
||||||
// We can't add or subtract two symbols.
|
// We can't add or subtract two symbols.
|
||||||
@@ -255,12 +257,40 @@ static bool EvaluateSymbolicAdd(const MCValue &LHS,const MCSymbolRefExpr *RHS_A,
|
|||||||
if (!A)
|
if (!A)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Absolutize symbol differences between defined symbols when we have a
|
||||||
|
// layout object and the target requests it.
|
||||||
|
|
||||||
|
if (Layout && A && B) {
|
||||||
|
const MCSymbol &SA = A->getSymbol();
|
||||||
|
const MCSymbol &SB = B->getSymbol();
|
||||||
|
const MCObjectFormat &F =
|
||||||
|
Layout->getAssembler().getBackend().getObjectFormat();
|
||||||
|
if (SA.isDefined() && SB.isDefined() && F.isAbsolute(InSet, SA, SB)) {
|
||||||
|
const MCAssembler &Asm = Layout->getAssembler();
|
||||||
|
MCSymbolData &AD = Asm.getSymbolData(A->getSymbol());
|
||||||
|
MCSymbolData &BD = Asm.getSymbolData(B->getSymbol());
|
||||||
|
Res = MCValue::get(+ Layout->getSymbolAddress(&AD)
|
||||||
|
- Layout->getSymbolAddress(&BD)
|
||||||
|
+ LHS.getConstant()
|
||||||
|
+ RHS_Cst);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst);
|
Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
|
bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
|
||||||
const MCAsmLayout *Layout) const {
|
const MCAsmLayout *Layout) const {
|
||||||
|
return EvaluateAsRelocatableImpl(Res, Layout, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
|
||||||
|
const MCAsmLayout *Layout,
|
||||||
|
bool InSet) const {
|
||||||
++stats::MCExprEvaluate;
|
++stats::MCExprEvaluate;
|
||||||
|
|
||||||
switch (getKind()) {
|
switch (getKind()) {
|
||||||
@@ -276,27 +306,9 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
|
|||||||
const MCSymbol &Sym = SRE->getSymbol();
|
const MCSymbol &Sym = SRE->getSymbol();
|
||||||
|
|
||||||
// Evaluate recursively if this is a variable.
|
// Evaluate recursively if this is a variable.
|
||||||
if (Sym.isVariable()) {
|
if (Sym.isVariable())
|
||||||
if (!Sym.getVariableValue()->EvaluateAsRelocatable(Res, Layout))
|
return Sym.getVariableValue()->EvaluateAsRelocatableImpl(Res, Layout,
|
||||||
return false;
|
true);
|
||||||
|
|
||||||
// Absolutize symbol differences between defined symbols when we have a
|
|
||||||
// layout object and the target requests it.
|
|
||||||
if (Layout && Res.getSymB() &&
|
|
||||||
Layout->getAssembler().getBackend().hasAbsolutizedSet() &&
|
|
||||||
Res.getSymA()->getSymbol().isDefined() &&
|
|
||||||
Res.getSymB()->getSymbol().isDefined()) {
|
|
||||||
MCSymbolData &A =
|
|
||||||
Layout->getAssembler().getSymbolData(Res.getSymA()->getSymbol());
|
|
||||||
MCSymbolData &B =
|
|
||||||
Layout->getAssembler().getSymbolData(Res.getSymB()->getSymbol());
|
|
||||||
Res = MCValue::get(+ Layout->getSymbolAddress(&A)
|
|
||||||
- Layout->getSymbolAddress(&B)
|
|
||||||
+ Res.getConstant());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Res = MCValue::get(SRE, 0, 0);
|
Res = MCValue::get(SRE, 0, 0);
|
||||||
return true;
|
return true;
|
||||||
@@ -306,7 +318,7 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
|
|||||||
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
|
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
|
||||||
MCValue Value;
|
MCValue Value;
|
||||||
|
|
||||||
if (!AUE->getSubExpr()->EvaluateAsRelocatable(Value, Layout))
|
if (!AUE->getSubExpr()->EvaluateAsRelocatableImpl(Value, Layout, InSet))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (AUE->getOpcode()) {
|
switch (AUE->getOpcode()) {
|
||||||
@@ -339,8 +351,8 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
|
|||||||
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
|
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
|
||||||
MCValue LHSValue, RHSValue;
|
MCValue LHSValue, RHSValue;
|
||||||
|
|
||||||
if (!ABE->getLHS()->EvaluateAsRelocatable(LHSValue, Layout) ||
|
if (!ABE->getLHS()->EvaluateAsRelocatableImpl(LHSValue, Layout, InSet) ||
|
||||||
!ABE->getRHS()->EvaluateAsRelocatable(RHSValue, Layout))
|
!ABE->getRHS()->EvaluateAsRelocatableImpl(RHSValue, Layout, InSet))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// We only support a few operations on non-constant expressions, handle
|
// We only support a few operations on non-constant expressions, handle
|
||||||
@@ -351,13 +363,13 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
|
|||||||
return false;
|
return false;
|
||||||
case MCBinaryExpr::Sub:
|
case MCBinaryExpr::Sub:
|
||||||
// Negate RHS and add.
|
// Negate RHS and add.
|
||||||
return EvaluateSymbolicAdd(LHSValue,
|
return EvaluateSymbolicAdd(Layout, InSet, LHSValue,
|
||||||
RHSValue.getSymB(), RHSValue.getSymA(),
|
RHSValue.getSymB(), RHSValue.getSymA(),
|
||||||
-RHSValue.getConstant(),
|
-RHSValue.getConstant(),
|
||||||
Res);
|
Res);
|
||||||
|
|
||||||
case MCBinaryExpr::Add:
|
case MCBinaryExpr::Add:
|
||||||
return EvaluateSymbolicAdd(LHSValue,
|
return EvaluateSymbolicAdd(Layout, InSet, LHSValue,
|
||||||
RHSValue.getSymA(), RHSValue.getSymB(),
|
RHSValue.getSymA(), RHSValue.getSymB(),
|
||||||
RHSValue.getConstant(),
|
RHSValue.getConstant(),
|
||||||
Res);
|
Res);
|
||||||
|
|||||||
31
lib/MC/MCObjectFormat.cpp
Normal file
31
lib/MC/MCObjectFormat.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
//===- lib/MC/MCObjectFormat.cpp - MCObjectFormat implementation ----------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/MC/MCObjectFormat.h"
|
||||||
|
#include "llvm/MC/MCSymbol.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
bool MCELFObjectFormat::isAbsolute(bool IsSet, const MCSymbol &A,
|
||||||
|
const MCSymbol &B) const {
|
||||||
|
// On ELF A - B is absolute if A and B are in the same section.
|
||||||
|
return &A.getSection() == &B.getSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MCMachOObjectFormat::isAbsolute(bool IsSet, const MCSymbol &A,
|
||||||
|
const MCSymbol &B) const {
|
||||||
|
// On MachO A - B is absolute only if in a set.
|
||||||
|
return IsSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MCCOFFObjectFormat::isAbsolute(bool IsSet, const MCSymbol &A,
|
||||||
|
const MCSymbol &B) const {
|
||||||
|
// On COFF A - B is absolute if A and B are in the same section.
|
||||||
|
return &A.getSection() == &B.getSection();
|
||||||
|
}
|
||||||
@@ -12,7 +12,6 @@ using namespace llvm;
|
|||||||
|
|
||||||
TargetAsmBackend::TargetAsmBackend(const Target &T)
|
TargetAsmBackend::TargetAsmBackend(const Target &T)
|
||||||
: TheTarget(T),
|
: TheTarget(T),
|
||||||
HasAbsolutizedSet(false),
|
|
||||||
HasReliableSymbolDifference(false),
|
HasReliableSymbolDifference(false),
|
||||||
HasScatteredSymbols(false)
|
HasScatteredSymbols(false)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "llvm/MC/ELFObjectWriter.h"
|
#include "llvm/MC/ELFObjectWriter.h"
|
||||||
#include "llvm/MC/MCAssembler.h"
|
#include "llvm/MC/MCAssembler.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
|
#include "llvm/MC/MCObjectFormat.h"
|
||||||
#include "llvm/MC/MCObjectWriter.h"
|
#include "llvm/MC/MCObjectWriter.h"
|
||||||
#include "llvm/MC/MCSectionELF.h"
|
#include "llvm/MC/MCSectionELF.h"
|
||||||
#include "llvm/MC/MCSectionMachO.h"
|
#include "llvm/MC/MCSectionMachO.h"
|
||||||
@@ -66,14 +67,19 @@ namespace {
|
|||||||
// FIXME: This should be in a separate file.
|
// FIXME: This should be in a separate file.
|
||||||
// ELF is an ELF of course...
|
// ELF is an ELF of course...
|
||||||
class ELFARMAsmBackend : public ARMAsmBackend {
|
class ELFARMAsmBackend : public ARMAsmBackend {
|
||||||
|
MCELFObjectFormat Format;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Triple::OSType OSType;
|
Triple::OSType OSType;
|
||||||
ELFARMAsmBackend(const Target &T, Triple::OSType _OSType)
|
ELFARMAsmBackend(const Target &T, Triple::OSType _OSType)
|
||||||
: ARMAsmBackend(T), OSType(_OSType) {
|
: ARMAsmBackend(T), OSType(_OSType) {
|
||||||
HasAbsolutizedSet = true;
|
|
||||||
HasScatteredSymbols = true;
|
HasScatteredSymbols = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const MCObjectFormat &getObjectFormat() const {
|
||||||
|
return Format;
|
||||||
|
}
|
||||||
|
|
||||||
void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
|
void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
|
||||||
uint64_t Value) const;
|
uint64_t Value) const;
|
||||||
|
|
||||||
@@ -98,14 +104,19 @@ void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
|
|||||||
|
|
||||||
// FIXME: This should be in a separate file.
|
// FIXME: This should be in a separate file.
|
||||||
class DarwinARMAsmBackend : public ARMAsmBackend {
|
class DarwinARMAsmBackend : public ARMAsmBackend {
|
||||||
|
MCMachOObjectFormat Format;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DarwinARMAsmBackend(const Target &T)
|
DarwinARMAsmBackend(const Target &T)
|
||||||
: ARMAsmBackend(T) {
|
: ARMAsmBackend(T) {
|
||||||
HasAbsolutizedSet = true;
|
|
||||||
HasScatteredSymbols = true;
|
HasScatteredSymbols = true;
|
||||||
assert(0 && "DarwinARMAsmBackend::DarwinARMAsmBackend() unimplemented");
|
assert(0 && "DarwinARMAsmBackend::DarwinARMAsmBackend() unimplemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const MCObjectFormat &getObjectFormat() const {
|
||||||
|
return Format;
|
||||||
|
}
|
||||||
|
|
||||||
void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
|
void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
|
||||||
uint64_t Value) const;
|
uint64_t Value) const;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "llvm/MC/ELFObjectWriter.h"
|
#include "llvm/MC/ELFObjectWriter.h"
|
||||||
#include "llvm/MC/MCAssembler.h"
|
#include "llvm/MC/MCAssembler.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
|
#include "llvm/MC/MCObjectFormat.h"
|
||||||
#include "llvm/MC/MCObjectWriter.h"
|
#include "llvm/MC/MCObjectWriter.h"
|
||||||
#include "llvm/MC/MCSectionCOFF.h"
|
#include "llvm/MC/MCSectionCOFF.h"
|
||||||
#include "llvm/MC/MCSectionELF.h"
|
#include "llvm/MC/MCSectionELF.h"
|
||||||
@@ -186,15 +187,20 @@ bool X86AsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class ELFX86AsmBackend : public X86AsmBackend {
|
class ELFX86AsmBackend : public X86AsmBackend {
|
||||||
|
MCELFObjectFormat Format;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Triple::OSType OSType;
|
Triple::OSType OSType;
|
||||||
ELFX86AsmBackend(const Target &T, Triple::OSType _OSType)
|
ELFX86AsmBackend(const Target &T, Triple::OSType _OSType)
|
||||||
: X86AsmBackend(T), OSType(_OSType) {
|
: X86AsmBackend(T), OSType(_OSType) {
|
||||||
HasAbsolutizedSet = true;
|
|
||||||
HasScatteredSymbols = true;
|
HasScatteredSymbols = true;
|
||||||
HasReliableSymbolDifference = true;
|
HasReliableSymbolDifference = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const MCObjectFormat &getObjectFormat() const {
|
||||||
|
return Format;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
|
virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
|
||||||
const MCSectionELF &ES = static_cast<const MCSectionELF&>(Section);
|
const MCSectionELF &ES = static_cast<const MCSectionELF&>(Section);
|
||||||
return ES.getFlags() & MCSectionELF::SHF_MERGE;
|
return ES.getFlags() & MCSectionELF::SHF_MERGE;
|
||||||
@@ -242,6 +248,8 @@ public:
|
|||||||
|
|
||||||
class WindowsX86AsmBackend : public X86AsmBackend {
|
class WindowsX86AsmBackend : public X86AsmBackend {
|
||||||
bool Is64Bit;
|
bool Is64Bit;
|
||||||
|
MCCOFFObjectFormat Format;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WindowsX86AsmBackend(const Target &T, bool is64Bit)
|
WindowsX86AsmBackend(const Target &T, bool is64Bit)
|
||||||
: X86AsmBackend(T)
|
: X86AsmBackend(T)
|
||||||
@@ -249,6 +257,10 @@ public:
|
|||||||
HasScatteredSymbols = true;
|
HasScatteredSymbols = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const MCObjectFormat &getObjectFormat() const {
|
||||||
|
return Format;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned getPointerSize() const {
|
unsigned getPointerSize() const {
|
||||||
if (Is64Bit)
|
if (Is64Bit)
|
||||||
return 8;
|
return 8;
|
||||||
@@ -267,13 +279,18 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class DarwinX86AsmBackend : public X86AsmBackend {
|
class DarwinX86AsmBackend : public X86AsmBackend {
|
||||||
|
MCMachOObjectFormat Format;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DarwinX86AsmBackend(const Target &T)
|
DarwinX86AsmBackend(const Target &T)
|
||||||
: X86AsmBackend(T) {
|
: X86AsmBackend(T) {
|
||||||
HasAbsolutizedSet = true;
|
|
||||||
HasScatteredSymbols = true;
|
HasScatteredSymbols = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const MCObjectFormat &getObjectFormat() const {
|
||||||
|
return Format;
|
||||||
|
}
|
||||||
|
|
||||||
bool isVirtualSection(const MCSection &Section) const {
|
bool isVirtualSection(const MCSection &Section) const {
|
||||||
const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
|
const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
|
||||||
return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
|
return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
|
||||||
|
|||||||
15
test/MC/ELF/diff.s
Normal file
15
test/MC/ELF/diff.s
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
|
||||||
|
|
||||||
|
.global zed
|
||||||
|
foo:
|
||||||
|
nop
|
||||||
|
bar:
|
||||||
|
nop
|
||||||
|
zed:
|
||||||
|
mov zed+(bar-foo), %eax
|
||||||
|
|
||||||
|
// CHECK: # Relocation 0
|
||||||
|
// CHECK-NEXT: (('r_offset', 5)
|
||||||
|
// CHECK-NEXT: ('r_sym', 6)
|
||||||
|
// CHECK-NEXT: ('r_type', 11)
|
||||||
|
// CHECK-NEXT: ('r_addend', 1)
|
||||||
13
test/MC/ELF/diff2.s
Normal file
13
test/MC/ELF/diff2.s
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s 2> %t
|
||||||
|
// RUN: FileCheck -input-file %t %s
|
||||||
|
|
||||||
|
.global zed
|
||||||
|
.data
|
||||||
|
foo:
|
||||||
|
.text
|
||||||
|
nop
|
||||||
|
bar:
|
||||||
|
nop
|
||||||
|
zed:
|
||||||
|
// CHECK: expected relocatable expression
|
||||||
|
mov zed+(bar-foo), %eax
|
||||||
Reference in New Issue
Block a user