78 const Section *definition =
nullptr;
116 this->definition = section;
117 this->offset = offset;
122 return definition !=
nullptr;
139 this->binding = binding;
143 this->visibility = visibility;
161 const Symbol *symbol =
nullptr;
166 : type(type), offset(offset), addend(addend), symbol(symbol) {
185 this->offset = offset;
196 this->symbol = symbol;
200 this->addend = addend;
252 std::vector<char> contents;
261 : name(name), type(type) {
285 this->flags &= ~flag;
315 this->alignment = alignment;
323 this->contents = std::move(contents);
326 template<
typename It>
328 this->contents.assign(begin, end);
331 template<
typename It>
333 this->contents.insert(this->contents.end(), begin, end);
336 template<
typename It>
338 typedef typename std::iterator_traits<It>::value_type T;
339 uint64_t size_bytes = std::distance(begin, end) *
sizeof(T);
340 this->contents.insert(this->contents.begin(), begin, end);
345 r.set_offset(r.get_offset() + size_bytes);
354 this->contents.assign((
const char *)contents.data(), (
const char *)(contents.data() + contents.size()));
369 return contents.begin();
372 return contents.end();
375 return contents.begin();
378 return contents.end();
381 return contents.data();
384 return contents.size();
387 return contents.empty();
391 this->relocs = std::move(relocs);
394 template<
typename It>
396 this->relocs.assign(begin, end);
400 relocs.push_back(reloc);
403 return relocs.begin();
409 return {relocs.begin(), relocs.end()};
412 return relocs.begin();
418 return {relocs.begin(), relocs.end()};
421 return relocs.size();
446 const Symbol &got_sym) = 0;
491 void operator=(
const Object &);
517 this->machine = machine;
521 this->version = version;
534 static std::unique_ptr<Object>
parse_object(
const char *data,
size_t size);
538 const std::string &soname =
"");
547 return {secs.begin(), secs.end()};
556 return {secs.begin(), secs.end()};
566 return secs.erase(i);
579 return {syms.begin(), syms.end()};
588 return {syms.begin(), syms.end()};
Base class for a target architecture to implement the target specific aspects of linking.
virtual Symbol add_plt_entry(const Symbol &sym, Section &plt, Section &got, const Symbol &got_sym)=0
Add a PLT entry for a symbol sym defined externally.
virtual void append_dynamic(Section &dynamic)=0
virtual bool needs_plt_entry(const Relocation &reloc)=0
Check to see if this relocation should go through the PLT.
virtual uint32_t get_flags()=0
virtual ~Linker()=default
virtual uint32_t get_version()=0
virtual uint64_t get_got_entry(Section &got, const Symbol &sym)=0
Add or get an entry to the global offset table (GOT) with a relocation pointing to sym.
virtual uint16_t get_machine()=0
virtual Relocation relocate(uint64_t fixup_offset, char *fixup_addr, uint64_t type, const Symbol *sym, uint64_t sym_offset, int64_t addend, Section &got)=0
Perform a relocation.
Holds all of the relevant sections and symbols for an object.
uint16_t get_machine() const
symbol_iterator symbols_end()
section_iterator erase_section(section_iterator i)
Object & set_type(Type type)
symbol_iterator find_symbol(const std::string &name)
Object & set_flags(uint32_t flags)
const_section_iterator sections_begin() const
section_iterator sections_end()
static std::unique_ptr< Object > parse_object(const char *data, size_t size)
Parse an object in memory to an Object.
iterator_range< const_section_iterator > sections() const
Object & set_entry(uint64_t entry)
section_iterator find_section(const std::string &name)
std::list< Section > SectionList
std::vector< char > write_shared_object(Linker *linker, const std::vector< std::string > &depedencies={}, const std::string &soname="")
Write a shared object in memory.
iterator_range< section_iterator > sections()
iterator_range< symbol_iterator > symbols()
section_iterator add_section(const std::string &name, Section::Type type)
uint32_t get_flags() const
Object & set_machine(uint16_t machine)
const_symbol_iterator find_symbol(const std::string &name) const
const_section_iterator sections_end() const
SymbolList::iterator symbol_iterator
const_symbol_iterator symbols_begin() const
Object & set_version(uint32_t version)
section_iterator add_relocation_section(const Section &for_section)
size_t symbols_size() const
section_iterator merge_text_sections()
uint64_t get_entry() const
section_iterator merge_sections(const std::vector< section_iterator > §ions)
const_symbol_iterator symbols_end() const
symbol_iterator add_symbol(const std::string &name)
symbol_iterator symbols_begin()
size_t sections_size() const
uint32_t get_version() const
section_iterator sections_begin()
SectionList::const_iterator const_section_iterator
iterator_range< const_symbol_iterator > symbols() const
SectionList::iterator section_iterator
std::list< Symbol > SymbolList
SymbolList::const_iterator const_symbol_iterator
Describes a relocation to be applied to an offset of a section in an Object.
int64_t get_addend() const
The value to replace with the relocation is the address of the symbol plus the addend.
Relocation(uint32_t type, uint64_t offset, int64_t addend, const Symbol *symbol)
Relocation & set_symbol(const Symbol *symbol)
The value to replace with the relocation is the address of the symbol plus the addend.
Relocation & set_type(uint32_t type)
The type of relocation to be applied.
Relocation & set_addend(int64_t addend)
The value to replace with the relocation is the address of the symbol plus the addend.
uint64_t get_offset() const
Where to apply the relocation.
Relocation & set_offset(uint64_t offset)
Where to apply the relocation.
const Symbol * get_symbol() const
The value to replace with the relocation is the address of the symbol plus the addend.
uint32_t get_type() const
The type of relocation to be applied.
Describes a section of an object file.
RelocationList::iterator relocation_iterator
bool contents_empty() const
Section & prepend_contents(It begin, It end)
size_t relocations_size() const
Section & append_contents(It begin, It end)
uint64_t get_alignment() const
std::vector< Relocation > RelocationList
size_t contents_size() const
Section & set_contents(const std::vector< T > &contents)
Set, append or prepend an object to the contents, assuming T is a trivially copyable datatype.
relocation_iterator relocations_end()
uint32_t get_flags() const
Section & set_relocations(std::vector< Relocation > relocs)
Section & set_contents(std::vector< char > contents)
uint64_t get_size() const
Get or set the size of the section.
Section & set_flags(uint32_t flags)
relocation_iterator relocations_begin()
void add_relocation(const Relocation &reloc)
RelocationList::const_iterator const_relocation_iterator
const std::vector< char > & get_contents() const
std::vector< char >::const_iterator const_contents_iterator
Section & set_contents(It begin, It end)
const_contents_iterator contents_begin() const
Section & set_size(uint64_t size)
Get or set the size of the section.
contents_iterator contents_begin()
const std::string & get_name() const
contents_iterator contents_end()
const_relocation_iterator relocations_begin() const
iterator_range< relocation_iterator > relocations()
Section & set_type(Type type)
Section & remove_flag(Flag flag)
Section & append_contents(const T &x)
Section(const std::string &name, Type type)
Section & set_flag(Flag flag)
Section & set_name(const std::string &name)
Section & prepend_contents(const T &x)
const_contents_iterator contents_end() const
Section & set_relocations(It begin, It end)
const_relocation_iterator relocations_end() const
iterator_range< const_relocation_iterator > relocations() const
const char * contents_data() const
std::vector< char >::iterator contents_iterator
Section & set_alignment(uint64_t alignment)
Symbol(const std::string &name)
uint64_t get_offset() const
Accesses the properties that describe the definition of this symbol.
const Section * get_section() const
Accesses the properties that describe the definition of this symbol.
Visibility get_visibility() const
Access the binding and visibility of this symbol.
Type get_type() const
Accesses the type of this symbol.
Symbol & set_visibility(Visibility visibility)
Access the binding and visibility of this symbol.
Symbol & define(const Section *section, uint64_t offset, uint32_t size)
Accesses the properties that describe the definition of this symbol.
Symbol & set_type(Type type)
Accesses the type of this symbol.
bool is_defined() const
Accesses the properties that describe the definition of this symbol.
Symbol & set_name(const std::string &name)
Accesses the name of this symbol.
Symbol & set_binding(Binding binding)
Access the binding and visibility of this symbol.
const std::string & get_name() const
Accesses the name of this symbol.
uint32_t get_size() const
Accesses the properties that describe the definition of this symbol.
Binding get_binding() const
Access the binding and visibility of this symbol.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
unsigned __INT8_TYPE__ uint8_t
unsigned __INT16_TYPE__ uint16_t
unsigned __INT32_TYPE__ uint32_t
Types in the halide type system.