ENH: check in almost building VMS stuff with VMSBuild directory since the bootstrap...
[cmake.git] / Source / cmELF.h
blob75c755ad03bf1237b9dcba7aa9f613aa5eb349c2
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmELF.h,v $
5 Language: C++
6 Date: $Date: 2008-04-14 19:02:24 $
7 Version: $Revision: 1.5 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmELF_h
18 #define cmELF_h
20 #if !defined(CMAKE_USE_ELF_PARSER)
21 # error "This file may be included only if CMAKE_USE_ELF_PARSER is enabled."
22 #endif
24 class cmELFInternal;
26 /** \class cmELF
27 * \brief Executable and Link Format (ELF) parser.
29 class cmELF
31 public:
32 /** Construct with the name of the ELF input file to parse. */
33 cmELF(const char* fname);
35 /** Destruct. */
36 ~cmELF();
38 /** Get the error message if any. */
39 std::string const& GetErrorMessage() const
41 return this->ErrorMessage;
44 /** Boolean conversion. True if the ELF file is valid. */
45 operator bool() const { return this->Valid(); }
47 /** Enumeration of ELF file types. */
48 enum FileType
50 FileTypeInvalid,
51 FileTypeRelocatableObject,
52 FileTypeExecutable,
53 FileTypeSharedLibrary,
54 FileTypeCore,
55 FileTypeSpecificOS,
56 FileTypeSpecificProc
59 /** Represent string table entries. */
60 struct StringEntry
62 // The string value itself.
63 std::string Value;
65 // The position in the file at which the string appears.
66 unsigned long Position;
68 // The size of the string table entry. This includes the space
69 // allocated for one or more null terminators.
70 unsigned long Size;
72 // The index of the section entry referencing the string.
73 int IndexInSection;
76 /** Get the type of the file opened. */
77 FileType GetFileType() const;
79 /** Get the number of ELF sections present. */
80 unsigned int GetNumberOfSections() const;
82 /** Get the number of DYNAMIC section entries before the first
83 DT_NULL. Returns zero on error. */
84 unsigned int GetDynamicEntryCount() const;
86 /** Get the position of a DYNAMIC section header entry. Returns
87 zero on error. */
88 unsigned long GetDynamicEntryPosition(int index) const;
90 /** Read bytes from the file. */
91 bool ReadBytes(unsigned long pos, unsigned long size, char* buf) const;
93 /** Get the SONAME field if any. */
94 bool GetSOName(std::string& soname);
95 StringEntry const* GetSOName();
97 /** Get the RPATH field if any. */
98 StringEntry const* GetRPath();
100 /** Get the RUNPATH field if any. */
101 StringEntry const* GetRunPath();
103 /** Print human-readable information about the ELF file. */
104 void PrintInfo(std::ostream& os) const;
106 private:
107 friend class cmELFInternal;
108 bool Valid() const;
109 cmELFInternal* Internal;
110 std::string ErrorMessage;
113 #endif