User:Xenos/UEFI Bare Bones: Difference between revisions
Content deleted Content added
→Source files: Added minimal elf.h include file. |
→Linker script: Added linker scripts. |
||
Line 190:
=== Linker script ===
To link the final binary and keep the sections which are needed, a linker script is used. The following linker scripts, for different target architectures, do the following:
# Select the output file format (ELF and its specific flavor).
# Select the output architecture.
# Set the entry point to the function efi_main.
# Select the necessary sections and align them on page boundaries.
# Create a fake relocation entry, since EFI loaders check for the presence of a relocation table.
# Discard unnecessary sections.
For linking, one must make sure that the correct target architecture is selected.
==== i386 ====
<source lang="c">OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(efi_main)
SECTIONS
{
. = 4096;
ImageBase = .;
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
. = ALIGN(4096);
.text :
{
_text = .;
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
. = ALIGN(16);
}
_etext = .;
_text_size = . - _text;
. = ALIGN(4096);
.rdata :
{
_data = .;
*(.got.plt)
*(.got)
*(.rodata*)
*(.srodata)
}
. = ALIGN(4096);
.data :
{
*(.data)
*(.data1)
*(.data.*)
*(.sdata)
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
}
. = ALIGN(4096);
.dynamic : { *(.dynamic) }
. = ALIGN(4096);
.rel :
{
*(.rel.data)
*(.rel.data.*)
*(.rel.got)
*(.rel.stab)
}
_edata = .;
_data_size = . - _etext;
. = ALIGN(4096);
.reloc :
{
LONG(_data);
LONG(10);
SHORT(0);
*(.reloc)
}
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
. = ALIGN(4096);
/DISCARD/ :
{
*(.rel.reloc)
*(.eh_frame)
*(.note*)
*(.comment*)
}
}</source>
==== x86_64 ====
<source lang="c">OUTPUT_FORMAT("elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(efi_main)
SECTIONS
{
. = 4096;
ImageBase = .;
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
. = ALIGN(4096);
.text :
{
_text = .;
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
. = ALIGN(16);
}
_etext = .;
_text_size = . - _text;
. = ALIGN(4096);
.rdata :
{
_data = .;
*(.got.plt)
*(.got)
*(.rodata*)
*(.srodata)
}
. = ALIGN(4096);
.data :
{
*(.data)
*(.data1)
*(.data.*)
*(.sdata)
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
}
. = ALIGN(4096);
.dynamic : { *(.dynamic) }
. = ALIGN(4096);
.rela :
{
*(.rela.data)
*(.rela.data.*)
*(.rela.got)
*(.rela.stab)
}
_edata = .;
_data_size = . - _etext;
. = ALIGN(4096);
.reloc :
{
LONG(_data);
LONG(10);
SHORT(0);
*(.reloc)
}
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
. = ALIGN(4096);
/DISCARD/ :
{
*(.rel.reloc)
*(.eh_frame)
*(.note*)
*(.comment*)
}
}</source>
== Building ==
|