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