2010-10-21 05:57:26 +02:00
|
|
|
//===-- MBlazeELFWriterInfo.cpp - ELF Writer Info for the MBlaze backend --===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements ELF writer information for the MBlaze backend.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MBlazeELFWriterInfo.h"
|
|
|
|
#include "MBlazeRelocations.h"
|
|
|
|
#include "llvm/Function.h"
|
2010-11-21 23:06:28 +01:00
|
|
|
#include "llvm/Support/ELF.h"
|
2010-10-21 05:57:26 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Target/TargetData.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Implementation of the MBlazeELFWriterInfo class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
MBlazeELFWriterInfo::MBlazeELFWriterInfo(TargetMachine &TM)
|
|
|
|
: TargetELFWriterInfo(TM.getTargetData()->getPointerSizeInBits() == 64,
|
|
|
|
TM.getTargetData()->isLittleEndian()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MBlazeELFWriterInfo::~MBlazeELFWriterInfo() {}
|
|
|
|
|
|
|
|
unsigned MBlazeELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
|
2010-11-08 20:40:01 +01:00
|
|
|
switch (MachineRelTy) {
|
2010-10-21 05:57:26 +02:00
|
|
|
case MBlaze::reloc_pcrel_word:
|
2010-11-21 23:06:28 +01:00
|
|
|
return ELF::R_MICROBLAZE_64_PCREL;
|
2010-10-21 05:57:26 +02:00
|
|
|
case MBlaze::reloc_absolute_word:
|
2010-11-21 23:06:28 +01:00
|
|
|
return ELF::R_MICROBLAZE_NONE;
|
2010-10-21 05:57:26 +02:00
|
|
|
default:
|
|
|
|
llvm_unreachable("unknown mblaze machine relocation type");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
long int MBlazeELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy,
|
|
|
|
long int Modifier) const {
|
2010-11-08 20:40:01 +01:00
|
|
|
switch (RelTy) {
|
2010-11-21 23:06:28 +01:00
|
|
|
case ELF::R_MICROBLAZE_32_PCREL:
|
2010-10-21 05:57:26 +02:00
|
|
|
return Modifier - 4;
|
2010-11-21 23:06:28 +01:00
|
|
|
case ELF::R_MICROBLAZE_32:
|
2010-10-21 05:57:26 +02:00
|
|
|
return Modifier;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unknown mblaze relocation type");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MBlazeELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
|
|
|
|
// FIXME: Most of these sizes are guesses based on the name
|
2010-11-08 20:40:01 +01:00
|
|
|
switch (RelTy) {
|
2010-11-21 23:06:28 +01:00
|
|
|
case ELF::R_MICROBLAZE_32:
|
|
|
|
case ELF::R_MICROBLAZE_32_PCREL:
|
|
|
|
case ELF::R_MICROBLAZE_32_PCREL_LO:
|
|
|
|
case ELF::R_MICROBLAZE_32_LO:
|
|
|
|
case ELF::R_MICROBLAZE_SRO32:
|
|
|
|
case ELF::R_MICROBLAZE_SRW32:
|
|
|
|
case ELF::R_MICROBLAZE_32_SYM_OP_SYM:
|
|
|
|
case ELF::R_MICROBLAZE_GOTOFF_32:
|
2010-10-21 05:57:26 +02:00
|
|
|
return 32;
|
|
|
|
|
2010-11-21 23:06:28 +01:00
|
|
|
case ELF::R_MICROBLAZE_64_PCREL:
|
|
|
|
case ELF::R_MICROBLAZE_64:
|
|
|
|
case ELF::R_MICROBLAZE_GOTPC_64:
|
|
|
|
case ELF::R_MICROBLAZE_GOT_64:
|
|
|
|
case ELF::R_MICROBLAZE_PLT_64:
|
|
|
|
case ELF::R_MICROBLAZE_GOTOFF_64:
|
2010-10-21 05:57:26 +02:00
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MBlazeELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
|
|
|
|
// FIXME: Most of these are guesses based on the name
|
2010-11-08 20:40:01 +01:00
|
|
|
switch (RelTy) {
|
2010-11-21 23:06:28 +01:00
|
|
|
case ELF::R_MICROBLAZE_32_PCREL:
|
|
|
|
case ELF::R_MICROBLAZE_64_PCREL:
|
|
|
|
case ELF::R_MICROBLAZE_32_PCREL_LO:
|
|
|
|
case ELF::R_MICROBLAZE_GOTPC_64:
|
2010-10-21 05:57:26 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MBlazeELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
|
|
|
|
return MBlaze::reloc_absolute_word;
|
|
|
|
}
|
|
|
|
|
|
|
|
long int MBlazeELFWriterInfo::computeRelocation(unsigned SymOffset,
|
|
|
|
unsigned RelOffset,
|
|
|
|
unsigned RelTy) const {
|
2010-11-21 23:06:28 +01:00
|
|
|
if (RelTy == ELF::R_MICROBLAZE_32_PCREL || ELF::R_MICROBLAZE_64_PCREL)
|
2010-10-21 05:57:26 +02:00
|
|
|
return SymOffset - (RelOffset + 4);
|
|
|
|
else
|
|
|
|
assert("computeRelocation unknown for this relocation type");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|