1c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===- ELFObjectFile.h - ELF object file implementation ---------*- C++ -*-===// 2c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 3c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// The LLVM Compiler Infrastructure 4c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 5c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file is distributed under the University of Illinois Open Source 6c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// License. See LICENSE.TXT for details. 7c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 8c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 9c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 10c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file declares the ELFObjectFile template class. 11c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 12c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 13c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 14c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#ifndef LLVM_OBJECT_ELFOBJECTFILE_H 15c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define LLVM_OBJECT_ELFOBJECTFILE_H 16c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 17c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/ArrayRef.h" 18c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/SmallVector.h" 19c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/StringRef.h" 20c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/Triple.h" 21c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/iterator_range.h" 22c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/BinaryFormat/ELF.h" 23c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/MC/SubtargetFeature.h" 24c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/Binary.h" 25c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/ELF.h" 26c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/ELFTypes.h" 27c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/Error.h" 28c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/ObjectFile.h" 29c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/SymbolicFile.h" 30c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/ARMAttributeParser.h" 31c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/ARMBuildAttributes.h" 32c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/Casting.h" 33c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/Endian.h" 34c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/Error.h" 35c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/ErrorHandling.h" 36c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/MemoryBuffer.h" 37c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cassert> 38c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cstdint> 39c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <system_error> 40c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 41c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace llvm { 42c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace object { 43c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 44c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass elf_symbol_iterator; 45c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 46c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ELFObjectFileBase : public ObjectFile { 47c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class ELFRelocationRef; 48c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class ELFSectionRef; 49c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class ELFSymbolRef; 50c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 51c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprotected: 52c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source); 53c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 54c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual uint16_t getEMachine() const = 0; 55c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0; 56c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual uint8_t getSymbolOther(DataRefImpl Symb) const = 0; 57c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual uint8_t getSymbolELFType(DataRefImpl Symb) const = 0; 58c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 59c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual uint32_t getSectionType(DataRefImpl Sec) const = 0; 60c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual uint64_t getSectionFlags(DataRefImpl Sec) const = 0; 61c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual uint64_t getSectionOffset(DataRefImpl Sec) const = 0; 62c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 63c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0; 64c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 65c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 66c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot using elf_symbol_iterator_range = iterator_range<elf_symbol_iterator>; 67c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 68c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual elf_symbol_iterator_range getDynamicSymbolIterators() const = 0; 69c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 70c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot elf_symbol_iterator_range symbols() const; 71c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 72c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static bool classof(const Binary *v) { return v->isELF(); } 73c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 74c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SubtargetFeatures getFeatures() const override; 75c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 76c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SubtargetFeatures getMIPSFeatures() const; 77c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 78c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SubtargetFeatures getARMFeatures() const; 79c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 80c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setARMSubArch(Triple &TheTriple) const override; 81c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 82c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 83c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ELFSectionRef : public SectionRef { 84c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 85c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ELFSectionRef(const SectionRef &B) : SectionRef(B) { 86c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(isa<ELFObjectFileBase>(SectionRef::getObject())); 87c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 88c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 89c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFObjectFileBase *getObject() const { 90c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return cast<ELFObjectFileBase>(SectionRef::getObject()); 91c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 92c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 93c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint32_t getType() const { 94c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getObject()->getSectionType(getRawDataRefImpl()); 95c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 96c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 97c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getFlags() const { 98c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getObject()->getSectionFlags(getRawDataRefImpl()); 99c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getOffset() const { 102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getObject()->getSectionOffset(getRawDataRefImpl()); 103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass elf_section_iterator : public section_iterator { 107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot elf_section_iterator(const section_iterator &B) : section_iterator(B) { 109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(isa<ELFObjectFileBase>(B->getObject())); 110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFSectionRef *operator->() const { 113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return static_cast<const ELFSectionRef *>(section_iterator::operator->()); 114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFSectionRef &operator*() const { 117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return static_cast<const ELFSectionRef &>(section_iterator::operator*()); 118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ELFSymbolRef : public SymbolRef { 122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ELFSymbolRef(const SymbolRef &B) : SymbolRef(B) { 124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(isa<ELFObjectFileBase>(SymbolRef::getObject())); 125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFObjectFileBase *getObject() const { 128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return cast<ELFObjectFileBase>(BasicSymbolRef::getObject()); 129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSize() const { 132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getObject()->getSymbolSize(getRawDataRefImpl()); 133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint8_t getOther() const { 136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getObject()->getSymbolOther(getRawDataRefImpl()); 137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint8_t getELFType() const { 140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getObject()->getSymbolELFType(getRawDataRefImpl()); 141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass elf_symbol_iterator : public symbol_iterator { 145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot elf_symbol_iterator(const basic_symbol_iterator &B) 147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : symbol_iterator(SymbolRef(B->getRawDataRefImpl(), 148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot cast<ELFObjectFileBase>(B->getObject()))) {} 149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFSymbolRef *operator->() const { 151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return static_cast<const ELFSymbolRef *>(symbol_iterator::operator->()); 152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFSymbolRef &operator*() const { 155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return static_cast<const ELFSymbolRef &>(symbol_iterator::operator*()); 156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ELFRelocationRef : public RelocationRef { 160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ELFRelocationRef(const RelocationRef &B) : RelocationRef(B) { 162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(isa<ELFObjectFileBase>(RelocationRef::getObject())); 163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFObjectFileBase *getObject() const { 166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return cast<ELFObjectFileBase>(RelocationRef::getObject()); 167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Expected<int64_t> getAddend() const { 170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getObject()->getRelocationAddend(getRawDataRefImpl()); 171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass elf_relocation_iterator : public relocation_iterator { 175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot elf_relocation_iterator(const relocation_iterator &B) 177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : relocation_iterator(RelocationRef( 178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot B->getRawDataRefImpl(), cast<ELFObjectFileBase>(B->getObject()))) {} 179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFRelocationRef *operator->() const { 181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return static_cast<const ELFRelocationRef *>( 182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot relocation_iterator::operator->()); 183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFRelocationRef &operator*() const { 186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return static_cast<const ELFRelocationRef &>( 187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot relocation_iterator::operator*()); 188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline ELFObjectFileBase::elf_symbol_iterator_range 192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFileBase::symbols() const { 193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return elf_symbol_iterator_range(symbol_begin(), symbol_end()); 194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> class ELFObjectFile : public ELFObjectFileBase { 197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint16_t getEMachine() const override; 198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSymbolSize(DataRefImpl Sym) const override; 199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) 202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot using uintX_t = typename ELFFile<ELFT>::uintX_t; 204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot using Elf_Sym = typename ELFFile<ELFT>::Elf_Sym; 206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot using Elf_Shdr = typename ELFFile<ELFT>::Elf_Shdr; 207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot using Elf_Ehdr = typename ELFFile<ELFT>::Elf_Ehdr; 208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot using Elf_Rel = typename ELFFile<ELFT>::Elf_Rel; 209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot using Elf_Rela = typename ELFFile<ELFT>::Elf_Rela; 210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot using Elf_Dyn = typename ELFFile<ELFT>::Elf_Dyn; 211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate: 213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ELFObjectFile(MemoryBufferRef Object, ELFFile<ELFT> EF, 214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *DotDynSymSec, const Elf_Shdr *DotSymtabSec, 215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<Elf_Word> ShndxTable); 216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprotected: 218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ELFFile<ELFT> EF; 219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section. 221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section. 222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<Elf_Word> ShndxTable; 223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void moveSymbolNext(DataRefImpl &Symb) const override; 225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Expected<StringRef> getSymbolName(DataRefImpl Symb) const override; 226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override; 227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSymbolValueImpl(DataRefImpl Symb) const override; 228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint32_t getSymbolAlignment(DataRefImpl Symb) const override; 229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; 230c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint32_t getSymbolFlags(DataRefImpl Symb) const override; 231c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint8_t getSymbolOther(DataRefImpl Symb) const override; 232c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint8_t getSymbolELFType(DataRefImpl Symb) const override; 233c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override; 234c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Expected<section_iterator> getSymbolSection(const Elf_Sym *Symb, 235c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *SymTab) const; 236c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override; 237c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 238c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void moveSectionNext(DataRefImpl &Sec) const override; 239c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::error_code getSectionName(DataRefImpl Sec, 240c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef &Res) const override; 241c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSectionAddress(DataRefImpl Sec) const override; 242c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSectionIndex(DataRefImpl Sec) const override; 243c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSectionSize(DataRefImpl Sec) const override; 244c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::error_code getSectionContents(DataRefImpl Sec, 245c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef &Res) const override; 246c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSectionAlignment(DataRefImpl Sec) const override; 247c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isSectionCompressed(DataRefImpl Sec) const override; 248c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isSectionText(DataRefImpl Sec) const override; 249c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isSectionData(DataRefImpl Sec) const override; 250c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isSectionBSS(DataRefImpl Sec) const override; 251c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isSectionVirtual(DataRefImpl Sec) const override; 252c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot relocation_iterator section_rel_begin(DataRefImpl Sec) const override; 253c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot relocation_iterator section_rel_end(DataRefImpl Sec) const override; 254c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot section_iterator getRelocatedSection(DataRefImpl Sec) const override; 255c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 256c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void moveRelocationNext(DataRefImpl &Rel) const override; 257c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getRelocationOffset(DataRefImpl Rel) const override; 258c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override; 259c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getRelocationType(DataRefImpl Rel) const override; 260c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void getRelocationTypeName(DataRefImpl Rel, 261c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SmallVectorImpl<char> &Result) const override; 262c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 263c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint32_t getSectionType(DataRefImpl Sec) const override; 264c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSectionFlags(DataRefImpl Sec) const override; 265c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t getSectionOffset(DataRefImpl Sec) const override; 266c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef getRelocationTypeName(uint32_t Type) const; 267c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 268c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the relocation section that contains \a Rel. 269c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *getRelSection(DataRefImpl Rel) const { 270c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto RelSecOrErr = EF.getSection(Rel.d.a); 271c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!RelSecOrErr) 272c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error(errorToErrorCode(RelSecOrErr.takeError()).message()); 273c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return *RelSecOrErr; 274c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 275c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 276c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const { 277c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl DRI; 278c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SymTable) { 279c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DRI.d.a = 0; 280c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DRI.d.b = 0; 281c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return DRI; 282c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 283c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(SymTable->sh_type == ELF::SHT_SYMTAB || 284c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SymTable->sh_type == ELF::SHT_DYNSYM); 285c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 286c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SectionsOrErr = EF.sections(); 287c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SectionsOrErr) { 288c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DRI.d.a = 0; 289c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DRI.d.b = 0; 290c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return DRI; 291c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 292c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin()); 293c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned SymTableIndex = 294c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot (reinterpret_cast<uintptr_t>(SymTable) - SHT) / sizeof(Elf_Shdr); 295c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 296c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DRI.d.a = SymTableIndex; 297c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DRI.d.b = SymbolNum; 298c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return DRI; 299c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 300c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 301c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *toELFShdrIter(DataRefImpl Sec) const { 302c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return reinterpret_cast<const Elf_Shdr *>(Sec.p); 303c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 304c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 305c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl toDRI(const Elf_Shdr *Sec) const { 306c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl DRI; 307c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DRI.p = reinterpret_cast<uintptr_t>(Sec); 308c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return DRI; 309c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 310c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 311c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl toDRI(const Elf_Dyn *Dyn) const { 312c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl DRI; 313c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DRI.p = reinterpret_cast<uintptr_t>(Dyn); 314c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return DRI; 315c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 316c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 317c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isExportedToOtherDSO(const Elf_Sym *ESym) const { 318c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned char Binding = ESym->getBinding(); 319c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned char Visibility = ESym->getVisibility(); 320c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 321c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // A symbol is exported if its binding is either GLOBAL or WEAK, and its 322c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // visibility is either DEFAULT or PROTECTED. All other symbols are not 323c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // exported. 324c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ((Binding == ELF::STB_GLOBAL || Binding == ELF::STB_WEAK) && 325c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot (Visibility == ELF::STV_DEFAULT || 326c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Visibility == ELF::STV_PROTECTED)); 327c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 328c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 329c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // This flag is used for classof, to distinguish ELFObjectFile from 330c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // its subclass. If more subclasses will be created, this flag will 331c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // have to become an enum. 332c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isDyldELFObject; 333c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 334c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 335c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ELFObjectFile(ELFObjectFile<ELFT> &&Other); 336c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static Expected<ELFObjectFile<ELFT>> create(MemoryBufferRef Object); 337c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 338c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Rel *getRel(DataRefImpl Rel) const; 339c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Rela *getRela(DataRefImpl Rela) const; 340c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 341c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Sym *getSymbol(DataRefImpl Sym) const { 342c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto Ret = EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b); 343c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!Ret) 344c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error(errorToErrorCode(Ret.takeError()).message()); 345c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return *Ret; 346c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 347c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 348c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *getSection(DataRefImpl Sec) const { 349c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return reinterpret_cast<const Elf_Shdr *>(Sec.p); 350c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 351c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 352c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot basic_symbol_iterator symbol_begin() const override; 353c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot basic_symbol_iterator symbol_end() const override; 354c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 355c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot elf_symbol_iterator dynamic_symbol_begin() const; 356c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot elf_symbol_iterator dynamic_symbol_end() const; 357c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 358c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot section_iterator section_begin() const override; 359c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot section_iterator section_end() const override; 360c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 361c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const override; 362c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 363c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint8_t getBytesInAddress() const override; 364c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef getFileFormatName() const override; 365c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getArch() const override; 366c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 367c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::error_code getPlatformFlags(unsigned &Result) const override { 368c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result = EF.getHeader()->e_flags; 369c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::error_code(); 370c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 371c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 372c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::error_code getBuildAttributes(ARMAttributeParser &Attributes) const override { 373c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SectionsOrErr = EF.sections(); 374c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SectionsOrErr) 375c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return errorToErrorCode(SectionsOrErr.takeError()); 376c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 377c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot for (const Elf_Shdr &Sec : *SectionsOrErr) { 378c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES) { 379c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto ErrorOrContents = EF.getSectionContents(&Sec); 380c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!ErrorOrContents) 381c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return errorToErrorCode(ErrorOrContents.takeError()); 382c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 383c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto Contents = ErrorOrContents.get(); 384c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1) 385c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::error_code(); 386c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 387c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Attributes.Parse(Contents, ELFT::TargetEndianness == support::little); 388c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot break; 389c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 390c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 391c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::error_code(); 392c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 393c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 394c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ELFFile<ELFT> *getELFFile() const { return &EF; } 395c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 396c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isDyldType() const { return isDyldELFObject; } 397c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static bool classof(const Binary *v) { 398c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return v->getType() == getELFType(ELFT::TargetEndianness == support::little, 399c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ELFT::Is64Bits); 400c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 401c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 402c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot elf_symbol_iterator_range getDynamicSymbolIterators() const override; 403c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 404c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isRelocatableObject() const override; 405c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 406c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 407c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotusing ELF32LEObjectFile = ELFObjectFile<ELFType<support::little, false>>; 408c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotusing ELF64LEObjectFile = ELFObjectFile<ELFType<support::little, true>>; 409c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotusing ELF32BEObjectFile = ELFObjectFile<ELFType<support::big, false>>; 410c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotusing ELF64BEObjectFile = ELFObjectFile<ELFType<support::big, true>>; 411c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 412c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 413c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotvoid ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const { 414c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ++Sym.d.b; 415c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 416c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 417c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 418c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotExpected<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const { 419c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Sym *ESym = getSymbol(Sym); 420c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SymTabOrErr = EF.getSection(Sym.d.a); 421c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SymTabOrErr) 422c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymTabOrErr.takeError(); 423c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *SymTableSec = *SymTabOrErr; 424c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto StrTabOrErr = EF.getSection(SymTableSec->sh_link); 425c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!StrTabOrErr) 426c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return StrTabOrErr.takeError(); 427c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *StringTableSec = *StrTabOrErr; 428c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SymStrTabOrErr = EF.getStringTable(StringTableSec); 429c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SymStrTabOrErr) 430c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymStrTabOrErr.takeError(); 431c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ESym->getName(*SymStrTabOrErr); 432c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 433c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 434c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 435c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getSectionFlags(DataRefImpl Sec) const { 436c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_flags; 437c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 438c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 439c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 440c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint32_t ELFObjectFile<ELFT>::getSectionType(DataRefImpl Sec) const { 441c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_type; 442c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 443c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 444c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 445c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getSectionOffset(DataRefImpl Sec) const { 446c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_offset; 447c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 448c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 449c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 450c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getSymbolValueImpl(DataRefImpl Symb) const { 451c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Sym *ESym = getSymbol(Symb); 452c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t Ret = ESym->st_value; 453c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->st_shndx == ELF::SHN_ABS) 454c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Ret; 455c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 456c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Ehdr *Header = EF.getHeader(); 457c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Clear the ARM/Thumb or microMIPS indicator flag. 458c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if ((Header->e_machine == ELF::EM_ARM || Header->e_machine == ELF::EM_MIPS) && 459c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ESym->getType() == ELF::STT_FUNC) 460c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Ret &= ~1; 461c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 462c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Ret; 463c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 464c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 465c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 466c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotExpected<uint64_t> 467c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb) const { 468c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint64_t Result = getSymbolValue(Symb); 469c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Sym *ESym = getSymbol(Symb); 470c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (ESym->st_shndx) { 471c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::SHN_COMMON: 472c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::SHN_UNDEF: 473c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::SHN_ABS: 474c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Result; 475c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 476c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 477c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Ehdr *Header = EF.getHeader(); 478c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SymTabOrErr = EF.getSection(Symb.d.a); 479c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SymTabOrErr) 480c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymTabOrErr.takeError(); 481c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *SymTab = *SymTabOrErr; 482c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 483c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Header->e_type == ELF::ET_REL) { 484c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SectionOrErr = EF.getSection(ESym, SymTab, ShndxTable); 485c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SectionOrErr) 486c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SectionOrErr.takeError(); 487c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *Section = *SectionOrErr; 488c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Section) 489c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result += Section->sh_addr; 490c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 491c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 492c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Result; 493c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 494c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 495c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 496c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint32_t ELFObjectFile<ELFT>::getSymbolAlignment(DataRefImpl Symb) const { 497c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Sym *Sym = getSymbol(Symb); 498c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Sym->st_shndx == ELF::SHN_COMMON) 499c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Sym->st_value; 500c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return 0; 501c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 502c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 503c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 504c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint16_t ELFObjectFile<ELFT>::getEMachine() const { 505c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return EF.getHeader()->e_machine; 506c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 507c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 508c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 509c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getSymbolSize(DataRefImpl Sym) const { 510c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSymbol(Sym)->st_size; 511c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 512c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 513c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 514c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getCommonSymbolSizeImpl(DataRefImpl Symb) const { 515c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSymbol(Symb)->st_size; 516c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 517c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 518c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 519c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint8_t ELFObjectFile<ELFT>::getSymbolOther(DataRefImpl Symb) const { 520c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSymbol(Symb)->st_other; 521c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 522c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 523c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 524c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint8_t ELFObjectFile<ELFT>::getSymbolELFType(DataRefImpl Symb) const { 525c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSymbol(Symb)->getType(); 526c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 527c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 528c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 529c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotExpected<SymbolRef::Type> 530c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb) const { 531c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Sym *ESym = getSymbol(Symb); 532c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 533c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (ESym->getType()) { 534c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::STT_NOTYPE: 535c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymbolRef::ST_Unknown; 536c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::STT_SECTION: 537c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymbolRef::ST_Debug; 538c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::STT_FILE: 539c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymbolRef::ST_File; 540c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::STT_FUNC: 541c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymbolRef::ST_Function; 542c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::STT_OBJECT: 543c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::STT_COMMON: 544c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::STT_TLS: 545c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymbolRef::ST_Data; 546c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: 547c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymbolRef::ST_Other; 548c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 549c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 550c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 551c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 552c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint32_t ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const { 553c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Sym *ESym = getSymbol(Sym); 554c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 555c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint32_t Result = SymbolRef::SF_None; 556c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 557c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->getBinding() != ELF::STB_LOCAL) 558c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_Global; 559c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 560c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->getBinding() == ELF::STB_WEAK) 561c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_Weak; 562c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 563c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->st_shndx == ELF::SHN_ABS) 564c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_Absolute; 565c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 566c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION) 567c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_FormatSpecific; 568c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 569c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto DotSymtabSecSyms = EF.symbols(DotSymtabSec); 570c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (DotSymtabSecSyms && ESym == (*DotSymtabSecSyms).begin()) 571c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_FormatSpecific; 572c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto DotDynSymSecSyms = EF.symbols(DotDynSymSec); 573c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (DotDynSymSecSyms && ESym == (*DotDynSymSecSyms).begin()) 574c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_FormatSpecific; 575c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 576c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (EF.getHeader()->e_machine == ELF::EM_ARM) { 577c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) { 578c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef Name = *NameOrErr; 579c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Name.startswith("$d") || Name.startswith("$t") || 580c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Name.startswith("$a")) 581c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_FormatSpecific; 582c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } else { 583c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // TODO: Actually report errors helpfully. 584c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot consumeError(NameOrErr.takeError()); 585c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 586c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1) 587c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_Thumb; 588c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 589c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 590c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->st_shndx == ELF::SHN_UNDEF) 591c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_Undefined; 592c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 593c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->getType() == ELF::STT_COMMON || ESym->st_shndx == ELF::SHN_COMMON) 594c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_Common; 595c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 596c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (isExportedToOtherDSO(ESym)) 597c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_Exported; 598c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 599c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ESym->getVisibility() == ELF::STV_HIDDEN) 600c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result |= SymbolRef::SF_Hidden; 601c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 602c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Result; 603c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 604c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 605c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 606c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotExpected<section_iterator> 607c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getSymbolSection(const Elf_Sym *ESym, 608c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *SymTab) const { 609c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto ESecOrErr = EF.getSection(ESym, SymTab, ShndxTable); 610c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!ESecOrErr) 611c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ESecOrErr.takeError(); 612c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 613c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *ESec = *ESecOrErr; 614c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!ESec) 615c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_end(); 616c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 617c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl Sec; 618c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Sec.p = reinterpret_cast<intptr_t>(ESec); 619c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_iterator(SectionRef(Sec, this)); 620c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 621c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 622c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 623c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotExpected<section_iterator> 624c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getSymbolSection(DataRefImpl Symb) const { 625c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Sym *Sym = getSymbol(Symb); 626c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SymTabOrErr = EF.getSection(Symb.d.a); 627c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SymTabOrErr) 628c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SymTabOrErr.takeError(); 629c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *SymTab = *SymTabOrErr; 630c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSymbolSection(Sym, SymTab); 631c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 632c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 633c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 634c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotvoid ELFObjectFile<ELFT>::moveSectionNext(DataRefImpl &Sec) const { 635c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *ESec = getSection(Sec); 636c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Sec = toDRI(++ESec); 637c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 638c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 639c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 640c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotstd::error_code ELFObjectFile<ELFT>::getSectionName(DataRefImpl Sec, 641c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef &Result) const { 642c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto Name = EF.getSectionName(&*getSection(Sec)); 643c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!Name) 644c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return errorToErrorCode(Name.takeError()); 645c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result = *Name; 646c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::error_code(); 647c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 648c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 649c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 650c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getSectionAddress(DataRefImpl Sec) const { 651c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_addr; 652c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 653c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 654c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 655c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getSectionIndex(DataRefImpl Sec) const { 656c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SectionsOrErr = EF.sections(); 657c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot handleAllErrors(std::move(SectionsOrErr.takeError()), 658c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot [](const ErrorInfoBase &) { 659c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm_unreachable("unable to get section index"); 660c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }); 661c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *First = SectionsOrErr->begin(); 662c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec) - First; 663c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 664c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 665c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 666c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getSectionSize(DataRefImpl Sec) const { 667c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_size; 668c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 669c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 670c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 671c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotstd::error_code 672c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getSectionContents(DataRefImpl Sec, 673c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef &Result) const { 674c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *EShdr = getSection(Sec); 675c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (std::error_code EC = 676c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot checkOffset(getMemoryBufferRef(), 677c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot (uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size)) 678c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return EC; 679c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Result = StringRef((const char *)base() + EShdr->sh_offset, EShdr->sh_size); 680c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::error_code(); 681c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 682c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 683c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 684c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getSectionAlignment(DataRefImpl Sec) const { 685c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_addralign; 686c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 687c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 688c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 689c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotbool ELFObjectFile<ELFT>::isSectionCompressed(DataRefImpl Sec) const { 690c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_flags & ELF::SHF_COMPRESSED; 691c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 692c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 693c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 694c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotbool ELFObjectFile<ELFT>::isSectionText(DataRefImpl Sec) const { 695c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR; 696c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 697c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 698c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 699c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotbool ELFObjectFile<ELFT>::isSectionData(DataRefImpl Sec) const { 700c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *EShdr = getSection(Sec); 701c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) && 702c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot EShdr->sh_type == ELF::SHT_PROGBITS; 703c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 704c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 705c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 706c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotbool ELFObjectFile<ELFT>::isSectionBSS(DataRefImpl Sec) const { 707c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *EShdr = getSection(Sec); 708c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) && 709c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot EShdr->sh_type == ELF::SHT_NOBITS; 710c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 711c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 712c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 713c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotbool ELFObjectFile<ELFT>::isSectionVirtual(DataRefImpl Sec) const { 714c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSection(Sec)->sh_type == ELF::SHT_NOBITS; 715c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 716c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 717c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 718c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotrelocation_iterator 719c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::section_rel_begin(DataRefImpl Sec) const { 720c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl RelData; 721c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SectionsOrErr = EF.sections(); 722c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SectionsOrErr) 723c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return relocation_iterator(RelocationRef()); 724c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin()); 725c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize; 726c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot RelData.d.b = 0; 727c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return relocation_iterator(RelocationRef(RelData, this)); 728c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 729c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 730c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 731c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotrelocation_iterator 732c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::section_rel_end(DataRefImpl Sec) const { 733c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p); 734c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot relocation_iterator Begin = section_rel_begin(Sec); 735c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL) 736c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Begin; 737c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl RelData = Begin->getRawDataRefImpl(); 738c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *RelSec = getRelSection(RelData); 739c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 740c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Error check sh_link here so that getRelocationSymbol can just use it. 741c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SymSecOrErr = EF.getSection(RelSec->sh_link); 742c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SymSecOrErr) 743c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error(errorToErrorCode(SymSecOrErr.takeError()).message()); 744c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 745c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot RelData.d.b += S->sh_size / S->sh_entsize; 746c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return relocation_iterator(RelocationRef(RelData, this)); 747c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 748c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 749c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 750c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotsection_iterator 751c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getRelocatedSection(DataRefImpl Sec) const { 752c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (EF.getHeader()->e_type != ELF::ET_REL) 753c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_end(); 754c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 755c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *EShdr = getSection(Sec); 756c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uintX_t Type = EShdr->sh_type; 757c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA) 758c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_end(); 759c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 760c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto R = EF.getSection(EShdr->sh_info); 761c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!R) 762c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error(errorToErrorCode(R.takeError()).message()); 763c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_iterator(SectionRef(toDRI(*R), this)); 764c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 765c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 766c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// Relocations 767c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 768c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotvoid ELFObjectFile<ELFT>::moveRelocationNext(DataRefImpl &Rel) const { 769c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ++Rel.d.b; 770c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 771c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 772c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 773c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotsymbol_iterator 774c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const { 775c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint32_t symbolIdx; 776c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *sec = getRelSection(Rel); 777c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (sec->sh_type == ELF::SHT_REL) 778c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL()); 779c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot else 780c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL()); 781c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!symbolIdx) 782c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return symbol_end(); 783c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 784c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // FIXME: error check symbolIdx 785c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl SymbolData; 786c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SymbolData.d.a = sec->sh_link; 787c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SymbolData.d.b = symbolIdx; 788c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return symbol_iterator(SymbolRef(SymbolData, this)); 789c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 790c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 791c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 792c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel) const { 793c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(EF.getHeader()->e_type == ELF::ET_REL && 794c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot "Only relocatable object files have relocation offsets"); 795c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *sec = getRelSection(Rel); 796c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (sec->sh_type == ELF::SHT_REL) 797c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getRel(Rel)->r_offset; 798c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 799c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getRela(Rel)->r_offset; 800c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 801c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 802c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 803c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint64_t ELFObjectFile<ELFT>::getRelocationType(DataRefImpl Rel) const { 804c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *sec = getRelSection(Rel); 805c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (sec->sh_type == ELF::SHT_REL) 806c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getRel(Rel)->getType(EF.isMips64EL()); 807c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot else 808c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getRela(Rel)->getType(EF.isMips64EL()); 809c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 810c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 811c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 812c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotStringRef ELFObjectFile<ELFT>::getRelocationTypeName(uint32_t Type) const { 813c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getELFRelocationTypeName(EF.getHeader()->e_machine, Type); 814c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 815c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 816c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 817c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotvoid ELFObjectFile<ELFT>::getRelocationTypeName( 818c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl Rel, SmallVectorImpl<char> &Result) const { 819c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot uint32_t type = getRelocationType(Rel); 820c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot EF.getRelocationTypeName(type, Result); 821c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 822c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 823c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 824c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotExpected<int64_t> 825c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getRelocationAddend(DataRefImpl Rel) const { 826c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (getRelSection(Rel)->sh_type != ELF::SHT_RELA) 827c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return createError("Section is not SHT_RELA"); 828c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return (int64_t)getRela(Rel)->r_addend; 829c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 830c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 831c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 832c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotconst typename ELFObjectFile<ELFT>::Elf_Rel * 833c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getRel(DataRefImpl Rel) const { 834c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(getRelSection(Rel)->sh_type == ELF::SHT_REL); 835c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b); 836c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!Ret) 837c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error(errorToErrorCode(Ret.takeError()).message()); 838c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return *Ret; 839c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 840c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 841c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 842c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotconst typename ELFObjectFile<ELFT>::Elf_Rela * 843c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getRela(DataRefImpl Rela) const { 844c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA); 845c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b); 846c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!Ret) 847c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error(errorToErrorCode(Ret.takeError()).message()); 848c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return *Ret; 849c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 850c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 851c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 852c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotExpected<ELFObjectFile<ELFT>> 853c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::create(MemoryBufferRef Object) { 854c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto EFOrErr = ELFFile<ELFT>::create(Object.getBuffer()); 855c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Error E = EFOrErr.takeError()) 856c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::move(E); 857c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto EF = std::move(*EFOrErr); 858c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 859c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SectionsOrErr = EF.sections(); 860c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SectionsOrErr) 861c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SectionsOrErr.takeError(); 862c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 863c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *DotDynSymSec = nullptr; 864c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *DotSymtabSec = nullptr; 865c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<Elf_Word> ShndxTable; 866c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot for (const Elf_Shdr &Sec : *SectionsOrErr) { 867c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (Sec.sh_type) { 868c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::SHT_DYNSYM: { 869c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (DotDynSymSec) 870c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return createError("More than one dynamic symbol table!"); 871c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DotDynSymSec = &Sec; 872c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot break; 873c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 874c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::SHT_SYMTAB: { 875c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (DotSymtabSec) 876c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return createError("More than one static symbol table!"); 877c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DotSymtabSec = &Sec; 878c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot break; 879c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 880c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::SHT_SYMTAB_SHNDX: { 881c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto TableOrErr = EF.getSHNDXTable(Sec); 882c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!TableOrErr) 883c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return TableOrErr.takeError(); 884c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ShndxTable = *TableOrErr; 885c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot break; 886c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 887c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 888c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 889c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ELFObjectFile<ELFT>(Object, EF, DotDynSymSec, DotSymtabSec, 890c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ShndxTable); 891c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 892c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 893c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 894c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::ELFObjectFile(MemoryBufferRef Object, ELFFile<ELFT> EF, 895c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *DotDynSymSec, 896c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *DotSymtabSec, 897c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<Elf_Word> ShndxTable) 898c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : ELFObjectFileBase( 899c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits), 900c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Object), 901c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec), 902c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ShndxTable(ShndxTable) {} 903c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 904c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 905c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::ELFObjectFile(ELFObjectFile<ELFT> &&Other) 906c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : ELFObjectFile(Other.Data, Other.EF, Other.DotDynSymSec, 907c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Other.DotSymtabSec, Other.ShndxTable) {} 908c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 909c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 910c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotbasic_symbol_iterator ELFObjectFile<ELFT>::symbol_begin() const { 911c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl Sym = toDRI(DotSymtabSec, 0); 912c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return basic_symbol_iterator(SymbolRef(Sym, this)); 913c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 914c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 915c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 916c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotbasic_symbol_iterator ELFObjectFile<ELFT>::symbol_end() const { 917c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *SymTab = DotSymtabSec; 918c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SymTab) 919c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return symbol_begin(); 920c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym)); 921c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return basic_symbol_iterator(SymbolRef(Sym, this)); 922c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 923c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 924c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 925c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotelf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_begin() const { 926c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl Sym = toDRI(DotDynSymSec, 0); 927c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return symbol_iterator(SymbolRef(Sym, this)); 928c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 929c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 930c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 931c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotelf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_end() const { 932c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Elf_Shdr *SymTab = DotDynSymSec; 933c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SymTab) 934c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return dynamic_symbol_begin(); 935c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym)); 936c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return basic_symbol_iterator(SymbolRef(Sym, this)); 937c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 938c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 939c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 940c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotsection_iterator ELFObjectFile<ELFT>::section_begin() const { 941c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SectionsOrErr = EF.sections(); 942c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SectionsOrErr) 943c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_iterator(SectionRef()); 944c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_iterator(SectionRef(toDRI((*SectionsOrErr).begin()), this)); 945c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 946c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 947c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 948c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotsection_iterator ELFObjectFile<ELFT>::section_end() const { 949c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot auto SectionsOrErr = EF.sections(); 950c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!SectionsOrErr) 951c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_iterator(SectionRef()); 952c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return section_iterator(SectionRef(toDRI((*SectionsOrErr).end()), this)); 953c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 954c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 955c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 956c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotuint8_t ELFObjectFile<ELFT>::getBytesInAddress() const { 957c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ELFT::Is64Bits ? 8 : 4; 958c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 959c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 960c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 961c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotStringRef ELFObjectFile<ELFT>::getFileFormatName() const { 962c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool IsLittleEndian = ELFT::TargetEndianness == support::little; 963c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { 964c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::ELFCLASS32: 965c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (EF.getHeader()->e_machine) { 966c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_386: 967c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-i386"; 968c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_IAMCU: 969c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-iamcu"; 970c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_X86_64: 971c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-x86-64"; 972c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_ARM: 973c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return (IsLittleEndian ? "ELF32-arm-little" : "ELF32-arm-big"); 974c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_AVR: 975c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-avr"; 976c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_HEXAGON: 977c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-hexagon"; 978c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_LANAI: 979c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-lanai"; 980c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_MIPS: 981c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-mips"; 982c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_PPC: 983c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-ppc"; 984c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_RISCV: 985c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-riscv"; 986c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_SPARC: 987c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_SPARC32PLUS: 988c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-sparc"; 989c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_WEBASSEMBLY: 990c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-wasm"; 991c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_AMDGPU: 992c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-amdgpu"; 993c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: 994c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF32-unknown"; 995c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 996c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::ELFCLASS64: 997c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (EF.getHeader()->e_machine) { 998c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_386: 999c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-i386"; 1000c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_X86_64: 1001c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-x86-64"; 1002c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_AARCH64: 1003c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return (IsLittleEndian ? "ELF64-aarch64-little" : "ELF64-aarch64-big"); 1004c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_PPC64: 1005c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-ppc64"; 1006c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_RISCV: 1007c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-riscv"; 1008c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_S390: 1009c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-s390"; 1010c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_SPARCV9: 1011c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-sparc"; 1012c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_MIPS: 1013c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-mips"; 1014c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_WEBASSEMBLY: 1015c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-wasm"; 1016c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_AMDGPU: 1017c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-amdgpu"; 1018c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_BPF: 1019c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-BPF"; 1020c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: 1021c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return "ELF64-unknown"; 1022c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1023c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: 1024c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // FIXME: Proper error handling. 1025c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error("Invalid ELFCLASS!"); 1026c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1027c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 1028c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1029c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 1030c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotunsigned ELFObjectFile<ELFT>::getArch() const { 1031c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool IsLittleEndian = ELFT::TargetEndianness == support::little; 1032c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (EF.getHeader()->e_machine) { 1033c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_386: 1034c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_IAMCU: 1035c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::x86; 1036c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_X86_64: 1037c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::x86_64; 1038c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_AARCH64: 1039c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be; 1040c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_ARM: 1041c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::arm; 1042c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_AVR: 1043c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::avr; 1044c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_HEXAGON: 1045c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::hexagon; 1046c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_LANAI: 1047c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::lanai; 1048c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_MIPS: 1049c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { 1050c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::ELFCLASS32: 1051c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return IsLittleEndian ? Triple::mipsel : Triple::mips; 1052c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::ELFCLASS64: 1053c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return IsLittleEndian ? Triple::mips64el : Triple::mips64; 1054c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: 1055c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error("Invalid ELFCLASS!"); 1056c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1057c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_PPC: 1058c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::ppc; 1059c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_PPC64: 1060c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return IsLittleEndian ? Triple::ppc64le : Triple::ppc64; 1061c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_RISCV: 1062c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { 1063c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::ELFCLASS32: 1064c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::riscv32; 1065c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::ELFCLASS64: 1066c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::riscv64; 1067c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: 1068c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot report_fatal_error("Invalid ELFCLASS!"); 1069c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1070c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_S390: 1071c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::systemz; 1072c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1073c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_SPARC: 1074c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_SPARC32PLUS: 1075c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return IsLittleEndian ? Triple::sparcel : Triple::sparc; 1076c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_SPARCV9: 1077c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::sparcv9; 1078c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_WEBASSEMBLY: 1079c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { 1080c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::ELFCLASS32: return Triple::wasm32; 1081c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::ELFCLASS64: return Triple::wasm64; 1082c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: return Triple::UnknownArch; 1083c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1084c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1085c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_AMDGPU: { 1086c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!IsLittleEndian) 1087c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::UnknownArch; 1088c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1089c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned EFlags = EF.getHeader()->e_flags; 1090c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot switch (EFlags & ELF::EF_AMDGPU_ARCH) { 1091c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EF_AMDGPU_ARCH_R600: 1092c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::r600; 1093c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EF_AMDGPU_ARCH_GCN: 1094c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::amdgcn; 1095c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: 1096c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::UnknownArch; 1097c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1098c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1099c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot case ELF::EM_BPF: 1101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return IsLittleEndian ? Triple::bpfel : Triple::bpfeb; 1102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot default: 1104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Triple::UnknownArch; 1105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 1107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> 1109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFileBase::elf_symbol_iterator_range 1110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team RobotELFObjectFile<ELFT>::getDynamicSymbolIterators() const { 1111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return make_range(dynamic_symbol_begin(), dynamic_symbol_end()); 1112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 1113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const { 1115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return EF.getHeader()->e_type == ELF::ET_REL; 1116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 1117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // end namespace object 1119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // end namespace llvm 1120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#endif // LLVM_OBJECT_ELFOBJECTFILE_H 1122