LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
SymbolVersion.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_ELF_SYMBOL_VERSION_H
16#define LIEF_ELF_SYMBOL_VERSION_H
17#include <cassert>
18#include <cstdint>
19#include <ostream>
20
21#include "LIEF/Object.hpp"
22#include "LIEF/visibility.h"
23
24
25namespace LIEF::ELF {
26class Parser;
29
33 friend class Parser;
34
35 public:
36 static constexpr uint16_t LOCAL_VERSION = 0;
37 static constexpr uint16_t GLOBAL_VERSION = 1;
38
40 static constexpr uint16_t HIDDEN_MASK = 0x8000;
41
43 static constexpr uint16_t VERSION_MASK = 0x7fff;
44
45 SymbolVersion(uint16_t value) :
46 value_(value) {}
47 SymbolVersion() = default;
48
51 return LOCAL_VERSION;
52 }
53
56 return GLOBAL_VERSION;
57 }
58
59 ~SymbolVersion() override = default;
60
62 SymbolVersion(const SymbolVersion&) = default;
63
70 uint16_t value() const {
71 return value_;
72 }
73
75 uint16_t version() const {
76 return value() & VERSION_MASK;
77 }
78
80 bool is_local() const {
81 return version() == LOCAL_VERSION;
82 }
83
88 bool is_global() const {
89 return version() == GLOBAL_VERSION;
90 }
91
96 bool is_hidden() const {
97 return (value() & HIDDEN_MASK) != 0;
98 }
99
102 void set_hidden(bool value = true) {
103 if (value) {
104 value_ |= HIDDEN_MASK;
105 } else {
106 value_ &= VERSION_MASK;
107 }
108 }
109
112 return symbol_version_auxiliary() != nullptr;
113 }
114
120
122 return symbol_aux_;
123 }
124
132
134 void drop_version(uint16_t value) {
135 assert(value == LOCAL_VERSION || value == GLOBAL_VERSION);
136 value_ = value;
137 symbol_aux_ = nullptr;
138 }
139
143 void as_global() {
145 }
146
150 void as_local() {
152 }
153
154 void value(uint16_t v) {
155 value_ = v;
156 }
157
158 void accept(Visitor& visitor) const override;
159
160 LIEF_API friend std::ostream& operator<<(std::ostream& os,
161 const SymbolVersion& symv);
162
163 private:
164 uint16_t value_ = 0;
165 SymbolVersionAux* symbol_aux_ = nullptr;
166};
167}
168
169#endif
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:46
Definition SymbolVersionAuxRequirement.hpp:32
Class which represents an Auxiliary Symbol version.
Definition SymbolVersionAux.hpp:31
static constexpr uint16_t LOCAL_VERSION
Definition SymbolVersion.hpp:36
static constexpr uint16_t GLOBAL_VERSION
Definition SymbolVersion.hpp:37
const SymbolVersionAux * symbol_version_auxiliary() const
Definition SymbolVersion.hpp:121
bool has_auxiliary_version() const
Whether the current SymbolVersion has an auxiliary one.
Definition SymbolVersion.hpp:111
SymbolVersion & operator=(const SymbolVersion &)=default
static constexpr uint16_t VERSION_MASK
Mask for the version index (VERSYM_VERSION in the GNU implementation).
Definition SymbolVersion.hpp:43
void drop_version(uint16_t value)
Drop the versioning requirement and replace the value (local/global).
Definition SymbolVersion.hpp:134
static SymbolVersion local()
Generate a local SymbolVersion.
Definition SymbolVersion.hpp:50
uint16_t version() const
Version index without the GNU VERSYM_HIDDEN bit.
Definition SymbolVersion.hpp:75
static constexpr uint16_t HIDDEN_MASK
Mask for the GNU VERSYM_HIDDEN bit.
Definition SymbolVersion.hpp:40
bool is_hidden() const
Whether the GNU VERSYM_HIDDEN bit is set.
Definition SymbolVersion.hpp:96
bool is_global() const
Whether this symbol version is global (VER_NDX_GLOBAL).
Definition SymbolVersion.hpp:88
~SymbolVersion() override=default
bool is_local() const
Whether this symbol version is local (VER_NDX_LOCAL).
Definition SymbolVersion.hpp:80
friend std::ostream & operator<<(std::ostream &os, const SymbolVersion &symv)
void accept(Visitor &visitor) const override
SymbolVersion(const SymbolVersion &)=default
friend class Parser
Definition SymbolVersion.hpp:33
void symbol_version_auxiliary(SymbolVersionAuxRequirement &svauxr)
Set the version's auxiliary requirement The given SymbolVersionAuxRequirement must be an existing ref...
static SymbolVersion global()
Generate a global SymbolVersion.
Definition SymbolVersion.hpp:55
void as_local()
Redefine this version as local by dropping its auxiliary version.
Definition SymbolVersion.hpp:150
void as_global()
Redefine this version as global by dropping its auxiliary version.
Definition SymbolVersion.hpp:143
SymbolVersion(uint16_t value)
Definition SymbolVersion.hpp:45
void value(uint16_t v)
Definition SymbolVersion.hpp:154
void set_hidden(bool value=true)
Set or clear the GNU VERSYM_HIDDEN bit while preserving the version index.
Definition SymbolVersion.hpp:102
SymbolVersionAux * symbol_version_auxiliary()
SymbolVersionAux associated with the current Version if any, or a nullptr.
Definition SymbolVersion.hpp:117
uint16_t value() const
Value associated with the symbol.
Definition SymbolVersion.hpp:70
Definition Object.hpp:24
Definition Visitor.hpp:211
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:27
#define LIEF_API
Definition visibility.h:44