MatN work for versatile appimage creation for all types of os
[goodguy/cinelerra.git] / cinelerra-5.1 / tools / makeappimagetool / includes / elf_file.h
1 // system includes
2 #include <vector>
3 #include <string>
4 // including system elf header, which allows for interpretation of the return values of the methods
5 #include <elf.h>
6
7 // library includes
8 #include <boost/filesystem.hpp>
9
10 #pragma once
11
12 namespace linuxdeploy {
13     namespace core {
14         namespace elf_file {
15             // thrown by constructor if file is not an ELF file
16             class ElfFileParseError : public std::runtime_error {
17                 public:
18                     explicit ElfFileParseError(const std::string& msg) : std::runtime_error(msg) {}
19             };
20
21             // thrown by traceDynamicDependencies() if a dependency is missing
22             class DependencyNotFoundError : public std::runtime_error {
23                 public:
24                     explicit DependencyNotFoundError(const std::string& msg) : std::runtime_error(msg) {}
25             };
26
27             class ElfFile {
28                 private:
29                     class PrivateData;
30                     PrivateData* d;
31
32                 public:
33                     explicit ElfFile(const boost::filesystem::path& path);
34                     ~ElfFile();
35
36                 public:
37                     // return system ELF OS ABI
38                     static uint8_t getSystemElfABI();
39
40                     // return system ELF class (32-bit or 64-bit)
41                     static uint8_t getSystemElfClass();
42
43                     // return system (ELF) endianness
44                     static uint8_t getSystemElfEndianness();
45
46                 public:
47                     // recursively trace dynamic library dependencies of a given ELF file
48                     // this works for both libraries and executables
49                     // the resulting vector consists of absolute paths to the libraries determined by the same methods a system's
50                     // linker would use
51                     std::vector<boost::filesystem::path> traceDynamicDependencies();
52
53                     // fetch rpath stored in binary
54                     // it appears that according to the ELF standard, the rpath is ignored in libraries, therefore if the path
55                     // points to an executable, an empty string is returned
56                     std::string getRPath();
57
58                     // set rpath in ELF file
59                     // returns true on success, false otherwise
60                     bool setRPath(const std::string& value);
61
62                     // return ELF class
63                     uint8_t getElfClass();
64
65                     // return OS ABI
66                     uint8_t getElfABI();
67
68                     // check if this file is a debug symbols file
69                     bool isDebugSymbolsFile();
70
71                     // check whether the file contains a dynsym section
72                     bool isDynamicallyLinked();
73             };
74         }
75     }
76 }