diff options
Diffstat (limited to 'include/llvm/Object')
-rw-r--r-- | include/llvm/Object/ELF.h | 68 | ||||
-rw-r--r-- | include/llvm/Object/ELFObjectFile.h | 32 | ||||
-rw-r--r-- | include/llvm/Object/ELFTypes.h | 166 | ||||
-rw-r--r-- | include/llvm/Object/IRSymtab.h | 29 | ||||
-rw-r--r-- | include/llvm/Object/MachO.h | 122 | ||||
-rw-r--r-- | include/llvm/Object/ModuleSummaryIndexObjectFile.h | 25 | ||||
-rw-r--r-- | include/llvm/Object/ModuleSymbolTable.h | 16 | ||||
-rw-r--r-- | include/llvm/Object/RelocVisitor.h | 91 | ||||
-rw-r--r-- | include/llvm/Object/StackMapParser.h | 43 | ||||
-rw-r--r-- | include/llvm/Object/Wasm.h | 13 |
10 files changed, 339 insertions, 266 deletions
diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 7a3155b3953ec..9c72bd4023d8b 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -14,9 +14,19 @@ #ifndef LLVM_OBJECT_ELF_H #define LLVM_OBJECT_ELF_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Object/ELFTypes.h" -#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Object/Error.h" +#include "llvm/Support/ELF.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include <cassert> +#include <cstddef> +#include <cstdint> +#include <limits> +#include <utility> namespace llvm { namespace object { @@ -41,27 +51,27 @@ template <class ELFT> class ELFFile { public: LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) - typedef typename ELFT::uint uintX_t; - typedef typename ELFT::Ehdr Elf_Ehdr; - typedef typename ELFT::Shdr Elf_Shdr; - typedef typename ELFT::Sym Elf_Sym; - typedef typename ELFT::Dyn Elf_Dyn; - typedef typename ELFT::Phdr Elf_Phdr; - typedef typename ELFT::Rel Elf_Rel; - typedef typename ELFT::Rela Elf_Rela; - typedef typename ELFT::Verdef Elf_Verdef; - typedef typename ELFT::Verdaux Elf_Verdaux; - typedef typename ELFT::Verneed Elf_Verneed; - typedef typename ELFT::Vernaux Elf_Vernaux; - typedef typename ELFT::Versym Elf_Versym; - typedef typename ELFT::Hash Elf_Hash; - typedef typename ELFT::GnuHash Elf_GnuHash; - typedef typename ELFT::DynRange Elf_Dyn_Range; - typedef typename ELFT::ShdrRange Elf_Shdr_Range; - typedef typename ELFT::SymRange Elf_Sym_Range; - typedef typename ELFT::RelRange Elf_Rel_Range; - typedef typename ELFT::RelaRange Elf_Rela_Range; - typedef typename ELFT::PhdrRange Elf_Phdr_Range; + using uintX_t = typename ELFT::uint; + using Elf_Ehdr = typename ELFT::Ehdr; + using Elf_Shdr = typename ELFT::Shdr; + using Elf_Sym = typename ELFT::Sym; + using Elf_Dyn = typename ELFT::Dyn; + using Elf_Phdr = typename ELFT::Phdr; + using Elf_Rel = typename ELFT::Rel; + using Elf_Rela = typename ELFT::Rela; + using Elf_Verdef = typename ELFT::Verdef; + using Elf_Verdaux = typename ELFT::Verdaux; + using Elf_Verneed = typename ELFT::Verneed; + using Elf_Vernaux = typename ELFT::Vernaux; + using Elf_Versym = typename ELFT::Versym; + using Elf_Hash = typename ELFT::Hash; + using Elf_GnuHash = typename ELFT::GnuHash; + using Elf_Dyn_Range = typename ELFT::DynRange; + using Elf_Shdr_Range = typename ELFT::ShdrRange; + using Elf_Sym_Range = typename ELFT::SymRange; + using Elf_Rel_Range = typename ELFT::RelRange; + using Elf_Rela_Range = typename ELFT::RelaRange; + using Elf_Phdr_Range = typename ELFT::PhdrRange; const uint8_t *base() const { return reinterpret_cast<const uint8_t *>(Buf.data()); @@ -70,7 +80,6 @@ public: size_t getBufSize() const { return Buf.size(); } private: - StringRef Buf; public: @@ -161,10 +170,10 @@ public: Expected<ArrayRef<uint8_t>> getSectionContents(const Elf_Shdr *Sec) const; }; -typedef ELFFile<ELFType<support::little, false>> ELF32LEFile; -typedef ELFFile<ELFType<support::little, true>> ELF64LEFile; -typedef ELFFile<ELFType<support::big, false>> ELF32BEFile; -typedef ELFFile<ELFType<support::big, true>> ELF64BEFile; +using ELF32LEFile = ELFFile<ELFType<support::little, false>>; +using ELF64LEFile = ELFFile<ELFType<support::little, true>>; +using ELF32BEFile = ELFFile<ELFType<support::big, false>>; +using ELF64BEFile = ELFFile<ELFType<support::big, true>>; template <class ELFT> inline Expected<const typename ELFT::Shdr *> @@ -194,7 +203,7 @@ ELFFile<ELFT>::getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms, ArrayRef<Elf_Word> ShndxTable) const { uint32_t Index = Sym->st_shndx; if (Index == ELF::SHN_XINDEX) { - auto ErrorOrIndex = object::getExtendedSymbolTableIndex<ELFT>( + auto ErrorOrIndex = getExtendedSymbolTableIndex<ELFT>( Sym, Syms.begin(), ShndxTable); if (!ErrorOrIndex) return ErrorOrIndex.takeError(); @@ -519,7 +528,8 @@ inline unsigned hashSysV(StringRef SymbolName) { } return h; } + } // end namespace object } // end namespace llvm -#endif +#endif // LLVM_OBJECT_ELF_H diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 9e95f2958aa4f..d8b58b8079fa0 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -27,6 +27,7 @@ #include "llvm/Object/ObjectFile.h" #include "llvm/Object/SymbolicFile.h" #include "llvm/Support/ARMAttributeParser.h" +#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ELF.h" #include "llvm/Support/Endian.h" @@ -42,13 +43,11 @@ namespace llvm { namespace object { class elf_symbol_iterator; -class ELFSymbolRef; -class ELFRelocationRef; class ELFObjectFileBase : public ObjectFile { - friend class ELFSymbolRef; - friend class ELFSectionRef; friend class ELFRelocationRef; + friend class ELFSectionRef; + friend class ELFSymbolRef; protected: ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source); @@ -65,7 +64,8 @@ protected: virtual ErrorOr<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0; public: - typedef iterator_range<elf_symbol_iterator> elf_symbol_iterator_range; + using elf_symbol_iterator_range = iterator_range<elf_symbol_iterator>; + virtual elf_symbol_iterator_range getDynamicSymbolIterators() const = 0; elf_symbol_iterator_range symbols() const; @@ -201,14 +201,14 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase { public: LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) - typedef typename ELFFile<ELFT>::uintX_t uintX_t; + using uintX_t = typename ELFFile<ELFT>::uintX_t; - typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym; - typedef typename ELFFile<ELFT>::Elf_Shdr Elf_Shdr; - typedef typename ELFFile<ELFT>::Elf_Ehdr Elf_Ehdr; - typedef typename ELFFile<ELFT>::Elf_Rel Elf_Rel; - typedef typename ELFFile<ELFT>::Elf_Rela Elf_Rela; - typedef typename ELFFile<ELFT>::Elf_Dyn Elf_Dyn; + using Elf_Sym = typename ELFFile<ELFT>::Elf_Sym; + using Elf_Shdr = typename ELFFile<ELFT>::Elf_Shdr; + using Elf_Ehdr = typename ELFFile<ELFT>::Elf_Ehdr; + using Elf_Rel = typename ELFFile<ELFT>::Elf_Rel; + using Elf_Rela = typename ELFFile<ELFT>::Elf_Rela; + using Elf_Dyn = typename ELFFile<ELFT>::Elf_Dyn; protected: ELFFile<ELFT> EF; @@ -398,10 +398,10 @@ public: bool isRelocatableObject() const override; }; -typedef ELFObjectFile<ELFType<support::little, false>> ELF32LEObjectFile; -typedef ELFObjectFile<ELFType<support::little, true>> ELF64LEObjectFile; -typedef ELFObjectFile<ELFType<support::big, false>> ELF32BEObjectFile; -typedef ELFObjectFile<ELFType<support::big, true>> ELF64BEObjectFile; +using ELF32LEObjectFile = ELFObjectFile<ELFType<support::little, false>>; +using ELF64LEObjectFile = ELFObjectFile<ELFType<support::little, true>>; +using ELF32BEObjectFile = ELFObjectFile<ELFType<support::big, false>>; +using ELF64BEObjectFile = ELFObjectFile<ELFType<support::big, true>>; template <class ELFT> void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const { diff --git a/include/llvm/Object/ELFTypes.h b/include/llvm/Object/ELFTypes.h index 3e03fd8b980e7..99346fe1a882c 100644 --- a/include/llvm/Object/ELFTypes.h +++ b/include/llvm/Object/ELFTypes.h @@ -11,10 +11,15 @@ #define LLVM_OBJECT_ELFTYPES_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Object/Error.h" #include "llvm/Support/ELF.h" #include "llvm/Support/Endian.h" -#include "llvm/Support/ErrorOr.h" +#include "llvm/Support/Error.h" +#include <cassert> +#include <cstdint> +#include <cstring> +#include <type_traits> namespace llvm { namespace object { @@ -45,58 +50,58 @@ public: static const endianness TargetEndianness = E; static const bool Is64Bits = Is64; - typedef typename std::conditional<Is64, uint64_t, uint32_t>::type uint; - typedef Elf_Ehdr_Impl<ELFType<E, Is64>> Ehdr; - typedef Elf_Shdr_Impl<ELFType<E, Is64>> Shdr; - typedef Elf_Sym_Impl<ELFType<E, Is64>> Sym; - typedef Elf_Dyn_Impl<ELFType<E, Is64>> Dyn; - typedef Elf_Phdr_Impl<ELFType<E, Is64>> Phdr; - typedef Elf_Rel_Impl<ELFType<E, Is64>, false> Rel; - typedef Elf_Rel_Impl<ELFType<E, Is64>, true> Rela; - typedef Elf_Verdef_Impl<ELFType<E, Is64>> Verdef; - typedef Elf_Verdaux_Impl<ELFType<E, Is64>> Verdaux; - typedef Elf_Verneed_Impl<ELFType<E, Is64>> Verneed; - typedef Elf_Vernaux_Impl<ELFType<E, Is64>> Vernaux; - typedef Elf_Versym_Impl<ELFType<E, Is64>> Versym; - typedef Elf_Hash_Impl<ELFType<E, Is64>> Hash; - typedef Elf_GnuHash_Impl<ELFType<E, Is64>> GnuHash; - typedef Elf_Chdr_Impl<ELFType<E, Is64>> Chdr; - typedef ArrayRef<Dyn> DynRange; - typedef ArrayRef<Shdr> ShdrRange; - typedef ArrayRef<Sym> SymRange; - typedef ArrayRef<Rel> RelRange; - typedef ArrayRef<Rela> RelaRange; - typedef ArrayRef<Phdr> PhdrRange; - - typedef packed<uint16_t> Half; - typedef packed<uint32_t> Word; - typedef packed<int32_t> Sword; - typedef packed<uint64_t> Xword; - typedef packed<int64_t> Sxword; - typedef packed<uint> Addr; - typedef packed<uint> Off; -}; - -typedef ELFType<support::little, false> ELF32LE; -typedef ELFType<support::big, false> ELF32BE; -typedef ELFType<support::little, true> ELF64LE; -typedef ELFType<support::big, true> ELF64BE; + using uint = typename std::conditional<Is64, uint64_t, uint32_t>::type; + using Ehdr = Elf_Ehdr_Impl<ELFType<E, Is64>>; + using Shdr = Elf_Shdr_Impl<ELFType<E, Is64>>; + using Sym = Elf_Sym_Impl<ELFType<E, Is64>>; + using Dyn = Elf_Dyn_Impl<ELFType<E, Is64>>; + using Phdr = Elf_Phdr_Impl<ELFType<E, Is64>>; + using Rel = Elf_Rel_Impl<ELFType<E, Is64>, false>; + using Rela = Elf_Rel_Impl<ELFType<E, Is64>, true>; + using Verdef = Elf_Verdef_Impl<ELFType<E, Is64>>; + using Verdaux = Elf_Verdaux_Impl<ELFType<E, Is64>>; + using Verneed = Elf_Verneed_Impl<ELFType<E, Is64>>; + using Vernaux = Elf_Vernaux_Impl<ELFType<E, Is64>>; + using Versym = Elf_Versym_Impl<ELFType<E, Is64>>; + using Hash = Elf_Hash_Impl<ELFType<E, Is64>>; + using GnuHash = Elf_GnuHash_Impl<ELFType<E, Is64>>; + using Chdr = Elf_Chdr_Impl<ELFType<E, Is64>>; + using DynRange = ArrayRef<Dyn>; + using ShdrRange = ArrayRef<Shdr>; + using SymRange = ArrayRef<Sym>; + using RelRange = ArrayRef<Rel>; + using RelaRange = ArrayRef<Rela>; + using PhdrRange = ArrayRef<Phdr>; + + using Half = packed<uint16_t>; + using Word = packed<uint32_t>; + using Sword = packed<int32_t>; + using Xword = packed<uint64_t>; + using Sxword = packed<int64_t>; + using Addr = packed<uint>; + using Off = packed<uint>; +}; + +using ELF32LE = ELFType<support::little, false>; +using ELF32BE = ELFType<support::big, false>; +using ELF64LE = ELFType<support::little, true>; +using ELF64BE = ELFType<support::big, true>; // Use an alignment of 2 for the typedefs since that is the worst case for // ELF files in archives. // Templates to choose Elf_Addr and Elf_Off depending on is64Bits. template <endianness target_endianness> struct ELFDataTypeTypedefHelperCommon { - typedef support::detail::packed_endian_specific_integral< - uint16_t, target_endianness, 2> Elf_Half; - typedef support::detail::packed_endian_specific_integral< - uint32_t, target_endianness, 2> Elf_Word; - typedef support::detail::packed_endian_specific_integral< - int32_t, target_endianness, 2> Elf_Sword; - typedef support::detail::packed_endian_specific_integral< - uint64_t, target_endianness, 2> Elf_Xword; - typedef support::detail::packed_endian_specific_integral< - int64_t, target_endianness, 2> Elf_Sxword; + using Elf_Half = support::detail::packed_endian_specific_integral< + uint16_t, target_endianness, 2>; + using Elf_Word = support::detail::packed_endian_specific_integral< + uint32_t, target_endianness, 2>; + using Elf_Sword = support::detail::packed_endian_specific_integral< + int32_t, target_endianness, 2>; + using Elf_Xword = support::detail::packed_endian_specific_integral< + uint64_t, target_endianness, 2>; + using Elf_Sxword = support::detail::packed_endian_specific_integral< + int64_t, target_endianness, 2>; }; template <class ELFT> struct ELFDataTypeTypedefHelper; @@ -105,34 +110,34 @@ template <class ELFT> struct ELFDataTypeTypedefHelper; template <endianness TargetEndianness> struct ELFDataTypeTypedefHelper<ELFType<TargetEndianness, false>> : ELFDataTypeTypedefHelperCommon<TargetEndianness> { - typedef uint32_t value_type; - typedef support::detail::packed_endian_specific_integral< - value_type, TargetEndianness, 2> Elf_Addr; - typedef support::detail::packed_endian_specific_integral< - value_type, TargetEndianness, 2> Elf_Off; + using value_type = uint32_t; + using Elf_Addr = support::detail::packed_endian_specific_integral< + value_type, TargetEndianness, 2>; + using Elf_Off = support::detail::packed_endian_specific_integral< + value_type, TargetEndianness, 2>; }; /// ELF 64bit types. template <endianness TargetEndianness> struct ELFDataTypeTypedefHelper<ELFType<TargetEndianness, true>> : ELFDataTypeTypedefHelperCommon<TargetEndianness> { - typedef uint64_t value_type; - typedef support::detail::packed_endian_specific_integral< - value_type, TargetEndianness, 2> Elf_Addr; - typedef support::detail::packed_endian_specific_integral< - value_type, TargetEndianness, 2> Elf_Off; + using value_type = uint64_t; + using Elf_Addr = support::detail::packed_endian_specific_integral< + value_type, TargetEndianness, 2>; + using Elf_Off = support::detail::packed_endian_specific_integral< + value_type, TargetEndianness, 2>; }; // I really don't like doing this, but the alternative is copypasta. #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \ - typedef typename ELFT::Addr Elf_Addr; \ - typedef typename ELFT::Off Elf_Off; \ - typedef typename ELFT::Half Elf_Half; \ - typedef typename ELFT::Word Elf_Word; \ - typedef typename ELFT::Sword Elf_Sword; \ - typedef typename ELFT::Xword Elf_Xword; \ - typedef typename ELFT::Sxword Elf_Sxword; + using Elf_Addr = typename ELFT::Addr; \ + using Elf_Off = typename ELFT::Off; \ + using Elf_Half = typename ELFT::Half; \ + using Elf_Word = typename ELFT::Word; \ + using Elf_Sword = typename ELFT::Sword; \ + using Elf_Xword = typename ELFT::Xword; \ + using Elf_Sxword = typename ELFT::Sxword; #define LLD_ELF_COMMA , #define LLVM_ELF_IMPORT_TYPES(E, W) \ @@ -222,6 +227,7 @@ struct Elf_Sym_Impl : Elf_Sym_Base<ELFT> { uint64_t getValue() const { return st_value; } void setBinding(unsigned char b) { setBindingAndType(b, getType()); } void setType(unsigned char t) { setBindingAndType(getBinding(), t); } + void setBindingAndType(unsigned char b, unsigned char t) { st_info = (b << 4) + (t & 0x0f); } @@ -238,22 +244,29 @@ struct Elf_Sym_Impl : Elf_Sym_Base<ELFT> { } bool isAbsolute() const { return st_shndx == ELF::SHN_ABS; } + bool isCommon() const { return getType() == ELF::STT_COMMON || st_shndx == ELF::SHN_COMMON; } + bool isDefined() const { return !isUndefined(); } + bool isProcessorSpecific() const { return st_shndx >= ELF::SHN_LOPROC && st_shndx <= ELF::SHN_HIPROC; } + bool isOSSpecific() const { return st_shndx >= ELF::SHN_LOOS && st_shndx <= ELF::SHN_HIOS; } + bool isReserved() const { // ELF::SHN_HIRESERVE is 0xffff so st_shndx <= ELF::SHN_HIRESERVE is always // true and some compilers warn about it. return st_shndx >= ELF::SHN_LORESERVE; } + bool isUndefined() const { return st_shndx == ELF::SHN_UNDEF; } + bool isExternal() const { return getBinding() != ELF::STB_LOCAL; } @@ -277,14 +290,12 @@ struct Elf_Versym_Impl { Elf_Half vs_index; // Version index with flags (e.g. VERSYM_HIDDEN) }; -template <class ELFT> struct Elf_Verdaux_Impl; - /// Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section /// (.gnu.version_d). This structure is identical for ELF32 and ELF64. template <class ELFT> struct Elf_Verdef_Impl { LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) - typedef Elf_Verdaux_Impl<ELFT> Elf_Verdaux; + using Elf_Verdaux = Elf_Verdaux_Impl<ELFT>; Elf_Half vd_version; // Version of this structure (e.g. VER_DEF_CURRENT) Elf_Half vd_flags; // Bitwise flags (VER_DEF_*) Elf_Half vd_ndx; // Version index, used in .gnu.version entries @@ -361,10 +372,10 @@ template <class ELFT> struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> { using Elf_Dyn_Base<ELFT>::d_tag; using Elf_Dyn_Base<ELFT>::d_un; - typedef typename std::conditional<ELFT::Is64Bits, - int64_t, int32_t>::type intX_t; - typedef typename std::conditional<ELFT::Is64Bits, - uint64_t, uint32_t>::type uintX_t; + using intX_t = typename std::conditional<ELFT::Is64Bits, + int64_t, int32_t>::type; + using uintX_t = typename std::conditional<ELFT::Is64Bits, + uint64_t, uint32_t>::type; intX_t getTag() const { return d_tag; } uintX_t getVal() const { return d_un.d_val; } uintX_t getPtr() const { return d_un.d_ptr; } @@ -430,6 +441,7 @@ struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> { return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) | ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff); } + void setRInfo(uint64_t R, bool IsMips64EL) { if (IsMips64EL) r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) | @@ -483,15 +495,15 @@ struct Elf_Ehdr_Impl { Elf_Half e_shnum; // Number of entries in the section header table Elf_Half e_shstrndx; // Section header table index of section name // string table + bool checkMagic() const { return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0; } + unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; } unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; } }; -template <class ELFT> struct Elf_Phdr_Impl; - template <endianness TargetEndianness> struct Elf_Phdr_Impl<ELFType<TargetEndianness, false>> { LLVM_ELF_IMPORT_TYPES(TargetEndianness, false) @@ -582,7 +594,7 @@ struct Elf_Chdr_Impl<ELFType<TargetEndianness, true>> { template <class ELFT> struct Elf_Mips_RegInfo; -template <llvm::support::endianness TargetEndianness> +template <support::endianness TargetEndianness> struct Elf_Mips_RegInfo<ELFType<TargetEndianness, false>> { LLVM_ELF_IMPORT_TYPES(TargetEndianness, false) Elf_Word ri_gprmask; // bit-mask of used general registers @@ -590,7 +602,7 @@ struct Elf_Mips_RegInfo<ELFType<TargetEndianness, false>> { Elf_Addr ri_gp_value; // gp register value }; -template <llvm::support::endianness TargetEndianness> +template <support::endianness TargetEndianness> struct Elf_Mips_RegInfo<ELFType<TargetEndianness, true>> { LLVM_ELF_IMPORT_TYPES(TargetEndianness, true) Elf_Word ri_gprmask; // bit-mask of used general registers @@ -609,7 +621,7 @@ template <class ELFT> struct Elf_Mips_Options { Elf_Word info; // Kind-specific information Elf_Mips_RegInfo<ELFT> &getRegInfo() { - assert(kind == llvm::ELF::ODK_REGINFO); + assert(kind == ELF::ODK_REGINFO); return *reinterpret_cast<Elf_Mips_RegInfo<ELFT> *>( (uint8_t *)this + sizeof(Elf_Mips_Options)); } @@ -637,4 +649,4 @@ template <class ELFT> struct Elf_Mips_ABIFlags { } // end namespace object. } // end namespace llvm. -#endif +#endif // LLVM_OBJECT_ELFTYPES_H diff --git a/include/llvm/Object/IRSymtab.h b/include/llvm/Object/IRSymtab.h index be0f02aa7f171..b425543bf637d 100644 --- a/include/llvm/Object/IRSymtab.h +++ b/include/llvm/Object/IRSymtab.h @@ -25,23 +25,31 @@ #define LLVM_OBJECT_IRSYMTAB_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/ADT/StringRef.h" #include "llvm/IR/GlobalValue.h" #include "llvm/Object/SymbolicFile.h" #include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include <cassert> +#include <cstdint> +#include <vector> namespace llvm { namespace irsymtab { + namespace storage { // The data structures in this namespace define the low-level serialization // format. Clients that just want to read a symbol table should use the // irsymtab::Reader class. -typedef support::ulittle32_t Word; +using Word = support::ulittle32_t; /// A reference to a string in the string table. struct Str { Word Offset, Size; + StringRef get(StringRef Strtab) const { return {Strtab.data() + Offset, Size}; } @@ -50,6 +58,7 @@ struct Str { /// A reference to a range of objects in the symbol table. template <typename T> struct Range { Word Offset, Size; + ArrayRef<T> get(StringRef Symtab) const { return {reinterpret_cast<const T *>(Symtab.data() + Offset), Size}; } @@ -122,7 +131,7 @@ struct Header { Str COFFLinkerOpts; }; -} +} // end namespace storage /// Fills in Symtab and Strtab with a valid symbol and string table for Mods. Error build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab, @@ -152,18 +161,22 @@ struct Symbol { int getComdatIndex() const { return ComdatIndex; } using S = storage::Symbol; + GlobalValue::VisibilityTypes getVisibility() const { return GlobalValue::VisibilityTypes((Flags >> S::FB_visibility) & 3); } + bool isUndefined() const { return (Flags >> S::FB_undefined) & 1; } bool isWeak() const { return (Flags >> S::FB_weak) & 1; } bool isCommon() const { return (Flags >> S::FB_common) & 1; } bool isIndirect() const { return (Flags >> S::FB_indirect) & 1; } bool isUsed() const { return (Flags >> S::FB_used) & 1; } bool isTLS() const { return (Flags >> S::FB_tls) & 1; } + bool canBeOmittedFromSymbolTable() const { return (Flags >> S::FB_may_omit) & 1; } + bool isGlobal() const { return (Flags >> S::FB_global) & 1; } bool isFormatSpecific() const { return (Flags >> S::FB_format_specific) & 1; } bool isUnnamedAddr() const { return (Flags >> S::FB_unnamed_addr) & 1; } @@ -173,6 +186,7 @@ struct Symbol { assert(isCommon()); return CommonSize; } + uint32_t getCommonAlignment() const { assert(isCommon()); return CommonAlign; @@ -197,9 +211,11 @@ class Reader { ArrayRef<storage::Uncommon> Uncommons; StringRef str(storage::Str S) const { return S.get(Strtab); } + template <typename T> ArrayRef<T> range(storage::Range<T> R) const { return R.get(Symtab); } + const storage::Header &header() const { return *reinterpret_cast<const storage::Header *>(Symtab.data()); } @@ -215,7 +231,7 @@ public: Uncommons = range(header().Uncommons); } - typedef iterator_range<object::content_iterator<SymbolRef>> symbol_range; + using symbol_range = iterator_range<object::content_iterator<SymbolRef>>; /// Returns the symbol table for the entire bitcode file. /// The symbols enumerated by this method are ephemeral, but they can be @@ -298,8 +314,7 @@ inline Reader::symbol_range Reader::module_symbols(unsigned I) const { SymbolRef(MEnd, MEnd, nullptr, this)}; } -} - -} +} // end namespace irsymtab +} // end namespace llvm -#endif +#endif // LLVM_OBJECT_IRSYMTAB_H diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 1ee571cce738e..29553558f72f5 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -16,10 +16,25 @@ #define LLVM_OBJECT_MACHO_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" +#include "llvm/MC/SubtargetFeature.h" +#include "llvm/Object/Binary.h" #include "llvm/Object/ObjectFile.h" +#include "llvm/Object/SymbolicFile.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/Format.h" #include "llvm/Support/MachO.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/raw_ostream.h" +#include <cstdint> +#include <memory> +#include <string> +#include <system_error> namespace llvm { namespace object { @@ -28,11 +43,10 @@ namespace object { /// data in code entry in the table in a Mach-O object file. class DiceRef { DataRefImpl DicePimpl; - const ObjectFile *OwningObject; + const ObjectFile *OwningObject = nullptr; public: - DiceRef() : OwningObject(nullptr) { } - + DiceRef() = default; DiceRef(DataRefImpl DiceP, const ObjectFile *Owner); bool operator==(const DiceRef &Other) const; @@ -47,7 +61,7 @@ public: DataRefImpl getRawDataRefImpl() const; const ObjectFile *getObjectFile() const; }; -typedef content_iterator<DiceRef> dice_iterator; +using dice_iterator = content_iterator<DiceRef>; /// ExportEntry encapsulates the current-state-of-the-walk used when doing a /// non-recursive walk of the trie data structure. This allows you to iterate @@ -71,6 +85,7 @@ public: private: friend class MachOObjectFile; + void moveToFirst(); void moveToEnd(); uint64_t readULEB128(const uint8_t *&p); @@ -80,25 +95,26 @@ private: // Represents a node in the mach-o exports trie. struct NodeState { NodeState(const uint8_t *Ptr); + const uint8_t *Start; const uint8_t *Current; - uint64_t Flags; - uint64_t Address; - uint64_t Other; - const char *ImportName; - unsigned ChildCount; - unsigned NextChildIndex; - unsigned ParentStringLength; - bool IsExportNode; + uint64_t Flags = 0; + uint64_t Address = 0; + uint64_t Other = 0; + const char *ImportName = nullptr; + unsigned ChildCount = 0; + unsigned NextChildIndex = 0; + unsigned ParentStringLength = 0; + bool IsExportNode = false; }; ArrayRef<uint8_t> Trie; SmallString<256> CumulativeString; SmallVector<NodeState, 16> Stack; - bool Malformed; - bool Done; + bool Malformed = false; + bool Done = false; }; -typedef content_iterator<ExportEntry> export_iterator; +using export_iterator = content_iterator<ExportEntry>; // Segment info so SegIndex/SegOffset pairs in a Mach-O Bind or Rebase entry // can be checked and translated. Only the SegIndex/SegOffset pairs from @@ -106,7 +122,7 @@ typedef content_iterator<ExportEntry> export_iterator; // address() methods below. class BindRebaseSegInfo { public: - BindRebaseSegInfo(const object::MachOObjectFile *Obj); + BindRebaseSegInfo(const MachOObjectFile *Obj); // Used to check a Mach-O Bind or Rebase entry for errors when iterating. const char *checkSegAndOffset(int32_t SegIndex, uint64_t SegOffset, @@ -130,6 +146,7 @@ private: int32_t SegmentIndex; }; const SectionInfo &findSection(int32_t SegIndex, uint64_t SegOffset); + SmallVector<SectionInfo, 32> Sections; int32_t MaxSegIndex; }; @@ -159,6 +176,7 @@ public: private: friend class MachOObjectFile; + void moveToFirst(); void moveToEnd(); uint64_t readULEB128(const char **error); @@ -167,15 +185,15 @@ private: const MachOObjectFile *O; ArrayRef<uint8_t> Opcodes; const uint8_t *Ptr; - uint64_t SegmentOffset; - int32_t SegmentIndex; - uint64_t RemainingLoopCount; - uint64_t AdvanceAmount; - uint8_t RebaseType; + uint64_t SegmentOffset = 0; + int32_t SegmentIndex = -1; + uint64_t RemainingLoopCount = 0; + uint64_t AdvanceAmount = 0; + uint8_t RebaseType = 0; uint8_t PointerSize; - bool Done; + bool Done = false; }; -typedef content_iterator<MachORebaseEntry> rebase_iterator; +using rebase_iterator = content_iterator<MachORebaseEntry>; /// MachOBindEntry encapsulates the current state in the decompression of /// binding opcodes. This allows you to iterate through the compressed table of @@ -209,6 +227,7 @@ public: private: friend class MachOObjectFile; + void moveToFirst(); void moveToEnd(); uint64_t readULEB128(const char **error); @@ -218,21 +237,21 @@ private: const MachOObjectFile *O; ArrayRef<uint8_t> Opcodes; const uint8_t *Ptr; - uint64_t SegmentOffset; - int32_t SegmentIndex; + uint64_t SegmentOffset = 0; + int32_t SegmentIndex = -1; StringRef SymbolName; - bool LibraryOrdinalSet; - int Ordinal; - uint32_t Flags; - int64_t Addend; - uint64_t RemainingLoopCount; - uint64_t AdvanceAmount; - uint8_t BindType; + bool LibraryOrdinalSet = false; + int Ordinal = 0; + uint32_t Flags = 0; + int64_t Addend = 0; + uint64_t RemainingLoopCount = 0; + uint64_t AdvanceAmount = 0; + uint8_t BindType = 0; uint8_t PointerSize; Kind TableKind; - bool Done; + bool Done = false; }; -typedef content_iterator<MachOBindEntry> bind_iterator; +using bind_iterator = content_iterator<MachOBindEntry>; class MachOObjectFile : public ObjectFile { public: @@ -240,8 +259,8 @@ public: const char *Ptr; // Where in memory the load command is. MachO::load_command C; // The command itself. }; - typedef SmallVector<LoadCommandInfo, 4> LoadCommandList; - typedef LoadCommandList::const_iterator load_command_iterator; + using LoadCommandList = SmallVector<LoadCommandInfo, 4>; + using load_command_iterator = LoadCommandList::const_iterator; static Expected<std::unique_ptr<MachOObjectFile>> create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits, @@ -563,7 +582,7 @@ public: case MachO::PLATFORM_BRIDGEOS: return "bridgeos"; default: std::string ret; - llvm::raw_string_ostream ss(ret); + raw_string_ostream ss(ret); ss << format_hex(platform, 8, true); return ss.str(); } @@ -576,7 +595,7 @@ public: case MachO::TOOL_LD: return "ld"; default: std::string ret; - llvm::raw_string_ostream ss(ret); + raw_string_ostream ss(ret); ss << format_hex(tools, 8, true); return ss.str(); } @@ -595,7 +614,6 @@ public: } private: - MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits, Error &Err, uint32_t UniversalCputype = 0, uint32_t UniversalIndex = 0); @@ -606,23 +624,23 @@ private: MachO::mach_header_64 Header64; MachO::mach_header Header; }; - typedef SmallVector<const char*, 1> SectionList; + using SectionList = SmallVector<const char*, 1>; SectionList Sections; - typedef SmallVector<const char*, 1> LibraryList; + using LibraryList = SmallVector<const char*, 1>; LibraryList Libraries; LoadCommandList LoadCommands; - typedef SmallVector<StringRef, 1> LibraryShortName; + using LibraryShortName = SmallVector<StringRef, 1>; using BuildToolList = SmallVector<const char*, 1>; BuildToolList BuildTools; mutable LibraryShortName LibrariesShortNames; std::unique_ptr<BindRebaseSegInfo> BindRebaseSectionTable; - const char *SymtabLoadCmd; - const char *DysymtabLoadCmd; - const char *DataInCodeLoadCmd; - const char *LinkOptHintsLoadCmd; - const char *DyldInfoLoadCmd; - const char *UuidLoadCmd; - bool HasPageZeroSegment; + const char *SymtabLoadCmd = nullptr; + const char *DysymtabLoadCmd = nullptr; + const char *DataInCodeLoadCmd = nullptr; + const char *LinkOptHintsLoadCmd = nullptr; + const char *DyldInfoLoadCmd = nullptr; + const char *UuidLoadCmd = nullptr; + bool HasPageZeroSegment = false; }; /// DiceRef @@ -679,7 +697,7 @@ inline const ObjectFile *DiceRef::getObjectFile() const { return OwningObject; } -} -} +} // end namespace object +} // end namespace llvm -#endif +#endif // LLVM_OBJECT_MACHO_H diff --git a/include/llvm/Object/ModuleSummaryIndexObjectFile.h b/include/llvm/Object/ModuleSummaryIndexObjectFile.h index 713022264ea7a..f733f861e2c0c 100644 --- a/include/llvm/Object/ModuleSummaryIndexObjectFile.h +++ b/include/llvm/Object/ModuleSummaryIndexObjectFile.h @@ -1,4 +1,4 @@ -//===- ModuleSummaryIndexObjectFile.h - Summary index file implementation -=// +//===- ModuleSummaryIndexObjectFile.h - Summary index file implementation -===// // // The LLVM Compiler Infrastructure // @@ -14,14 +14,22 @@ #ifndef LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H #define LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H -#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Object/Binary.h" #include "llvm/Object/SymbolicFile.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ErrorOr.h" +#include "llvm/Support/MemoryBuffer.h" +#include <memory> +#include <system_error> namespace llvm { + class ModuleSummaryIndex; -class Module; namespace object { + class ObjectFile; /// This class is used to read just the module summary index related @@ -41,15 +49,18 @@ public: void moveSymbolNext(DataRefImpl &Symb) const override { llvm_unreachable("not implemented"); } + std::error_code printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override { llvm_unreachable("not implemented"); return std::error_code(); } + uint32_t getSymbolFlags(DataRefImpl Symb) const override { llvm_unreachable("not implemented"); return 0; } + basic_symbol_iterator symbol_begin() const override { llvm_unreachable("not implemented"); return basic_symbol_iterator(BasicSymbolRef()); @@ -85,7 +96,8 @@ public: static Expected<std::unique_ptr<ModuleSummaryIndexObjectFile>> create(MemoryBufferRef Object); }; -} + +} // end namespace object /// Parse the module summary index out of an IR file and return the module /// summary index object if found, or nullptr if not. If Identifier is @@ -94,6 +106,7 @@ public: /// containing minimized bitcode just for the thin link. Expected<std::unique_ptr<ModuleSummaryIndex>> getModuleSummaryIndexForFile(StringRef Path, StringRef Identifier = ""); -} -#endif +} // end namespace llvm + +#endif // LLVM_OBJECT_MODULESUMMARYINDEXOBJECTFILE_H diff --git a/include/llvm/Object/ModuleSymbolTable.h b/include/llvm/Object/ModuleSymbolTable.h index 333301d5b456c..9e93228853884 100644 --- a/include/llvm/Object/ModuleSymbolTable.h +++ b/include/llvm/Object/ModuleSymbolTable.h @@ -1,4 +1,4 @@ -//===- ModuleSymbolTable.h - symbol table for in-memory IR ----------------===// +//===- ModuleSymbolTable.h - symbol table for in-memory IR ------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -16,22 +16,24 @@ #ifndef LLVM_OBJECT_MODULESYMBOLTABLE_H #define LLVM_OBJECT_MODULESYMBOLTABLE_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/PointerUnion.h" -#include "llvm/ADT/Triple.h" #include "llvm/IR/Mangler.h" #include "llvm/Object/SymbolicFile.h" +#include "llvm/Support/Allocator.h" +#include <cstdint> #include <string> #include <utility> +#include <vector> namespace llvm { class GlobalValue; -class RecordStreamer; class ModuleSymbolTable { public: - typedef std::pair<std::string, uint32_t> AsmSymbol; - typedef PointerUnion<GlobalValue *, AsmSymbol *> Symbol; + using AsmSymbol = std::pair<std::string, uint32_t>; + using Symbol = PointerUnion<GlobalValue *, AsmSymbol *>; private: Module *FirstMod = nullptr; @@ -57,6 +59,6 @@ public: function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol); }; -} +} // end namespace llvm -#endif +#endif // LLVM_OBJECT_MODULESYMBOLTABLE_H diff --git a/include/llvm/Object/RelocVisitor.h b/include/llvm/Object/RelocVisitor.h index 3a0a62d9283b3..73c7ce367cb0c 100644 --- a/include/llvm/Object/RelocVisitor.h +++ b/include/llvm/Object/RelocVisitor.h @@ -1,4 +1,4 @@ -//===-- RelocVisitor.h - Visitor for object file relocations -*- C++ -*-===// +//===- RelocVisitor.h - Visitor for object file relocations -----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -16,34 +16,38 @@ #ifndef LLVM_OBJECT_RELOCVISITOR_H #define LLVM_OBJECT_RELOCVISITOR_H +#include "llvm/ADT/Triple.h" #include "llvm/Object/COFF.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" -#include "llvm/Support/Debug.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ELF.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ErrorOr.h" #include "llvm/Support/MachO.h" -#include "llvm/Support/raw_ostream.h" +#include <cstdint> +#include <system_error> namespace llvm { namespace object { struct RelocToApply { // The computed value after applying the relevant relocations. - int64_t Value; + int64_t Value = 0; // The width of the value; how many bytes to touch when applying the // relocation. - char Width; + char Width = 0; + + RelocToApply() = default; RelocToApply(int64_t Value, char Width) : Value(Value), Width(Width) {} - RelocToApply() : Value(0), Width(0) {} }; /// @brief Base class for object file relocation visitors. class RelocVisitor { public: - explicit RelocVisitor(const ObjectFile &Obj) - : ObjToVisit(Obj), HasError(false) {} + explicit RelocVisitor(const ObjectFile &Obj) : ObjToVisit(Obj) {} // TODO: Should handle multiple applied relocations via either passing in the // previously computed value or just count paired relocations as a single @@ -64,22 +68,22 @@ public: private: const ObjectFile &ObjToVisit; - bool HasError; + bool HasError = false; RelocToApply visitELF(uint32_t RelocType, RelocationRef R, uint64_t Value) { if (ObjToVisit.getBytesInAddress() == 8) { // 64-bit object file switch (ObjToVisit.getArch()) { case Triple::x86_64: switch (RelocType) { - case llvm::ELF::R_X86_64_NONE: + case ELF::R_X86_64_NONE: return visitELF_X86_64_NONE(R); - case llvm::ELF::R_X86_64_64: + case ELF::R_X86_64_64: return visitELF_X86_64_64(R, Value); - case llvm::ELF::R_X86_64_PC32: + case ELF::R_X86_64_PC32: return visitELF_X86_64_PC32(R, Value); - case llvm::ELF::R_X86_64_32: + case ELF::R_X86_64_32: return visitELF_X86_64_32(R, Value); - case llvm::ELF::R_X86_64_32S: + case ELF::R_X86_64_32S: return visitELF_X86_64_32S(R, Value); default: HasError = true; @@ -88,9 +92,9 @@ private: case Triple::aarch64: case Triple::aarch64_be: switch (RelocType) { - case llvm::ELF::R_AARCH64_ABS32: + case ELF::R_AARCH64_ABS32: return visitELF_AARCH64_ABS32(R, Value); - case llvm::ELF::R_AARCH64_ABS64: + case ELF::R_AARCH64_ABS64: return visitELF_AARCH64_ABS64(R, Value); default: HasError = true; @@ -99,9 +103,9 @@ private: case Triple::bpfel: case Triple::bpfeb: switch (RelocType) { - case llvm::ELF::R_BPF_64_64: + case ELF::R_BPF_64_64: return visitELF_BPF_64_64(R, Value); - case llvm::ELF::R_BPF_64_32: + case ELF::R_BPF_64_32: return visitELF_BPF_64_32(R, Value); default: HasError = true; @@ -110,9 +114,9 @@ private: case Triple::mips64el: case Triple::mips64: switch (RelocType) { - case llvm::ELF::R_MIPS_32: + case ELF::R_MIPS_32: return visitELF_MIPS64_32(R, Value); - case llvm::ELF::R_MIPS_64: + case ELF::R_MIPS_64: return visitELF_MIPS64_64(R, Value); default: HasError = true; @@ -121,9 +125,9 @@ private: case Triple::ppc64le: case Triple::ppc64: switch (RelocType) { - case llvm::ELF::R_PPC64_ADDR32: + case ELF::R_PPC64_ADDR32: return visitELF_PPC64_ADDR32(R, Value); - case llvm::ELF::R_PPC64_ADDR64: + case ELF::R_PPC64_ADDR64: return visitELF_PPC64_ADDR64(R, Value); default: HasError = true; @@ -131,9 +135,9 @@ private: } case Triple::systemz: switch (RelocType) { - case llvm::ELF::R_390_32: + case ELF::R_390_32: return visitELF_390_32(R, Value); - case llvm::ELF::R_390_64: + case ELF::R_390_64: return visitELF_390_64(R, Value); default: HasError = true; @@ -141,11 +145,11 @@ private: } case Triple::sparcv9: switch (RelocType) { - case llvm::ELF::R_SPARC_32: - case llvm::ELF::R_SPARC_UA32: + case ELF::R_SPARC_32: + case ELF::R_SPARC_UA32: return visitELF_SPARCV9_32(R, Value); - case llvm::ELF::R_SPARC_64: - case llvm::ELF::R_SPARC_UA64: + case ELF::R_SPARC_64: + case ELF::R_SPARC_UA64: return visitELF_SPARCV9_64(R, Value); default: HasError = true; @@ -153,9 +157,9 @@ private: } case Triple::amdgcn: switch (RelocType) { - case llvm::ELF::R_AMDGPU_ABS32: + case ELF::R_AMDGPU_ABS32: return visitELF_AMDGPU_ABS32(R, Value); - case llvm::ELF::R_AMDGPU_ABS64: + case ELF::R_AMDGPU_ABS64: return visitELF_AMDGPU_ABS64(R, Value); default: HasError = true; @@ -169,11 +173,11 @@ private: switch (ObjToVisit.getArch()) { case Triple::x86: switch (RelocType) { - case llvm::ELF::R_386_NONE: + case ELF::R_386_NONE: return visitELF_386_NONE(R); - case llvm::ELF::R_386_32: + case ELF::R_386_32: return visitELF_386_32(R, Value); - case llvm::ELF::R_386_PC32: + case ELF::R_386_PC32: return visitELF_386_PC32(R, Value); default: HasError = true; @@ -181,7 +185,7 @@ private: } case Triple::ppc: switch (RelocType) { - case llvm::ELF::R_PPC_ADDR32: + case ELF::R_PPC_ADDR32: return visitELF_PPC_ADDR32(R, Value); default: HasError = true; @@ -193,12 +197,12 @@ private: default: HasError = true; return RelocToApply(); - case llvm::ELF::R_ARM_ABS32: + case ELF::R_ARM_ABS32: return visitELF_ARM_ABS32(R, Value); } case Triple::lanai: switch (RelocType) { - case llvm::ELF::R_LANAI_32: + case ELF::R_LANAI_32: return visitELF_Lanai_32(R, Value); default: HasError = true; @@ -207,7 +211,7 @@ private: case Triple::mipsel: case Triple::mips: switch (RelocType) { - case llvm::ELF::R_MIPS_32: + case ELF::R_MIPS_32: return visitELF_MIPS_32(R, Value); default: HasError = true; @@ -215,8 +219,8 @@ private: } case Triple::sparc: switch (RelocType) { - case llvm::ELF::R_SPARC_32: - case llvm::ELF::R_SPARC_UA32: + case ELF::R_SPARC_32: + case ELF::R_SPARC_UA32: return visitELF_SPARC_32(R, Value); default: HasError = true; @@ -224,7 +228,7 @@ private: } case Triple::hexagon: switch (RelocType) { - case llvm::ELF::R_HEX_32: + case ELF::R_HEX_32: return visitELF_HEX_32(R, Value); default: HasError = true; @@ -483,6 +487,7 @@ private: } }; -} -} -#endif +} // end namespace object +} // end namespace llvm + +#endif // LLVM_OBJECT_RELOCVISITOR_H diff --git a/include/llvm/Object/StackMapParser.h b/include/llvm/Object/StackMapParser.h index efea62bb3cb3c..0c5e1e38cbaa4 100644 --- a/include/llvm/Object/StackMapParser.h +++ b/include/llvm/Object/StackMapParser.h @@ -1,4 +1,4 @@ -//===-------- StackMapParser.h - StackMap Parsing Support -------*- C++ -*-===// +//===- StackMapParser.h - StackMap Parsing Support --------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -11,7 +11,11 @@ #define LLVM_CODEGEN_STACKMAPPARSER_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Support/Endian.h" +#include <cassert> +#include <cstddef> +#include <cstdint> #include <vector> namespace llvm { @@ -19,12 +23,11 @@ namespace llvm { template <support::endianness Endianness> class StackMapV2Parser { public: - template <typename AccessorT> class AccessorIterator { public: - AccessorIterator(AccessorT A) : A(A) {} + AccessorIterator& operator++() { A = A.next(); return *this; } AccessorIterator operator++(int) { auto tmp = *this; @@ -48,8 +51,8 @@ public: /// Accessor for function records. class FunctionAccessor { friend class StackMapV2Parser; - public: + public: /// Get the function address. uint64_t getFunctionAddress() const { return read<uint64_t>(P); @@ -80,13 +83,12 @@ public: /// Accessor for constants. class ConstantAccessor { friend class StackMapV2Parser; - public: + public: /// Return the value of this constant. uint64_t getValue() const { return read<uint64_t>(P); } private: - ConstantAccessor(const uint8_t *P) : P(P) {} const static int ConstantAccessorSize = sizeof(uint64_t); @@ -98,20 +100,16 @@ public: const uint8_t *P; }; - // Forward-declare RecordAccessor so we can friend it below. - class RecordAccessor; - enum class LocationKind : uint8_t { Register = 1, Direct = 2, Indirect = 3, Constant = 4, ConstantIndex = 5 }; - /// Accessor for location records. class LocationAccessor { friend class StackMapV2Parser; friend class RecordAccessor; - public: + public: /// Get the Kind for this location. LocationKind getKind() const { return LocationKind(P[KindOffset]); @@ -144,7 +142,6 @@ public: } private: - LocationAccessor(const uint8_t *P) : P(P) {} LocationAccessor next() const { @@ -163,8 +160,8 @@ public: class LiveOutAccessor { friend class StackMapV2Parser; friend class RecordAccessor; - public: + public: /// Get the Dwarf register number for this live-out. uint16_t getDwarfRegNum() const { return read<uint16_t>(P + DwarfRegNumOffset); @@ -176,7 +173,6 @@ public: } private: - LiveOutAccessor(const uint8_t *P) : P(P) {} LiveOutAccessor next() const { @@ -194,10 +190,10 @@ public: /// Accessor for stackmap records. class RecordAccessor { friend class StackMapV2Parser; - public: - typedef AccessorIterator<LocationAccessor> location_iterator; - typedef AccessorIterator<LiveOutAccessor> liveout_iterator; + public: + using location_iterator = AccessorIterator<LocationAccessor>; + using liveout_iterator = AccessorIterator<LiveOutAccessor>; /// Get the patchpoint/stackmap ID for this record. uint64_t getID() const { @@ -254,7 +250,6 @@ public: return liveout_iterator(getLiveOut(0)); } - /// End iterator for live-outs. liveout_iterator liveouts_end() const { return liveout_iterator(getLiveOut(getNumLiveOuts())); @@ -266,7 +261,6 @@ public: } private: - RecordAccessor(const uint8_t *P) : P(P) {} unsigned getNumLiveOutsOffset() const { @@ -316,9 +310,9 @@ public: } } - typedef AccessorIterator<FunctionAccessor> function_iterator; - typedef AccessorIterator<ConstantAccessor> constant_iterator; - typedef AccessorIterator<RecordAccessor> record_iterator; + using function_iterator = AccessorIterator<FunctionAccessor>; + using constant_iterator = AccessorIterator<ConstantAccessor>; + using record_iterator = AccessorIterator<RecordAccessor>; /// Get the version number of this stackmap. (Always returns 2). unsigned getVersion() const { return 2; } @@ -413,7 +407,6 @@ public: } private: - template <typename T> static T read(const uint8_t *P) { return support::endian::read<T, Endianness, 1>(P); @@ -441,6 +434,6 @@ private: std::vector<unsigned> StackMapRecordOffsets; }; -} +} // end namespace llvm -#endif +#endif // LLVM_CODEGEN_STACKMAPPARSER_H diff --git a/include/llvm/Object/Wasm.h b/include/llvm/Object/Wasm.h index 43ad62be68b6c..6b6bbe252f65d 100644 --- a/include/llvm/Object/Wasm.h +++ b/include/llvm/Object/Wasm.h @@ -17,6 +17,8 @@ #ifndef LLVM_OBJECT_WASM_H #define LLVM_OBJECT_WASM_H +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Error.h" @@ -47,10 +49,10 @@ public: class WasmSection { public: - WasmSection() : Type(0), Offset(0) {} + WasmSection() = default; - uint32_t Type; // Section type (See below) - uint32_t Offset; // Offset with in the file + uint32_t Type = 0; // Section type (See below) + uint32_t Offset = 0; // Offset with in the file StringRef Name; // Section name (User-defined sections only) ArrayRef<uint8_t> Content; // Section content std::vector<wasm::WasmRelocation> Relocations; // Relocations for this section @@ -74,12 +76,15 @@ public: const std::vector<wasm::WasmLimits>& memories() const { return Memories; } const std::vector<wasm::WasmGlobal>& globals() const { return Globals; } const std::vector<wasm::WasmExport>& exports() const { return Exports; } + const std::vector<wasm::WasmElemSegment>& elements() const { return ElemSegments; } + const std::vector<wasm::WasmDataSegment>& dataSegments() const { return DataSegments; } + const std::vector<wasm::WasmFunction>& functions() const { return Functions; } const ArrayRef<uint8_t>& code() const { return CodeSection; } uint32_t startFunction() const { return StartFunction; } @@ -178,7 +183,7 @@ private: std::vector<WasmSymbol> Symbols; std::vector<wasm::WasmFunction> Functions; ArrayRef<uint8_t> CodeSection; - uint32_t StartFunction; + uint32_t StartFunction = -1; }; } // end namespace object |