packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmELF.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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 ============================================================================*/
12 #ifndef cmELF_h
13 #define cmELF_h
14
15 #if !defined(CMAKE_USE_ELF_PARSER)
16 # error "This file may be included only if CMAKE_USE_ELF_PARSER is enabled."
17 #endif
18
19 class cmELFInternal;
20
21 /** \class cmELF
22  * \brief Executable and Link Format (ELF) parser.
23  */
24 class cmELF
25 {
26 public:
27   /** Construct with the name of the ELF input file to parse.  */
28   cmELF(const char* fname);
29
30   /** Destruct.   */
31   ~cmELF();
32
33   /** Get the error message if any.  */
34   std::string const& GetErrorMessage() const
35     {
36     return this->ErrorMessage;
37     }
38
39   /** Boolean conversion.  True if the ELF file is valid.  */
40   operator bool() const { return this->Valid(); }
41
42   /** Enumeration of ELF file types.  */
43   enum FileType
44   {
45     FileTypeInvalid,
46     FileTypeRelocatableObject,
47     FileTypeExecutable,
48     FileTypeSharedLibrary,
49     FileTypeCore,
50     FileTypeSpecificOS,
51     FileTypeSpecificProc
52   };
53
54   /** Represent string table entries.  */
55   struct StringEntry
56   {
57     // The string value itself.
58     std::string Value;
59
60     // The position in the file at which the string appears.
61     unsigned long Position;
62
63     // The size of the string table entry.  This includes the space
64     // allocated for one or more null terminators.
65     unsigned long Size;
66
67     // The index of the section entry referencing the string.
68     int IndexInSection;
69   };
70
71   /** Get the type of the file opened.  */
72   FileType GetFileType() const;
73
74   /** Get the number of ELF sections present.  */
75   unsigned int GetNumberOfSections() const;
76
77   /** Get the number of DYNAMIC section entries before the first
78       DT_NULL.  Returns zero on error.  */
79   unsigned int GetDynamicEntryCount() const;
80
81   /** Get the position of a DYNAMIC section header entry.  Returns
82       zero on error.  */
83   unsigned long GetDynamicEntryPosition(int index) const;
84
85   /** Read bytes from the file.  */
86   bool ReadBytes(unsigned long pos, unsigned long size, char* buf) const;
87
88   /** Get the SONAME field if any.  */
89   bool GetSOName(std::string& soname);
90   StringEntry const* GetSOName();
91
92   /** Get the RPATH field if any.  */
93   StringEntry const* GetRPath();
94
95   /** Get the RUNPATH field if any.  */
96   StringEntry const* GetRunPath();
97
98   /** Print human-readable information about the ELF file.  */
99   void PrintInfo(std::ostream& os) const;
100
101 private:
102   friend class cmELFInternal;
103   bool Valid() const;
104   cmELFInternal* Internal;
105   std::string ErrorMessage;
106 };
107
108 #endif