1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
15 #if !defined(CMAKE_USE_ELF_PARSER)
16 # error "This file may be included only if CMAKE_USE_ELF_PARSER is enabled."
22 * \brief Executable and Link Format (ELF) parser.
27 /** Construct with the name of the ELF input file to parse. */
28 cmELF(const char* fname);
33 /** Get the error message if any. */
34 std::string const& GetErrorMessage() const
36 return this->ErrorMessage;
39 /** Boolean conversion. True if the ELF file is valid. */
40 operator bool() const { return this->Valid(); }
42 /** Enumeration of ELF file types. */
46 FileTypeRelocatableObject,
48 FileTypeSharedLibrary,
54 /** Represent string table entries. */
57 // The string value itself.
60 // The position in the file at which the string appears.
61 unsigned long Position;
63 // The size of the string table entry. This includes the space
64 // allocated for one or more null terminators.
67 // The index of the section entry referencing the string.
71 /** Get the type of the file opened. */
72 FileType GetFileType() const;
74 /** Get the number of ELF sections present. */
75 unsigned int GetNumberOfSections() const;
77 /** Get the number of DYNAMIC section entries before the first
78 DT_NULL. Returns zero on error. */
79 unsigned int GetDynamicEntryCount() const;
81 /** Get the position of a DYNAMIC section header entry. Returns
83 unsigned long GetDynamicEntryPosition(int index) const;
85 /** Read bytes from the file. */
86 bool ReadBytes(unsigned long pos, unsigned long size, char* buf) const;
88 /** Get the SONAME field if any. */
89 bool GetSOName(std::string& soname);
90 StringEntry const* GetSOName();
92 /** Get the RPATH field if any. */
93 StringEntry const* GetRPath();
95 /** Get the RUNPATH field if any. */
96 StringEntry const* GetRunPath();
98 /** Print human-readable information about the ELF file. */
99 void PrintInfo(std::ostream& os) const;
102 friend class cmELFInternal;
104 cmELFInternal* Internal;
105 std::string ErrorMessage;