168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//===- ObjectFile.h - File format independent object file -------*- C++ -*-===//
268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//
368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//                     The LLVM Compiler Infrastructure
468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//
568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer// This file is distributed under the University of Illinois Open Source
668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer// License. See LICENSE.TXT for details.
768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//
868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//===----------------------------------------------------------------------===//
968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//
1068b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer// This file declares a file format independent ObjectFile class.
1168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//
1268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer//===----------------------------------------------------------------------===//
1368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
14674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_OBJECT_OBJECTFILE_H
15674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_OBJECT_OBJECTFILE_H
1668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
1788af6b9217f9ff8b4592f38ac5175de697275f49Michael J. Spencer#include "llvm/ADT/StringRef.h"
1836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/Object/SymbolicFile.h"
191f6efa3996dd1929fbc129203ce5009b620e6969Michael J. Spencer#include "llvm/Support/DataTypes.h"
2025b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer#include "llvm/Support/ErrorHandling.h"
2136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/Support/FileSystem.h"
22001c9205fca2220480589ec355cb6ec701a37e08Michael J. Spencer#include "llvm/Support/MemoryBuffer.h"
237acdb4d237181976b04e72f6a6c329c3b2604440Michael J. Spencer#include <cstring>
2424973c1063bfb7ac353732a4e8eb801830336c5fEli Bendersky#include <vector>
2568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
2668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencernamespace llvm {
2768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencernamespace object {
2868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
2968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencerclass ObjectFile;
307acdb4d237181976b04e72f6a6c329c3b2604440Michael J. Spencer
319b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencerclass SymbolRef;
3236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesclass symbol_iterator;
3368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
340fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer/// RelocationRef - This is a value type class that represents a single
350fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer/// relocation in the list of relocations in the object file.
360fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramerclass RelocationRef {
370fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  DataRefImpl RelocationPimpl;
380fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  const ObjectFile *OwningObject;
390fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
400fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramerpublic:
41dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  RelocationRef() : OwningObject(nullptr) { }
420fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
430fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
440fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
450fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  bool operator==(const RelocationRef &Other) const;
460fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
4736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void moveNext();
480fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
49cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getAddress(uint64_t &Result) const;
50cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getOffset(uint64_t &Result) const;
516c1202c459ffa6d693ad92fa84e43902bc780bcaRafael Espindola  symbol_iterator getSymbol() const;
52cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getType(uint64_t &Result) const;
534344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer
540685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson  /// @brief Indicates whether this relocation should hidden when listing
550685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson  /// relocations, usually because it is the trailing part of a multipart
560685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson  /// relocation that will be printed as part of the leading relocation.
57cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getHidden(bool &Result) const;
580685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson
594344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  /// @brief Get a string that represents the type of this relocation.
604344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  ///
614344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  /// This is for display purposes only.
62cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getTypeName(SmallVectorImpl<char> &Result) const;
634344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer
644344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  /// @brief Get a string that represents the calculation of the value of this
654344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  ///        relocation.
664344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  ///
674344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  /// This is for display purposes only.
68cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getValueString(SmallVectorImpl<char> &Result) const;
699ac0f1d7255d7941c331b0a62a830a3b033358fdMarshall Clow
709ac0f1d7255d7941c331b0a62a830a3b033358fdMarshall Clow  DataRefImpl getRawDataRefImpl() const;
71167957fa095bc7200b908e6e142be3e604bcfeeaRafael Espindola  const ObjectFile *getObjectFile() const;
720fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer};
734344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencertypedef content_iterator<RelocationRef> relocation_iterator;
740fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
7568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer/// SectionRef - This is a value type class that represents a single section in
7668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer/// the list of sections in the object file.
777486d92a6c949a193bb75c0ffa0170eeb2fabb80Rafael Espindolaclass SectionRef;
787486d92a6c949a193bb75c0ffa0170eeb2fabb80Rafael Espindolatypedef content_iterator<SectionRef> section_iterator;
7968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencerclass SectionRef {
8007ea23aa2d17f701fa125442c20c1eba75b55fdbBenjamin Kramer  friend class SymbolRef;
8168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  DataRefImpl SectionPimpl;
8268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  const ObjectFile *OwningObject;
8368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
8468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencerpublic:
85dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  SectionRef() : OwningObject(nullptr) { }
86dedd6ee135f886e219035b2cf5957ce492f90ed1Michael J. Spencer
8768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
8868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
8968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  bool operator==(const SectionRef &Other) const;
9036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool operator!=(const SectionRef &Other) const;
915b957e6fd9853f938b8b33cfeb03d80595a9c2f8Eric Christopher  bool operator<(const SectionRef &Other) const;
9268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
9336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void moveNext();
9468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
95cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getName(StringRef &Result) const;
96cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getAddress(uint64_t &Result) const;
97cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getSize(uint64_t &Result) const;
98cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getContents(StringRef &Result) const;
9968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
100e2f2f07be7cf2b55b7e5501291bbcede87e43fd6Michael J. Spencer  /// @brief Get the alignment of this section as the actual value (not log 2).
101cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getAlignment(uint64_t &Result) const;
102e2f2f07be7cf2b55b7e5501291bbcede87e43fd6Michael J. Spencer
10368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  // FIXME: Move to the normalization layer when it's created.
104cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code isText(bool &Result) const;
105cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code isData(bool &Result) const;
106cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code isBSS(bool &Result) const;
107cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code isRequiredForExecution(bool &Result) const;
108cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code isVirtual(bool &Result) const;
109cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code isZeroInit(bool &Result) const;
110cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code isReadOnlyData(bool &Result) const;
11107ea23aa2d17f701fa125442c20c1eba75b55fdbBenjamin Kramer
112cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code containsSymbol(SymbolRef S, bool &Result) const;
1134344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer
11436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  relocation_iterator relocation_begin() const;
11536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  relocation_iterator relocation_end() const;
116dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  iterator_range<relocation_iterator> relocations() const {
117dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return iterator_range<relocation_iterator>(relocation_begin(),
118dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                                               relocation_end());
11936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
1207486d92a6c949a193bb75c0ffa0170eeb2fabb80Rafael Espindola  section_iterator getRelocatedSection() const;
121c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd
122c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd  DataRefImpl getRawDataRefImpl() const;
12368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer};
12468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
1259b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer/// SymbolRef - This is a value type class that represents a single symbol in
1269b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer/// the list of symbols in the object file.
12736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesclass SymbolRef : public BasicSymbolRef {
1289b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer  friend class SectionRef;
1299b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
1309b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencerpublic:
13136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SymbolRef() : BasicSymbolRef() {}
1329b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
1339b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer  enum Type {
1342c67727046234ad9702ab5acb72700b5ac99a676David Meyer    ST_Unknown, // Type not specified
1359b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer    ST_Data,
136206d17cf605293f1c12d8bfa8cf72826a29b253fMichael J. Spencer    ST_Debug,
137206d17cf605293f1c12d8bfa8cf72826a29b253fMichael J. Spencer    ST_File,
138206d17cf605293f1c12d8bfa8cf72826a29b253fMichael J. Spencer    ST_Function,
1399b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer    ST_Other
1409b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer  };
1419b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
1429b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer  SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
1439b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
144cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getName(StringRef &Result) const;
14501fa41a106ed0ff86c3b9ffe0843679211bf487cAlexey Samsonov  /// Returns the symbol virtual address (i.e. address at which it will be
14601fa41a106ed0ff86c3b9ffe0843679211bf487cAlexey Samsonov  /// mapped).
147cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getAddress(uint64_t &Result) const;
14859a0e79631ed851d98cf9c2ba6fa5f9aafdfdc93Rafael Espindola  /// @brief Get the alignment of this symbol as the actual value (not log 2).
149cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getAlignment(uint32_t &Result) const;
150cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getSize(uint64_t &Result) const;
151cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getType(SymbolRef::Type &Result) const;
1529b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
1539b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer  /// @brief Get section this symbol is defined in reference to. Result is
1549b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer  /// end_sections() if it is undefined or is an absolute symbol.
155cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getSection(section_iterator &Result) const;
1569b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
15736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  const ObjectFile *getObject() const;
15836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines};
159a41dce3c642e50775352cce49e3a3d0cd004d393Tim Northover
16036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesclass symbol_iterator : public basic_symbol_iterator {
16136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinespublic:
16236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  symbol_iterator(SymbolRef Sym) : basic_symbol_iterator(Sym) {}
16336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  symbol_iterator(const basic_symbol_iterator &B)
16436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      : basic_symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
16536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                        cast<ObjectFile>(B->getObject()))) {}
16636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
16736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  const SymbolRef *operator->() const {
16836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    const BasicSymbolRef &P = basic_symbol_iterator::operator *();
16936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return static_cast<const SymbolRef*>(&P);
17036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
17136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
17236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  const SymbolRef &operator*() const {
17336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    const BasicSymbolRef &P = basic_symbol_iterator::operator *();
17436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return static_cast<const SymbolRef&>(P);
17536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
1769b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer};
1779b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
1785c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer/// LibraryRef - This is a value type class that represents a single library in
1795c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer/// the list of libraries needed by a shared or dynamic object.
1805c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyerclass LibraryRef {
1815c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  friend class SectionRef;
1825c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  DataRefImpl LibraryPimpl;
1835c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  const ObjectFile *OwningObject;
1845c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
1855c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyerpublic:
186dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  LibraryRef() : OwningObject(nullptr) { }
1875c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
1885c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  LibraryRef(DataRefImpl LibraryP, const ObjectFile *Owner);
1895c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
1905c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  bool operator==(const LibraryRef &Other) const;
1915b957e6fd9853f938b8b33cfeb03d80595a9c2f8Eric Christopher  bool operator<(const LibraryRef &Other) const;
1925c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
193cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getNext(LibraryRef &Result) const;
1945c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
1955c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  // Get the path to this library, as stored in the object file.
196cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code getPath(StringRef &Result) const;
1975c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
1985c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  DataRefImpl getRawDataRefImpl() const;
1995c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer};
2005c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyertypedef content_iterator<LibraryRef> library_iterator;
2015c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
20268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer/// ObjectFile - This class is the base class for all object file types.
20368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer/// Concrete instances of this object are created by createObjectFile, which
20460f0819cb583799029fa11179576dd7f01d8002aEric Christopher/// figures out which type to create.
20536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesclass ObjectFile : public SymbolicFile {
2062d24e2a396a1d211baaeedf32148a3b657240170David Blaikie  virtual void anchor();
2079f9ce61972871efcf794bdc6125835c2c32cd863Craig Topper  ObjectFile() LLVM_DELETED_FUNCTION;
2089f9ce61972871efcf794bdc6125835c2c32cd863Craig Topper  ObjectFile(const ObjectFile &other) LLVM_DELETED_FUNCTION;
20968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
21068b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencerprotected:
211cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  ObjectFile(unsigned int Type, std::unique_ptr<MemoryBuffer> Source);
21268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
213001c9205fca2220480589ec355cb6ec701a37e08Michael J. Spencer  const uint8_t *base() const {
214001c9205fca2220480589ec355cb6ec701a37e08Michael J. Spencer    return reinterpret_cast<const uint8_t *>(Data->getBufferStart());
215001c9205fca2220480589ec355cb6ec701a37e08Michael J. Spencer  }
21668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
21768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  // These functions are for SymbolRef to call internally. The main goal of
21868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  // this is to allow SymbolRef::SymbolPimpl to point directly to the symbol
21968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  // entry in the memory mapped object file. SymbolPimpl cannot contain any
22068b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  // virtual functions because then it could not point into the memory mapped
22168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  // file.
22225b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer  //
22325b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer  // Implementations assume that the DataRefImpl is valid and has not been
22425b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer  // modified externally. It's UB otherwise.
22568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  friend class SymbolRef;
226cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSymbolName(DataRefImpl Symb,
227cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                        StringRef &Res) const = 0;
228cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  std::error_code printSymbolName(raw_ostream &OS,
229cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                  DataRefImpl Symb) const override;
230cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSymbolAddress(DataRefImpl Symb,
231cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                           uint64_t &Res) const = 0;
232cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSymbolAlignment(DataRefImpl Symb,
233cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                             uint32_t &Res) const;
234cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSymbolSize(DataRefImpl Symb,
235cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                        uint64_t &Res) const = 0;
236cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSymbolType(DataRefImpl Symb,
237cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                        SymbolRef::Type &Res) const = 0;
238cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSymbolSection(DataRefImpl Symb,
239cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                           section_iterator &Res) const = 0;
24068b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
24168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  // Same as above for SectionRef.
24268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  friend class SectionRef;
24336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
244cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSectionName(DataRefImpl Sec,
245cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                         StringRef &Res) const = 0;
246cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSectionAddress(DataRefImpl Sec,
247cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                            uint64_t &Res) const = 0;
248cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSectionSize(DataRefImpl Sec,
249cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                         uint64_t &Res) const = 0;
250cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSectionContents(DataRefImpl Sec,
251cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                             StringRef &Res) const = 0;
252cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getSectionAlignment(DataRefImpl Sec,
253cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                              uint64_t &Res) const = 0;
254cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code isSectionText(DataRefImpl Sec, bool &Res) const = 0;
255cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code isSectionData(DataRefImpl Sec, bool &Res) const = 0;
256cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code isSectionBSS(DataRefImpl Sec, bool &Res) const = 0;
257cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code isSectionRequiredForExecution(DataRefImpl Sec,
258cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                                        bool &Res) const = 0;
259c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd  // A section is 'virtual' if its contents aren't present in the object image.
260cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code isSectionVirtual(DataRefImpl Sec,
261cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                           bool &Res) const = 0;
262cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code isSectionZeroInit(DataRefImpl Sec,
263cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                            bool &Res) const = 0;
264cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code isSectionReadOnlyData(DataRefImpl Sec,
265cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                                bool &Res) const = 0;
266cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code sectionContainsSymbol(DataRefImpl Sec,
267cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                                DataRefImpl Symb,
268cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                                bool &Result) const = 0;
26929552222c2e7cbeb37fcd15d247597467f7b8544Rui Ueyama  virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
27029552222c2e7cbeb37fcd15d247597467f7b8544Rui Ueyama  virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
2717486d92a6c949a193bb75c0ffa0170eeb2fabb80Rafael Espindola  virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
27268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
2730fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  // Same as above for RelocationRef.
2740fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  friend class RelocationRef;
27536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
276cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getRelocationAddress(DataRefImpl Rel,
277cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                               uint64_t &Res) const = 0;
278cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getRelocationOffset(DataRefImpl Rel,
279cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                              uint64_t &Res) const = 0;
2806c1202c459ffa6d693ad92fa84e43902bc780bcaRafael Espindola  virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
281cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getRelocationType(DataRefImpl Rel,
282cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                            uint64_t &Res) const = 0;
283cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code
284cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  getRelocationTypeName(DataRefImpl Rel,
285cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                        SmallVectorImpl<char> &Result) const = 0;
286cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code
287cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  getRelocationValueString(DataRefImpl Rel,
288cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                           SmallVectorImpl<char> &Result) const = 0;
289cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getRelocationHidden(DataRefImpl Rel,
290cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                              bool &Result) const {
2910685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson    Result = false;
2920685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson    return object_error::success;
2930685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson  }
2940fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
2955c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  // Same for LibraryRef
2965c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  friend class LibraryRef;
297cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getLibraryNext(DataRefImpl Lib,
298cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                         LibraryRef &Res) const = 0;
299cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  virtual std::error_code getLibraryPath(DataRefImpl Lib,
300cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                         StringRef &Res) const = 0;
3015c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
30268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencerpublic:
30336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  typedef iterator_range<symbol_iterator> symbol_iterator_range;
30436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  symbol_iterator_range symbols() const {
30536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return symbol_iterator_range(symbol_begin(), symbol_end());
30636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
30768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
30836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual section_iterator section_begin() const = 0;
30936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual section_iterator section_end() const = 0;
310dfa1896b6b61e708f002b814794890ff308172eeMichael J. Spencer
31136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  typedef iterator_range<section_iterator> section_iterator_range;
31236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  section_iterator_range sections() const {
31336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return section_iterator_range(section_begin(), section_end());
31436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
31568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
31636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual library_iterator needed_library_begin() const = 0;
31736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual library_iterator needed_library_end() const = 0;
3185c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
31968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  /// @brief The number of bytes used to represent an address in this object
32068b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  ///        file format.
32168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  virtual uint8_t getBytesInAddress() const = 0;
32268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
32368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  virtual StringRef getFileFormatName() const = 0;
32488af6b9217f9ff8b4592f38ac5175de697275f49Michael J. Spencer  virtual /* Triple::ArchType */ unsigned getArch() const = 0;
32568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
32697f7787bfb56ad31fe20ec0bb9c3c9f3253d14fbDavid Meyer  /// For shared objects, returns the name which this object should be
32797f7787bfb56ad31fe20ec0bb9c3c9f3253d14fbDavid Meyer  /// loaded from at runtime. This corresponds to DT_SONAME on ELF and
32897f7787bfb56ad31fe20ec0bb9c3c9f3253d14fbDavid Meyer  /// LC_ID_DYLIB (install name) on MachO.
32997f7787bfb56ad31fe20ec0bb9c3c9f3253d14fbDavid Meyer  virtual StringRef getLoadName() const = 0;
33097f7787bfb56ad31fe20ec0bb9c3c9f3253d14fbDavid Meyer
33168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  /// @returns Pointer to ObjectFile subclass to handle this type of object.
33268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  /// @param ObjectPath The path to the object file. ObjectPath.isObject must
33368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  ///        return true.
33468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  /// @brief Create ObjectFile from path.
33536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath);
336cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  static ErrorOr<ObjectFile *>
337cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  createObjectFile(std::unique_ptr<MemoryBuffer> &Object,
338cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                   sys::fs::file_magic Type);
339cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  static ErrorOr<ObjectFile *>
340cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  createObjectFile(std::unique_ptr<MemoryBuffer> &Object) {
341cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    return createObjectFile(Object, sys::fs::file_magic::unknown);
34236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
34336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
34468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
345001c9205fca2220480589ec355cb6ec701a37e08Michael J. Spencer  static inline bool classof(const Binary *v) {
3466f9489a86f33624f9ff5388411d12359ce9cef20David Meyer    return v->isObject();
347001c9205fca2220480589ec355cb6ec701a37e08Michael J. Spencer  }
348001c9205fca2220480589ec355cb6ec701a37e08Michael J. Spencer
349001c9205fca2220480589ec355cb6ec701a37e08Michael J. Spencerpublic:
350cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  static ErrorOr<ObjectFile *>
351cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  createCOFFObjectFile(std::unique_ptr<MemoryBuffer> Object);
352cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  static ErrorOr<ObjectFile *>
353cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  createELFObjectFile(std::unique_ptr<MemoryBuffer> &Object);
354cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  static ErrorOr<ObjectFile *>
355cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  createMachOObjectFile(std::unique_ptr<MemoryBuffer> &Object);
35668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer};
35768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
35868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer// Inline function definitions.
35968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencerinline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
36036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    : BasicSymbolRef(SymbolP, Owner) {}
36168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
362cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SymbolRef::getName(StringRef &Result) const {
36336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return getObject()->getSymbolName(getRawDataRefImpl(), Result);
36468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
36568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
366cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SymbolRef::getAddress(uint64_t &Result) const {
36736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return getObject()->getSymbolAddress(getRawDataRefImpl(), Result);
36868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
36968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
370cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SymbolRef::getAlignment(uint32_t &Result) const {
37136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return getObject()->getSymbolAlignment(getRawDataRefImpl(), Result);
37259a0e79631ed851d98cf9c2ba6fa5f9aafdfdc93Rafael Espindola}
37359a0e79631ed851d98cf9c2ba6fa5f9aafdfdc93Rafael Espindola
374cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SymbolRef::getSize(uint64_t &Result) const {
37536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return getObject()->getSymbolSize(getRawDataRefImpl(), Result);
3769b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer}
3779b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
378cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SymbolRef::getSection(section_iterator &Result) const {
37936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return getObject()->getSymbolSection(getRawDataRefImpl(), Result);
3809b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer}
3819b2b812fea4df160437e7b7d56e38f6335189ad0Michael J. Spencer
382cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SymbolRef::getType(SymbolRef::Type &Result) const {
38336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return getObject()->getSymbolType(getRawDataRefImpl(), Result);
384a41dce3c642e50775352cce49e3a3d0cd004d393Tim Northover}
385a41dce3c642e50775352cce49e3a3d0cd004d393Tim Northover
38636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesinline const ObjectFile *SymbolRef::getObject() const {
38736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  const SymbolicFile *O = BasicSymbolRef::getObject();
38836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return cast<ObjectFile>(O);
38915c3f727aeff6a80e3f9e7e6b1284748e5f3322aNick Lewycky}
39015c3f727aeff6a80e3f9e7e6b1284748e5f3322aNick Lewycky
39168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
39268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer/// SectionRef
39368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencerinline SectionRef::SectionRef(DataRefImpl SectionP,
39468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer                              const ObjectFile *Owner)
39568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  : SectionPimpl(SectionP)
39668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  , OwningObject(Owner) {}
39768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
39868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencerinline bool SectionRef::operator==(const SectionRef &Other) const {
39968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer  return SectionPimpl == Other.SectionPimpl;
40068b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
40168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
40236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesinline bool SectionRef::operator!=(const SectionRef &Other) const {
40336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return SectionPimpl != Other.SectionPimpl;
40436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
40536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
4065b957e6fd9853f938b8b33cfeb03d80595a9c2f8Eric Christopherinline bool SectionRef::operator<(const SectionRef &Other) const {
4073314c26475b5561abbfe0785e0a64d189d5b4060Michael J. Spencer  return SectionPimpl < Other.SectionPimpl;
4083314c26475b5561abbfe0785e0a64d189d5b4060Michael J. Spencer}
4093314c26475b5561abbfe0785e0a64d189d5b4060Michael J. Spencer
41036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesinline void SectionRef::moveNext() {
41136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return OwningObject->moveSectionNext(SectionPimpl);
41268b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
41368b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
414cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::getName(StringRef &Result) const {
41525b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer  return OwningObject->getSectionName(SectionPimpl, Result);
41668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
41768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
418cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::getAddress(uint64_t &Result) const {
41925b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer  return OwningObject->getSectionAddress(SectionPimpl, Result);
42068b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
42168b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
422cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::getSize(uint64_t &Result) const {
42325b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer  return OwningObject->getSectionSize(SectionPimpl, Result);
42468b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
42568b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
426cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::getContents(StringRef &Result) const {
42725b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer  return OwningObject->getSectionContents(SectionPimpl, Result);
42868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
42968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
430cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::getAlignment(uint64_t &Result) const {
431e2f2f07be7cf2b55b7e5501291bbcede87e43fd6Michael J. Spencer  return OwningObject->getSectionAlignment(SectionPimpl, Result);
432e2f2f07be7cf2b55b7e5501291bbcede87e43fd6Michael J. Spencer}
433e2f2f07be7cf2b55b7e5501291bbcede87e43fd6Michael J. Spencer
434cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::isText(bool &Result) const {
43525b15777df42d5d608810f6881b6c98107481d69Michael J. Spencer  return OwningObject->isSectionText(SectionPimpl, Result);
43668b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer}
43768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
438cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::isData(bool &Result) const {
43913afc5eff2d7370ab486d5039886ab8bbf9039daMichael J. Spencer  return OwningObject->isSectionData(SectionPimpl, Result);
44013afc5eff2d7370ab486d5039886ab8bbf9039daMichael J. Spencer}
44113afc5eff2d7370ab486d5039886ab8bbf9039daMichael J. Spencer
442cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::isBSS(bool &Result) const {
44313afc5eff2d7370ab486d5039886ab8bbf9039daMichael J. Spencer  return OwningObject->isSectionBSS(SectionPimpl, Result);
44413afc5eff2d7370ab486d5039886ab8bbf9039daMichael J. Spencer}
44513afc5eff2d7370ab486d5039886ab8bbf9039daMichael J. Spencer
446cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::isRequiredForExecution(bool &Result) const {
447c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd  return OwningObject->isSectionRequiredForExecution(SectionPimpl, Result);
448c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd}
449c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd
450cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::isVirtual(bool &Result) const {
451c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd  return OwningObject->isSectionVirtual(SectionPimpl, Result);
452c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd}
453c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd
454cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::isZeroInit(bool &Result) const {
455c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd  return OwningObject->isSectionZeroInit(SectionPimpl, Result);
456c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd}
457c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd
458cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::isReadOnlyData(bool &Result) const {
4593a129c85920404e7ccdb7e655c89fa60a0309cfdAndrew Kaylor  return OwningObject->isSectionReadOnlyData(SectionPimpl, Result);
4603a129c85920404e7ccdb7e655c89fa60a0309cfdAndrew Kaylor}
4613a129c85920404e7ccdb7e655c89fa60a0309cfdAndrew Kaylor
462cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code SectionRef::containsSymbol(SymbolRef S,
463cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                                  bool &Result) const {
46436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return OwningObject->sectionContainsSymbol(SectionPimpl,
46536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                             S.getRawDataRefImpl(), Result);
46607ea23aa2d17f701fa125442c20c1eba75b55fdbBenjamin Kramer}
46707ea23aa2d17f701fa125442c20c1eba75b55fdbBenjamin Kramer
46836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesinline relocation_iterator SectionRef::relocation_begin() const {
46929552222c2e7cbeb37fcd15d247597467f7b8544Rui Ueyama  return OwningObject->section_rel_begin(SectionPimpl);
4704344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer}
4714344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer
47236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesinline relocation_iterator SectionRef::relocation_end() const {
47329552222c2e7cbeb37fcd15d247597467f7b8544Rui Ueyama  return OwningObject->section_rel_end(SectionPimpl);
4744344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer}
4754344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer
4767486d92a6c949a193bb75c0ffa0170eeb2fabb80Rafael Espindolainline section_iterator SectionRef::getRelocatedSection() const {
4777486d92a6c949a193bb75c0ffa0170eeb2fabb80Rafael Espindola  return OwningObject->getRelocatedSection(SectionPimpl);
4787486d92a6c949a193bb75c0ffa0170eeb2fabb80Rafael Espindola}
4797486d92a6c949a193bb75c0ffa0170eeb2fabb80Rafael Espindola
480c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurdinline DataRefImpl SectionRef::getRawDataRefImpl() const {
481c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd  return SectionPimpl;
482c68dda815e64fb2fb463318d1eaa304e22199d50Preston Gurd}
4830fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
4840fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer/// RelocationRef
4850fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramerinline RelocationRef::RelocationRef(DataRefImpl RelocationP,
4860fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer                              const ObjectFile *Owner)
4870fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  : RelocationPimpl(RelocationP)
4880fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  , OwningObject(Owner) {}
4890fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
4900fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramerinline bool RelocationRef::operator==(const RelocationRef &Other) const {
4910fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  return RelocationPimpl == Other.RelocationPimpl;
4920fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer}
4930fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
49436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesinline void RelocationRef::moveNext() {
49536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return OwningObject->moveRelocationNext(RelocationPimpl);
4960fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer}
4970fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
498cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code RelocationRef::getAddress(uint64_t &Result) const {
4990fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  return OwningObject->getRelocationAddress(RelocationPimpl, Result);
5000fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer}
5010fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
502cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code RelocationRef::getOffset(uint64_t &Result) const {
503b0436a73054fe676b216a0cf872d1fc433125c62Danil Malyshev  return OwningObject->getRelocationOffset(RelocationPimpl, Result);
504b0436a73054fe676b216a0cf872d1fc433125c62Danil Malyshev}
505b0436a73054fe676b216a0cf872d1fc433125c62Danil Malyshev
5066c1202c459ffa6d693ad92fa84e43902bc780bcaRafael Espindolainline symbol_iterator RelocationRef::getSymbol() const {
5076c1202c459ffa6d693ad92fa84e43902bc780bcaRafael Espindola  return OwningObject->getRelocationSymbol(RelocationPimpl);
5080fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer}
5090fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
510cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code RelocationRef::getType(uint64_t &Result) const {
5110fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer  return OwningObject->getRelocationType(RelocationPimpl, Result);
5120fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer}
5130fcab076f0358890e2f1b213f4303c780e05d99dBenjamin Kramer
514cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code
515cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen HinesRelocationRef::getTypeName(SmallVectorImpl<char> &Result) const {
5164344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
5174344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer}
5184344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer
519cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code
520cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen HinesRelocationRef::getValueString(SmallVectorImpl<char> &Result) const {
5214344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer  return OwningObject->getRelocationValueString(RelocationPimpl, Result);
5224344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer}
5234344b1ef9b3721a5ebc2e024f753772a1e4ddd92Michael J. Spencer
524cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code RelocationRef::getHidden(bool &Result) const {
5250685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson  return OwningObject->getRelocationHidden(RelocationPimpl, Result);
5260685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson}
5279ac0f1d7255d7941c331b0a62a830a3b033358fdMarshall Clow
5289ac0f1d7255d7941c331b0a62a830a3b033358fdMarshall Clowinline DataRefImpl RelocationRef::getRawDataRefImpl() const {
5299ac0f1d7255d7941c331b0a62a830a3b033358fdMarshall Clow  return RelocationPimpl;
5309ac0f1d7255d7941c331b0a62a830a3b033358fdMarshall Clow}
5319ac0f1d7255d7941c331b0a62a830a3b033358fdMarshall Clow
532167957fa095bc7200b908e6e142be3e604bcfeeaRafael Espindolainline const ObjectFile *RelocationRef::getObjectFile() const {
533167957fa095bc7200b908e6e142be3e604bcfeeaRafael Espindola  return OwningObject;
534167957fa095bc7200b908e6e142be3e604bcfeeaRafael Espindola}
535167957fa095bc7200b908e6e142be3e604bcfeeaRafael Espindola
5365c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer// Inline function definitions.
5375c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyerinline LibraryRef::LibraryRef(DataRefImpl LibraryP, const ObjectFile *Owner)
5385c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  : LibraryPimpl(LibraryP)
5395c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  , OwningObject(Owner) {}
5405c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
5415c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyerinline bool LibraryRef::operator==(const LibraryRef &Other) const {
5425c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  return LibraryPimpl == Other.LibraryPimpl;
5435c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer}
5445c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
5455b957e6fd9853f938b8b33cfeb03d80595a9c2f8Eric Christopherinline bool LibraryRef::operator<(const LibraryRef &Other) const {
5465c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  return LibraryPimpl < Other.LibraryPimpl;
5475c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer}
5485c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
549cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code LibraryRef::getNext(LibraryRef &Result) const {
5505c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  return OwningObject->getLibraryNext(LibraryPimpl, Result);
5515c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer}
5525c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer
553cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesinline std::error_code LibraryRef::getPath(StringRef &Result) const {
5545c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer  return OwningObject->getLibraryPath(LibraryPimpl, Result);
5555c2b4ea73c8f48bb5f96c86fe437385b8fb3dcdaDavid Meyer}
5560685e94895f26f96aa1032696e3150dd00aad1f3Owen Anderson
55768b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer} // end namespace object
55868b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer} // end namespace llvm
55968b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer
56068b3f0c40e29e461dbbc85370078692df4336b42Michael J. Spencer#endif
561