RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
symbol_definition.h
1#ifndef SYMBOL_DEFINITION_H
2#define SYMBOL_DEFINITION_H
3
4#include <iostream>
5#include <optional>
6#include <string>
7#include "../common.h"
8#include "location.h"
9
10namespace Linker
11{
16 {
17 public:
18 std::string name;
34 binding_type binding = Undefined;
35 Location location;
36 offset_t size = 0, align = 1;
37 std::string section_name, alternative_section_name;
38
39 protected:
40 SymbolDefinition(std::string name, binding_type binding, Location location, offset_t size, offset_t align, std::string section_name = "", std::string alternative_section_name = "")
41 : name(name), binding(binding), location(location), size(size), align(align), section_name(section_name), alternative_section_name(alternative_section_name)
42 {
43 }
44
45 public:
46 SymbolDefinition()
47 {
48 }
49
50 static SymbolDefinition CreateUndefined(std::string name, offset_t size = 0, offset_t align = 1);
51 static SymbolDefinition CreateLocal(std::string name, Location location, offset_t size = 0, offset_t align = 1);
52 static SymbolDefinition CreateGlobal(std::string name, Location location, offset_t size = 0, offset_t align = 1);
53 static SymbolDefinition CreateWeak(std::string name, Location location, offset_t size = 0, offset_t align = 1);
54 static SymbolDefinition CreateCommon(std::string name, std::string section, offset_t size = 0, offset_t align = 1);
55 static SymbolDefinition CreateCommon(std::string name, std::string section, offset_t size, offset_t align, std::string alternative_section);
56 static SymbolDefinition CreateCommon(std::string name, std::string section, std::string alternative_section);
57 static SymbolDefinition CreateLocalCommon(std::string name, std::string section, offset_t size = 0, offset_t align = 1);
58 static SymbolDefinition CreateLocalCommon(std::string name, std::string section, offset_t size, offset_t align, std::string alternative_section);
59 static SymbolDefinition CreateLocalCommon(std::string name, std::string section, std::string alternative_section);
60
61 bool operator ==(const SymbolDefinition& other) const;
62
63 bool IsLocal() const;
64 bool IsCommon() const;
65 bool IsAllocated() const;
66
76 bool Displace(const Displacement& displacement);
77 };
78
79 std::ostream& operator <<(std::ostream& out, const SymbolDefinition& symbol);
80}
81
82#endif /* SYMBOL_DEFINITION_H */
Represents a single offset within a section, or an absolute location in memory if the section is null...
Definition location.h:17
Represents a symbol definition.
Definition symbol_definition.h:16
bool Displace(const Displacement &displacement)
Recalculates the location after a section has moved.
Definition symbol_definition.cc:66
binding_type
Definition symbol_definition.h:20
@ Global
A variable that is visible in all modules and must appear once.
Definition symbol_definition.h:26
@ Weak
A variable that is visible in all modules, however takes lower precedence than a Global variable.
Definition symbol_definition.h:28
@ Common
A currently unallocated variable that should be allocated in the final stages of the linking process.
Definition symbol_definition.h:30
@ Undefined
An undefined variable that needs to appear in another module for the linking process to succeed.
Definition symbol_definition.h:22
@ LocalCommon
A currently unallocated local variable that should be allocated in the final stages of the linking pr...
Definition symbol_definition.h:32
@ Local
A variable that is only visible in the current module.
Definition symbol_definition.h:24