//===- lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h ------------===// // // The LLVM Linker // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "MachONormalizedFile.h" #include "lld/Core/Error.h" #include "lld/Core/LLVM.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Endian.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Host.h" #include "llvm/Support/MachO.h" #include #ifndef LLD_READER_WRITER_MACHO_NORMALIZED_FILE_BINARY_UTILS_H #define LLD_READER_WRITER_MACHO_NORMALIZED_FILE_BINARY_UTILS_H namespace lld { namespace mach_o { namespace normalized { using llvm::sys::getSwappedBytes; using llvm::support::ubig16_t; using llvm::support::ubig32_t; using llvm::support::ubig64_t; using llvm::support::ulittle16_t; using llvm::support::ulittle32_t; using llvm::support::ulittle64_t; template static inline uint16_t read16(const T *loc, bool isBig) { assert((uint64_t)loc % llvm::alignOf() == 0 && "invalid pointer alignment"); if (isBig) return *(const ubig16_t *)loc; return *(const ulittle16_t *)loc; } template static inline uint32_t read32(const T *loc, bool isBig) { assert((uint64_t)loc % llvm::alignOf() == 0 && "invalid pointer alignment"); if (isBig) return *(const ubig32_t *)loc; return *(const ulittle32_t *)loc; } template static inline uint64_t read64(const T *loc, bool isBig) { assert((uint64_t)loc % llvm::alignOf() == 0 && "invalid pointer alignment"); if (isBig) return *(const ubig64_t *)loc; return *(const ulittle64_t *)loc; } inline void write16(uint8_t *loc, uint16_t value, bool isBig) { if (isBig) *(ubig16_t *)loc = value; else *(ulittle16_t *)loc = value; } inline void write32(uint8_t *loc, uint32_t value, bool isBig) { if (isBig) *(ubig32_t *)loc = value; else *(ulittle32_t *)loc = value; } inline void write64(uint8_t *loc, uint64_t value, bool isBig) { if (isBig) *(ubig64_t *)loc = value; else *(ulittle64_t *)loc = value; } inline uint32_t bitFieldExtract(uint32_t value, bool isBigEndianBigField, uint8_t firstBit, uint8_t bitCount) { const uint32_t mask = ((1<> shift) & mask; } inline void bitFieldSet(uint32_t &bits, bool isBigEndianBigField, uint32_t newBits, uint8_t firstBit, uint8_t bitCount) { const uint32_t mask = ((1< 16 ) return x.substr(0, 16); else return x; } inline void setString16(StringRef str, char s[16]) { memset(s, 0, 16); memcpy(s, str.begin(), (str.size() > 16) ? 16: str.size()); } // Implemented in normalizedToAtoms() and used by normalizedFromAtoms() so // that the same table can be used to map mach-o sections to and from // DefinedAtom::ContentType. void relocatableSectionInfoForContentType(DefinedAtom::ContentType atomType, StringRef &segmentName, StringRef §ionName, SectionType §ionType, SectionAttr §ionAttrs); } // namespace normalized } // namespace mach_o } // namespace lld #endif // LLD_READER_WRITER_MACHO_NORMALIZED_FILE_BINARY_UTILS_H