[MC][mips] Replace setRType## methods by single setRTypes function. NFC

MCELFObjectWriter::setRType## methods are always used altogether to
build complete MIPS N64 ABI "chain" of relocations. Using single
function for this task makes code less verbose.
This commit is contained in:
Simon Atanasyan 2020-04-24 11:54:23 +03:00
parent 9aa6792729
commit 0eec6662f6
2 changed files with 17 additions and 44 deletions

View File

@ -130,14 +130,10 @@ public:
}
// N64 relocation type setting
unsigned setRType(unsigned Value, unsigned Type) const {
return ((Type & R_TYPE_MASK) | ((Value & 0xff) << R_TYPE_SHIFT));
}
unsigned setRType2(unsigned Value, unsigned Type) const {
return (Type & R_TYPE2_MASK) | ((Value & 0xff) << R_TYPE2_SHIFT);
}
unsigned setRType3(unsigned Value, unsigned Type) const {
return (Type & R_TYPE3_MASK) | ((Value & 0xff) << R_TYPE3_SHIFT);
static unsigned setRTypes(unsigned Value1, unsigned Value2, unsigned Value3) {
return ((Value1 & 0xff) << R_TYPE_SHIFT) |
((Value2 & 0xff) << R_TYPE2_SHIFT) |
((Value3 & 0xff) << R_TYPE3_SHIFT);
}
unsigned setRSsym(unsigned Value, unsigned Type) const {
return (Type & R_SSYM_MASK) | ((Value & 0xff) << R_SSYM_SHIFT);

View File

@ -289,14 +289,9 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
case FK_TPRel_8:
return ELF::R_MIPS_TLS_TPREL64;
case FK_GPRel_4:
if (is64Bit()) {
unsigned Type = (unsigned)ELF::R_MIPS_NONE;
Type = setRType((unsigned)ELF::R_MIPS_GPREL32, Type);
Type = setRType2((unsigned)ELF::R_MIPS_64, Type);
Type = setRType3((unsigned)ELF::R_MIPS_NONE, Type);
return Type;
}
return ELF::R_MIPS_GPREL32;
return setRTypes(ELF::R_MIPS_GPREL32,
is64Bit() ? ELF::R_MIPS_64 : ELF::R_MIPS_NONE,
ELF::R_MIPS_NONE);
case Mips::fixup_Mips_GPREL16:
return ELF::R_MIPS_GPREL16;
case Mips::fixup_Mips_26:
@ -329,34 +324,16 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
return ELF::R_MIPS_GOT_OFST;
case Mips::fixup_Mips_GOT_DISP:
return ELF::R_MIPS_GOT_DISP;
case Mips::fixup_Mips_GPOFF_HI: {
unsigned Type = (unsigned)ELF::R_MIPS_NONE;
Type = setRType((unsigned)ELF::R_MIPS_GPREL16, Type);
Type = setRType2((unsigned)ELF::R_MIPS_SUB, Type);
Type = setRType3((unsigned)ELF::R_MIPS_HI16, Type);
return Type;
}
case Mips::fixup_MICROMIPS_GPOFF_HI: {
unsigned Type = (unsigned)ELF::R_MIPS_NONE;
Type = setRType((unsigned)ELF::R_MICROMIPS_GPREL16, Type);
Type = setRType2((unsigned)ELF::R_MICROMIPS_SUB, Type);
Type = setRType3((unsigned)ELF::R_MICROMIPS_HI16, Type);
return Type;
}
case Mips::fixup_Mips_GPOFF_LO: {
unsigned Type = (unsigned)ELF::R_MIPS_NONE;
Type = setRType((unsigned)ELF::R_MIPS_GPREL16, Type);
Type = setRType2((unsigned)ELF::R_MIPS_SUB, Type);
Type = setRType3((unsigned)ELF::R_MIPS_LO16, Type);
return Type;
}
case Mips::fixup_MICROMIPS_GPOFF_LO: {
unsigned Type = (unsigned)ELF::R_MIPS_NONE;
Type = setRType((unsigned)ELF::R_MICROMIPS_GPREL16, Type);
Type = setRType2((unsigned)ELF::R_MICROMIPS_SUB, Type);
Type = setRType3((unsigned)ELF::R_MICROMIPS_LO16, Type);
return Type;
}
case Mips::fixup_Mips_GPOFF_HI:
return setRTypes(ELF::R_MIPS_GPREL16, ELF::R_MIPS_SUB, ELF::R_MIPS_HI16);
case Mips::fixup_MICROMIPS_GPOFF_HI:
return setRTypes(ELF::R_MICROMIPS_GPREL16, ELF::R_MICROMIPS_SUB,
ELF::R_MICROMIPS_HI16);
case Mips::fixup_Mips_GPOFF_LO:
return setRTypes(ELF::R_MIPS_GPREL16, ELF::R_MIPS_SUB, ELF::R_MIPS_LO16);
case Mips::fixup_MICROMIPS_GPOFF_LO:
return setRTypes(ELF::R_MICROMIPS_GPREL16, ELF::R_MICROMIPS_SUB,
ELF::R_MICROMIPS_LO16);
case Mips::fixup_Mips_HIGHER:
return ELF::R_MIPS_HIGHER;
case Mips::fixup_Mips_HIGHEST: