1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
17 * \brief Executable and Link Format (ELF) parser.
22 /** Construct with the name of the ELF input file to parse. */
23 cmELF(const char* fname);
28 cmELF(const cmELF&) = delete;
29 cmELF& operator=(const cmELF&) = delete;
31 /** Get the error message if any. */
32 std::string const& GetErrorMessage() const { return this->ErrorMessage; }
34 /** Boolean conversion. True if the ELF file is valid. */
35 explicit operator bool() const { return this->Valid(); }
37 /** Enumeration of ELF file types. */
41 FileTypeRelocatableObject,
43 FileTypeSharedLibrary,
49 /** Represent string table entries. */
52 // The string value itself.
55 // The position in the file at which the string appears.
56 unsigned long Position;
58 // The size of the string table entry. This includes the space
59 // allocated for one or more null terminators.
62 // The index of the section entry referencing the string.
66 /** Represent entire dynamic section header */
67 using DynamicEntryList = std::vector<std::pair<long, unsigned long>>;
69 /** Get the type of the file opened. */
70 FileType GetFileType() const;
72 /** Get the machine of the file opened. */
73 std::uint16_t GetMachine() const;
75 /** Get the number of ELF sections present. */
76 unsigned int GetNumberOfSections() const;
78 /** Get the position of a DYNAMIC section header entry. Returns
80 unsigned long GetDynamicEntryPosition(int index) const;
82 /** Get a copy of all the DYNAMIC section header entries.
83 Returns an empty vector on error */
84 DynamicEntryList GetDynamicEntries() const;
86 /** Encodes a DYNAMIC section header entry list into a char vector according
87 to the type of ELF file this is */
88 std::vector<char> EncodeDynamicEntries(
89 const DynamicEntryList& entries) const;
91 /** Get the SONAME field if any. */
92 bool GetSOName(std::string& soname);
93 StringEntry const* GetSOName();
95 /** Get the RPATH field if any. */
96 StringEntry const* GetRPath();
98 /** Get the RUNPATH field if any. */
99 StringEntry const* GetRunPath();
101 /** Returns true if the ELF file targets a MIPS CPU. */
104 /** Print human-readable information about the ELF file. */
105 void PrintInfo(std::ostream& os) const;
107 /** Interesting dynamic tags.
108 If the tag is 0, it does not exist in the host ELF implementation */
109 static const long TagRPath, TagRunPath, TagMipsRldMapRel;
112 friend class cmELFInternal;
114 std::unique_ptr<cmELFInternal> Internal;
115 std::string ErrorMessage;