Turnstone Operating System
Loading...
Searching...
No Matches
linker.h File Reference

linker functions and types More...

#include <types.h>
#include <buffer.h>
#include <hashmap.h>
#include <tosdb/tosdb.h>
#include <utils.h>

Classes

struct  linker_relocation_entry_t
 
struct  linker_section_locations_t
 section information More...
 
struct  linker_global_offset_table_entry_t
 
struct  program_header_t
 program definition header. More...
 
struct  linker_section_t
 
struct  linker_module_t
 
struct  linker_context_t
 

Macros

#define ___LINKER_H   0
 
#define TOS_EXECUTABLE_OR_LIBRARY_MAGIC   "TOSELF"
 
#define LINKER_GOT_SYMBOL_ID   0x1
 
#define LINKER_GOT_SECTION_ID   0x1
 

Typedefs

typedef enum linker_section_type_t linker_section_type_t
 shorthand for enum
 
typedef enum linker_relocation_type_t linker_relocation_type_t
 shorthand for enum
 
typedef enum linker_symbol_type_t linker_symbol_type_t
 shorthand for enum
 
typedef enum linker_symbol_scope_t linker_symbol_scope_t
 shorthand for enum
 
typedef struct linker_relocation_entry_t linker_relocation_entry_t
 shorthand for struct
 
typedef struct linker_section_locations_t linker_section_locations_t
 shorthand for struct
 
typedef struct linker_global_offset_table_entry_t linker_global_offset_table_entry_t
 shorthand for struct
 
typedef struct program_header_t program_header_t
 shorthand for struct
 
typedef struct linker_section_t linker_section_t
 
typedef struct linker_module_t linker_module_t
 
typedef struct linker_context_t linker_context_t
 
typedef enum linker_program_dump_type_t linker_program_dump_type_t
 

Enumerations

enum  linker_section_type_t {
  LINKER_SECTION_TYPE_TEXT , LINKER_SECTION_TYPE_DATA , LINKER_SECTION_TYPE_DATARELOC , LINKER_SECTION_TYPE_RODATA ,
  LINKER_SECTION_TYPE_RODATARELOC , LINKER_SECTION_TYPE_BSS , LINKER_SECTION_TYPE_PLT , LINKER_SECTION_TYPE_RELOCATION_TABLE ,
  LINKER_SECTION_TYPE_GOT_RELATIVE_RELOCATION_TABLE , LINKER_SECTION_TYPE_GOT , LINKER_SECTION_TYPE_STACK , LINKER_SECTION_TYPE_HEAP ,
  LINKER_SECTION_TYPE_NR_SECTIONS
}
 linker section types. More...
 
enum  linker_relocation_type_t {
  LINKER_RELOCATION_TYPE_32_16 , LINKER_RELOCATION_TYPE_32_32 , LINKER_RELOCATION_TYPE_32_PC16 , LINKER_RELOCATION_TYPE_32_PC32 ,
  LINKER_RELOCATION_TYPE_64_8 , LINKER_RELOCATION_TYPE_64_16 , LINKER_RELOCATION_TYPE_64_32 , LINKER_RELOCATION_TYPE_64_32S ,
  LINKER_RELOCATION_TYPE_64_64 , LINKER_RELOCATION_TYPE_64_PC32 , LINKER_RELOCATION_TYPE_64_PC64 , LINKER_RELOCATION_TYPE_64_GOT64 ,
  LINKER_RELOCATION_TYPE_64_GOTOFF64 , LINKER_RELOCATION_TYPE_64_GOTPC64 , LINKER_RELOCATION_TYPE_64_PLTOFF64
}
 relocation stypes More...
 
enum  linker_symbol_type_t {
  LINKER_SYMBOL_TYPE_UNDEF , LINKER_SYMBOL_TYPE_OBJECT , LINKER_SYMBOL_TYPE_FUNCTION , LINKER_SYMBOL_TYPE_SECTION ,
  LINKER_SYMBOL_TYPE_SYMBOL
}
 symbol types More...
 
enum  linker_symbol_scope_t { LINKER_SYMBOL_SCOPE_LOCAL , LINKER_SYMBOL_SCOPE_GLOBAL }
 symbol scope More...
 
enum  linker_program_dump_type_t {
  LINKER_PROGRAM_DUMP_TYPE_NONE = 0 , LINKER_PROGRAM_DUMP_TYPE_CODE = 1 , LINKER_PROGRAM_DUMP_TYPE_GOT = 2 , LINKER_PROGRAM_DUMP_TYPE_RELOCATIONS = 4 ,
  LINKER_PROGRAM_DUMP_TYPE_METADATA = 8 , LINKER_PROGRAM_DUMP_TYPE_HEADER = 0x10 , LINKER_PROGRAM_DUMP_TYPE_ALL_WITHOUT_PAGE_TABLE = 0x1f , LINKER_PROGRAM_DUMP_TYPE_BUILD_PAGE_TABLE = 0x20 ,
  LINKER_PROGRAM_DUMP_TYPE_SYMBOLS = 0x40 , LINKER_PROGRAM_DUMP_TYPE_ALL = 0x7f
}
 

Functions

 _Static_assert (sizeof(linker_global_offset_table_entry_t) % 8==0, "linker_global_offset_table_entry_t align mismatch")
 
 _Static_assert (sizeof(linker_global_offset_table_entry_t)==0x38, "linker_global_offset_table_entry_t size mismatch")
 
 _Static_assert (offsetof_field(program_header_t, trampoline_code)==256, "program_header_t trampoline code align mismatch")
 
