I'm trying to set up my kernel to be bootable using another bootloader, and I need to use a linker script like the following:
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
/* Define the program headers we want so the bootloader gives us the right */
/* MMU permissions */
PHDRS
{
null PT_NULL FLAGS(0);
text PT_LOAD FLAGS(0x5);
rodata PT_LOAD FLAGS(0x4);
data PT_LOAD FLAGS(0x6);
}
SECTIONS
{
/* We wanna be placed in the topmost 2GiB of the address space, for optimizations */
/* and because that is what the stivale2 spec mandates. */
. = 0xffffffff80000000;
.text : {
*(.text .text.*)
} :text
/* Move to the next memory page for .rodata */
. += CONSTANT(MAXPAGESIZE);
/* We place the .stivale2hdr section containing the header in its own section, */
/* and we use the KEEP directive on it to make sure it doesn't get discarded. */
.stivale2hdr : {
KEEP(*(.stivale2hdr))
} :rodata
.rodata : {
*(.rodata .rodata.*)
} :rodata
/* Move to the next memory page for .data */
. += CONSTANT(MAXPAGESIZE);
.data : {
*(.data .data.*)
} :data
.bss : {
*(COMMON)
*(.bss .bss.*)
} :data
}
However, I also want to keep everything defined by the x86_64-unknown-none
target (e.g. a PIC/PIE executable for example). Will this linker script break that, and if so, how can I retain it?