Skip to content

Commit

Permalink
Relative data reloc
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Sep 12, 2024
1 parent 628f82a commit a8bdd06
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions llvm/lib/Target/SBF/MCTargetDesc/SBFMCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/MC/MCSymbol.h"
#include <cassert>
#include <cstdint>
#include <iostream>

using namespace llvm;

Expand Down Expand Up @@ -79,6 +82,7 @@ unsigned SBFMCCodeEmitter::getMachineOpValue(const MCInst &MI,
const MCOperand &MO,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
std::cout << "I am here!" << std::endl;
if (MO.isReg())
return MRI.getEncodingValue(MO.getReg());
if (MO.isImm())
Expand All @@ -94,8 +98,21 @@ unsigned SBFMCCodeEmitter::getMachineOpValue(const MCInst &MI,
// func call name
Fixups.push_back(MCFixup::create(0, Expr, FK_PCRel_4));
else if (MI.getOpcode() == SBF::LD_imm64 ||
MI.getOpcode() == SBF::MOV_32_64_addr)
Fixups.push_back(MCFixup::create(0, Expr, FK_SecRel_8));
MI.getOpcode() == SBF::MOV_32_64_addr) {
const MCSymbolRefExpr * SymbolExpr = dyn_cast<MCSymbolRefExpr>(Expr);
const MCSymbol& Sym = SymbolExpr->getSymbol();
if (Sym.isInSection()) {
Fixups.push_back(MCFixup::create(0, Expr, FK_SecRel_8));
} else {
Fixups.push_back(MCFixup::create(0, Expr, FK_Data_8));
}
// std::cout << "Name: " << MySym.getName().str() << std::endl;
// std::cout << "Is absolute: " << MySym.isAbsolute() << std::endl;
// std::cout << "Defined in some section: " << MySym.isInSection() << std::endl;
// std::cout << "Is this a data section: " << SK.isData() << std::endl;
// std::cout << "Is this a text section: " << SK.isText() << std::endl;
//Fixups.push_back(MCFixup::create(0, Expr, FK_SecRel_8));
}
// In SBFv2, LD_imm64 is replaced by MOV_32_64_addr and HOR_addr when loading
// addresses. These two instructions always appear together, so if a
// relocation is necessary, we only insert it for one of them, in this case
Expand Down

0 comments on commit a8bdd06

Please sign in to comment.