diff options
| author | Simon Atanasyan <simon@atanasyan.com> | 2017-09-04 16:16:46 +0000 |
|---|---|---|
| committer | Simon Atanasyan <simon@atanasyan.com> | 2017-09-04 16:16:46 +0000 |
| commit | 7644191fb18ea5b917fd1c7ca786ee2e8252cfd4 (patch) | |
| tree | 85796bae95be97212271fccdb386d1718e8e7c7a | |
| parent | 351cf49579b3f08defb103db10afaa95bdcd9843 (diff) | |
| download | bcm5719-llvm-7644191fb18ea5b917fd1c7ca786ee2e8252cfd4.tar.gz bcm5719-llvm-7644191fb18ea5b917fd1c7ca786ee2e8252cfd4.zip | |
[MIPS] Convert template parameters to function arguments. NFC
Pass BSIZE and SHIFT as a function arguments to the `writeRelocation`
routine. It does not make a sense to have so many `writeRelocation's`
instances.
llvm-svn: 312495
| -rw-r--r-- | lld/ELF/Arch/Mips.cpp | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/lld/ELF/Arch/Mips.cpp b/lld/ELF/Arch/Mips.cpp index a835449652a..3a45f26840f 100644 --- a/lld/ELF/Arch/Mips.cpp +++ b/lld/ELF/Arch/Mips.cpp @@ -142,11 +142,12 @@ void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { write32<ELFT::TargetEndianness>(Buf, InX::Plt->getVA()); } -template <endianness E, uint8_t BSIZE, uint8_t SHIFT> -static void writeRelocation(uint8_t *Loc, uint64_t V) { +template <endianness E> +static void writeRelocation(uint8_t *Loc, uint64_t V, uint8_t BitsSize, + uint8_t Shift) { uint32_t Instr = read32<E>(Loc); - uint32_t Mask = 0xffffffff >> (32 - BSIZE); - uint32_t Data = (Instr & ~Mask) | ((V >> SHIFT) & Mask); + uint32_t Mask = 0xffffffff >> (32 - BitsSize); + uint32_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask); write32<E>(Loc, Data); } @@ -176,9 +177,9 @@ template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const { write32<E>(Buf + 28, 0x2718fffe); // subu $24, $24, 2 uint64_t GotPlt = InX::GotPlt->getVA(); - writeRelocation<E, 16, 16>(Buf, GotPlt + 0x8000); - writeRelocation<E, 16, 0>(Buf + 4, GotPlt); - writeRelocation<E, 16, 0>(Buf + 8, GotPlt); + writeRelocation<E>(Buf, GotPlt + 0x8000, 16, 16); + writeRelocation<E>(Buf + 4, GotPlt, 16, 0); + writeRelocation<E>(Buf + 8, GotPlt, 16, 0); } template <class ELFT> @@ -191,9 +192,9 @@ void MIPS<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, // jr $25 write32<E>(Buf + 8, isMipsR6<ELFT>() ? 0x03200009 : 0x03200008); write32<E>(Buf + 12, 0x25f80000); // addiu $24, $15, %lo(.got.plt entry) - writeRelocation<E, 16, 16>(Buf, GotPltEntryAddr + 0x8000); - writeRelocation<E, 16, 0>(Buf + 4, GotPltEntryAddr); - writeRelocation<E, 16, 0>(Buf + 12, GotPltEntryAddr); + writeRelocation<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16); + writeRelocation<E>(Buf + 4, GotPltEntryAddr, 16, 0); + writeRelocation<E>(Buf + 12, GotPltEntryAddr, 16, 0); } template <class ELFT> @@ -312,17 +313,17 @@ void MIPS<ELFT>::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const { write64<E>(Loc, Val); break; case R_MIPS_26: - writeRelocation<E, 26, 2>(Loc, Val); + writeRelocation<E>(Loc, Val, 26, 2); break; case R_MIPS_GOT16: // The R_MIPS_GOT16 relocation's value in "relocatable" linking mode // is updated addend (not a GOT index). In that case write high 16 bits // to store a correct addend value. if (Config->Relocatable) { - writeRelocation<E, 16, 16>(Loc, Val + 0x8000); + writeRelocation<E>(Loc, Val + 0x8000, 16, 16); } else { checkInt<16>(Loc, Val, Type); - writeRelocation<E, 16, 0>(Loc, Val); + writeRelocation<E>(Loc, Val, 16, 0); } break; case R_MIPS_GOT_DISP: @@ -341,7 +342,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const { case R_MIPS_TLS_DTPREL_LO16: case R_MIPS_TLS_GOTTPREL: case R_MIPS_TLS_TPREL_LO16: - writeRelocation<E, 16, 0>(Loc, Val); + writeRelocation<E>(Loc, Val, 16, 0); break; case R_MIPS_CALL_HI16: case R_MIPS_GOT_HI16: @@ -349,13 +350,13 @@ void MIPS<ELFT>::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const { case R_MIPS_PCHI16: case R_MIPS_TLS_DTPREL_HI16: case R_MIPS_TLS_TPREL_HI16: - writeRelocation<E, 16, 16>(Loc, Val + 0x8000); + writeRelocation<E>(Loc, Val + 0x8000, 16, 16); break; case R_MIPS_HIGHER: - writeRelocation<E, 16, 32>(Loc, Val + 0x80008000); + writeRelocation<E>(Loc, Val + 0x80008000, 16, 32); break; case R_MIPS_HIGHEST: - writeRelocation<E, 16, 48>(Loc, Val + 0x800080008000); + writeRelocation<E>(Loc, Val + 0x800080008000, 16, 48); break; case R_MIPS_JALR: // Ignore this optimization relocation for now @@ -363,25 +364,25 @@ void MIPS<ELFT>::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const { case R_MIPS_PC16: checkAlignment<4>(Loc, Val, Type); checkInt<18>(Loc, Val, Type); - writeRelocation<E, 16, 2>(Loc, Val); + writeRelocation<E>(Loc, Val, 16, 2); break; case R_MIPS_PC19_S2: checkAlignment<4>(Loc, Val, Type); checkInt<21>(Loc, Val, Type); - writeRelocation<E, 19, 2>(Loc, Val); + writeRelocation<E>(Loc, Val, 19, 2); break; case R_MIPS_PC21_S2: checkAlignment<4>(Loc, Val, Type); checkInt<23>(Loc, Val, Type); - writeRelocation<E, 21, 2>(Loc, Val); + writeRelocation<E>(Loc, Val, 21, 2); break; case R_MIPS_PC26_S2: checkAlignment<4>(Loc, Val, Type); checkInt<28>(Loc, Val, Type); - writeRelocation<E, 26, 2>(Loc, Val); + writeRelocation<E>(Loc, Val, 26, 2); break; case R_MIPS_PC32: - writeRelocation<E, 32, 0>(Loc, Val); + writeRelocation<E>(Loc, Val, 32, 0); break; default: error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); |