int8_t linker_destroy_context (linker_context_t *ctx)
 
int8_t linker_build_module (linker_context_t *ctx, uint64_t module_id, boolean_t recursive)
 
int8_t linker_build_symbols (linker_context_t *ctx, uint64_t module_id, uint64_t section_id, uint8_t section_type, uint64_t section_offset)
 
int8_t linker_build_relocations (linker_context_t *ctx, uint64_t section_id, uint8_t section_type, uint64_t section_offset, linker_module_t *module, boolean_t recursive)
 
boolean_t linker_is_all_symbols_resolved (linker_context_t *ctx)
 
int8_t linker_calculate_program_size (linker_context_t *ctx)
 
int8_t linker_bind_linear_addresses (linker_context_t *ctx)
 
int8_t linker_bind_got_entry_values (linker_context_t *ctx)
 
int8_t linker_link_program (linker_context_t *ctx)
 
int64_t linker_get_section_count_without_relocations (linker_context_t *ctx)
 
buffer_tlinker_build_efi_image_relocations (linker_context_t *ctx)
 
buffer_tlinker_build_efi_image_section_headers_without_relocations (linker_context_t *ctx)
 
buffer_tlinker_build_efi (linker_context_t *ctx)
 
int8_t linker_dump_program_to_array (linker_context_t *ctx, linker_program_dump_type_t dump_type, uint8_t *array)
 
void linker_build_modules_at_memory (void)
 
void linker_print_modules_at_memory (void)
 
void linker_print_module_info_at_memory (uint64_t module_id)
 

Variables

const char_t *const linker_section_type_names [LINKER_SECTION_TYPE_NR_SECTIONS]
 linker section type names
 

Detailed Description

linker functions and types

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Macro Definition Documentation

◆ ___LINKER_H

#define ___LINKER_H   0

prevent duplicate header error macro

◆ TOS_EXECUTABLE_OR_LIBRARY_MAGIC

#define TOS_EXECUTABLE_OR_LIBRARY_MAGIC   "TOSELF"

linker executable or library magic TOSEL

Enumeration Type Documentation

◆ linker_relocation_type_t

relocation stypes

Enumerator
LINKER_RELOCATION_TYPE_32_16 

32 bit width 16 bit addend section relative relocation

LINKER_RELOCATION_TYPE_32_32 

32 bit width 32 bit addend section relative relocation

LINKER_RELOCATION_TYPE_32_PC16 

32 bit width 16 bit addend program counter relative relocation

LINKER_RELOCATION_TYPE_32_PC32 

32 bit width 32 bit addend program counter relative relocation

LINKER_RELOCATION_TYPE_64_8 

64 bit width 8 bit addend section relative relocation

LINKER_RELOCATION_TYPE_64_16 

64 bit width 16 bit addend section relative relocation

LINKER_RELOCATION_TYPE_64_32 

64 bit width 32 bit addend section relative relocation

LINKER_RELOCATION_TYPE_64_32S 

64 bit width signed 32 bit addend section relative relocation

LINKER_RELOCATION_TYPE_64_64 

64 bit width 64 bit addend section relative relocation

LINKER_RELOCATION_TYPE_64_PC32 

64 bit width 32 bit addend program counter relative relocation

LINKER_RELOCATION_TYPE_64_PC64 

64 bit width 64 bit addend program counter relative relocation

LINKER_RELOCATION_TYPE_64_GOT64 

64 bit width 64 bit got direct

LINKER_RELOCATION_TYPE_64_GOTOFF64 

64 bit width 64 bit got offset relocation

LINKER_RELOCATION_TYPE_64_GOTPC64 

64 bit width 64 bit got pc relative relocation

LINKER_RELOCATION_TYPE_64_PLTOFF64 

64 bit width 64 bit plt offset relocation

◆ linker_section_type_t

linker section types.

Enumerator
LINKER_SECTION_TYPE_TEXT 

executable (text) section

LINKER_SECTION_TYPE_DATA 

read-write data section

LINKER_SECTION_TYPE_DATARELOC 

read-write relocation data section

LINKER_SECTION_TYPE_RODATA 

readonly data section

LINKER_SECTION_TYPE_RODATARELOC 

readonly relocation data section

LINKER_SECTION_TYPE_BSS 

bss section

LINKER_SECTION_TYPE_PLT 

procedure linkage table section

LINKER_SECTION_TYPE_RELOCATION_TABLE 

relocation table section

LINKER_SECTION_TYPE_GOT_RELATIVE_RELOCATION_TABLE 

got relative relocation table section

LINKER_SECTION_TYPE_GOT 

global offset table section

LINKER_SECTION_TYPE_STACK 

stack section

LINKER_SECTION_TYPE_HEAP 

heap section

LINKER_SECTION_TYPE_NR_SECTIONS 

hack four enum item count

◆ linker_symbol_scope_t

symbol scope

Enumerator
LINKER_SYMBOL_SCOPE_LOCAL 

local

LINKER_SYMBOL_SCOPE_GLOBAL 

global

◆ linker_symbol_type_t

symbol types

Enumerator
LINKER_SYMBOL_TYPE_UNDEF 

undefined

LINKER_SYMBOL_TYPE_OBJECT 

object

LINKER_SYMBOL_TYPE_FUNCTION 

function

LINKER_SYMBOL_TYPE_SECTION 

section

LINKER_SYMBOL_TYPE_SYMBOL 

symbol