Bartleby 0.1.0
A symbol renaming toolkit
Loading...
Searching...
No Matches
Symbol.h
Go to the documentation of this file.
1// Copyright 2023 SandboxAQ
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
20
21#pragma once
22
23#include "llvm/Object/ObjectFile.h"
24
25#include <optional>
26
27namespace saq::bartleby {
28
30struct SymbolInfo {
32 llvm::object::SymbolRef Sym;
33
35 std::optional<llvm::object::SymbolRef::Type> Type;
36
38 std::optional<uint32_t> Flags;
39
41 std::optional<llvm::StringRef> Name;
42
44 llvm::Triple::ObjectFormatType ObjectType =
45 llvm::Triple::ObjectFormatType::UnknownObjectFormat;
46
48 bool Err = false;
49};
50
52class Symbol {
53public:
57 [[nodiscard]] bool isGlobal() const noexcept;
58
62 [[nodiscard]] bool isDefined() const noexcept;
63
67 [[nodiscard]] size_t getReferences() const noexcept;
68
72 [[nodiscard]] std::optional<llvm::StringRef>
73 getOverwriteName() const noexcept;
74
80 [[nodiscard]] bool isMachO() const noexcept;
81
85 void setName(std::string Name) noexcept;
86
90 void updateWithNewSymbolInfo(const SymbolInfo &Syminfo) noexcept;
91
93 Symbol() noexcept;
94
95 Symbol(const Symbol &) noexcept = delete;
96 Symbol(Symbol &&) noexcept = default;
97 Symbol &operator=(const Symbol &) noexcept = delete;
98 Symbol &operator=(Symbol &&) noexcept = default;
99 ~Symbol() noexcept = default;
100
101private:
103 std::optional<std::string> OverwriteName;
104
106 llvm::Triple::ObjectFormatType Type =
107 llvm::Triple::ObjectFormatType::UnknownObjectFormat;
108
110 bool Global = false;
111
113 bool Defined = false;
114};
115
116} // end namespace saq::bartleby
An high view of a symbol.
Definition: Symbol.h:52
size_t getReferences() const noexcept
Counts how many times this symbol is referenced.
std::optional< llvm::StringRef > getOverwriteName() const noexcept
Returns the overwrite name.
Definition: Symbol.cpp:65
void setName(std::string Name) noexcept
Sets the name of the symbol.
Definition: Symbol.cpp:56
bool isGlobal() const noexcept
Returns the visibility of the symbol.
Definition: Symbol.cpp:60
void updateWithNewSymbolInfo(const SymbolInfo &Syminfo) noexcept
Updates the symbol with new symbol information.
Definition: Symbol.cpp:35
bool isMachO() const noexcept
Returns true if the symbol contains references to some mach-o symbols.
Definition: Symbol.cpp:52
bool isDefined() const noexcept
Returns the definedness of the symbol.
Definition: Symbol.cpp:62
Various information about a symbol.
Definition: Symbol.h:30
std::optional< llvm::StringRef > Name
Its name.
Definition: Symbol.h:41
bool Err
An error occurred.
Definition: Symbol.h:48
std::optional< uint32_t > Flags
Its flags.
Definition: Symbol.h:38
std::optional< llvm::object::SymbolRef::Type > Type
Its type.
Definition: Symbol.h:35
llvm::Triple::ObjectFormatType ObjectType
Type of the object it belongs to.
Definition: Symbol.h:44
llvm::object::SymbolRef Sym
The symbol.
Definition: Symbol.h:32