Move bit operations to a new file, ELF/Bits.h.

llvm-svn: 316707
This commit is contained in:
Rui Ueyama 2017-10-26 21:37:17 +00:00
parent 1f13b3c243
commit 6e5fda9db8
2 changed files with 36 additions and 13 deletions

35
lld/ELF/Bits.h Normal file
View File

@ -0,0 +1,35 @@
//===- Bits.h ---------------------------------------------------*- C++ -*-===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_ELF_BITS_H
#define LLD_ELF_BITS_H
#include "Config.h"
#include "llvm/Support/Endian.h"
namespace lld {
namespace elf {
inline uint64_t readUint(uint8_t *Buf) {
if (Config->Is64)
return llvm::support::endian::read64(Buf, Config->Endianness);
return llvm::support::endian::read32(Buf, Config->Endianness);
}
inline void writeUint(uint8_t *Buf, uint64_t Val) {
if (Config->Is64)
llvm::support::endian::write64(Buf, Val, Config->Endianness);
else
llvm::support::endian::write32(Buf, Val, Config->Endianness);
}
} // namespace elf
} // namespace lld
#endif

View File

@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===//
#include "SyntheticSections.h"
#include "Bits.h"
#include "Config.h"
#include "InputFiles.h"
#include "LinkerScript.h"
@ -854,19 +855,6 @@ bool MipsGotSection::empty() const {
uint64_t MipsGotSection::getGp() const { return ElfSym::MipsGp->getVA(0); }
static uint64_t readUint(uint8_t *Buf) {
if (Config->Is64)
return read64(Buf, Config->Endianness);
return read32(Buf, Config->Endianness);
}
static void writeUint(uint8_t *Buf, uint64_t Val) {
if (Config->Is64)
write64(Buf, Val, Config->Endianness);
else
write32(Buf, Val, Config->Endianness);
}
void MipsGotSection::writeTo(uint8_t *Buf) {
// Set the MSB of the second GOT slot. This is not required by any
// MIPS ABI documentation, though.