LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
SymbolVersion.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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 <ostream>
19#include <cstdint>
20#include <cassert>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24
25namespace LIEF {
26namespace ELF {
27class Parser;
30class LIEF_API SymbolVersion : public Object {
34 friend class Parser;
35
36 public:
37 static constexpr auto LOCAL_VERSION = 0;
38 static constexpr auto GLOBAL_VERSION = 1;
39
40 SymbolVersion(uint16_t value) :
41 value_(value)
42 {}
43 SymbolVersion() = default;
44 static SymbolVersion local() {
47 return SymbolVersion(LOCAL_VERSION);
48 }
49 static SymbolVersion global() {
52 return SymbolVersion(GLOBAL_VERSION);
53 }
54
55 ~SymbolVersion() override = default;
56
57 SymbolVersion& operator=(const SymbolVersion&) = default;
58 SymbolVersion(const SymbolVersion&) = default;
59 uint16_t value() const {
67 return value_;
68 }
69 bool has_auxiliary_version() const {
72 return symbol_version_auxiliary() != nullptr;
73 }
74 SymbolVersionAux* symbol_version_auxiliary() {
78 return symbol_aux_;
79 }
80
81 const SymbolVersionAux* symbol_version_auxiliary() const {
82 return symbol_aux_;
83 }
84 void symbol_version_auxiliary(SymbolVersionAuxRequirement& svauxr);
92 void drop_version(uint16_t value) {
95 if (symbol_aux_ == nullptr) {
96 return;
97 }
98 assert(value == LOCAL_VERSION || value == GLOBAL_VERSION);
99 value_ = value;
100 symbol_aux_ = nullptr;
101 }
102 void as_global() {
107 return drop_version(GLOBAL_VERSION);
108 }
109 void as_local() {
114 return drop_version(LOCAL_VERSION);
115 }
116
117 void value(uint16_t v) {
118 value_ = v;
119 }
120
121 void accept(Visitor& visitor) const override;
122
123 LIEF_API friend std::ostream& operator<<(std::ostream& os, const SymbolVersion& symv);
124
125 private:
126 uint16_t value_ = 0;
127 SymbolVersionAux* symbol_aux_ = nullptr;
128};
129}
130}
131#endif
Object.hpp
LIEF::ELF::Parser
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
LIEF::ELF::SymbolVersionAuxRequirement
Definition SymbolVersionAuxRequirement.hpp:35
LIEF::ELF::SymbolVersionAux
Class which represents an Auxiliary Symbol version.
Definition SymbolVersionAux.hpp:30
LIEF::ELF::SymbolVersion
Class which represents an entry defined in the DT_VERSYM dynamic entry.
Definition SymbolVersion.hpp:33
LIEF::ELF::SymbolVersion::symbol_version_auxiliary
const SymbolVersionAux * symbol_version_auxiliary() const
Definition SymbolVersion.hpp:81
LIEF::ELF::SymbolVersion::has_auxiliary_version
bool has_auxiliary_version() const
Whether the current SymbolVersion has an auxiliary one.
Definition SymbolVersion.hpp:71
LIEF::ELF::SymbolVersion::operator=
SymbolVersion & operator=(const SymbolVersion &)=default
LIEF::ELF::SymbolVersion::drop_version
void drop_version(uint16_t value)
Drop the versioning requirement and replace the value (local/global)
Definition SymbolVersion.hpp:94
LIEF::ELF::SymbolVersion::local
static SymbolVersion local()
Generate a local SymbolVersion.
Definition SymbolVersion.hpp:46
LIEF::ELF::SymbolVersion::SymbolVersion
SymbolVersion()=default
LIEF::ELF::SymbolVersion::~SymbolVersion
~SymbolVersion() override=default
LIEF::ELF::SymbolVersion::operator<<
friend std::ostream & operator<<(std::ostream &os, const SymbolVersion &symv)
LIEF::ELF::SymbolVersion::accept
void accept(Visitor &visitor) const override
LIEF::ELF::SymbolVersion::SymbolVersion
SymbolVersion(const SymbolVersion &)=default
LIEF::ELF::SymbolVersion::symbol_version_auxiliary
void symbol_version_auxiliary(SymbolVersionAuxRequirement &svauxr)
Set the version's auxiliary requirement The given SymbolVersionAuxRequirement must be an existing ref...
LIEF::ELF::SymbolVersion::global
static SymbolVersion global()
Generate a global SymbolVersion.
Definition SymbolVersion.hpp:51
LIEF::ELF::SymbolVersion::as_local
void as_local()
Redefine this version as local by dropping its auxiliary version.
Definition SymbolVersion.hpp:113
LIEF::ELF::SymbolVersion::as_global
void as_global()
Redefine this version as global by dropping its auxiliary version.
Definition SymbolVersion.hpp:106
LIEF::ELF::SymbolVersion::SymbolVersion
SymbolVersion(uint16_t value)
Definition SymbolVersion.hpp:40
LIEF::ELF::SymbolVersion::value
void value(uint16_t v)
Definition SymbolVersion.hpp:117
LIEF::ELF::SymbolVersion::symbol_version_auxiliary
SymbolVersionAux * symbol_version_auxiliary()
SymbolVersionAux associated with the current Version if any, or a nullptr.
Definition SymbolVersion.hpp:77
LIEF::ELF::SymbolVersion::value
uint16_t value() const
Value associated with the symbol.
Definition SymbolVersion.hpp:66
LIEF::ELF
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:39
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41