An x86-64 operating system built from xv6, now largely rewritten: SMP, a copy-on-write root filesystem (SchFS), PCI/USB/virtio drivers, a TTF rasteriser, and a Linux-numbered syscall ABI. No history before this point -- the tree was never under version control. This commit exists so the rename that follows has something to undo to.
104 lines
3.5 KiB
Text
104 lines
3.5 KiB
Text
/* Simple linker script for the JOS kernel.
|
|
See the GNU ld 'info' manual ("info ld") to learn the syntax. */
|
|
|
|
/* OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") */
|
|
/* OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") */
|
|
OUTPUT_FORMAT("elf64-x86-64")
|
|
OUTPUT_ARCH(i386:x86-64)
|
|
ENTRY(_start)
|
|
|
|
mboot_load_addr = 0x00100000;
|
|
|
|
SECTIONS
|
|
{
|
|
/* Link the kernel at this address: "." means the current address */
|
|
/* Must be equal to KERNLINK */
|
|
. = 0xFFFF800000100000;
|
|
|
|
PROVIDE(begin = .);
|
|
|
|
/* The .l* section names are the x86-64 psABI's "large" sections, and they
|
|
* are not optional decoration: with -mcmodel=large both LLVM and GCC 13+
|
|
* put nearly all code and data into .ltext/.lrodata/.ldata/.lbss rather
|
|
* than the classic names.
|
|
*
|
|
* A script that does not name them still links. The large sections become
|
|
* orphans placed after everything the script did name, which puts them past
|
|
* PROVIDE(end = .) -- so kinit1(end, ...) hands the page allocator a megabyte
|
|
* of live .lbss and the kernel destroys itself within a few instructions of
|
|
* its first printf. That is exactly how this was found: the boot printed one
|
|
* line and triple-faulted in a loop.
|
|
*
|
|
* Matched alongside their small counterparts so the layout is unchanged for
|
|
* a toolchain that does not use them. */
|
|
.text : AT(mboot_load_addr) {
|
|
*(.text .rela.text .stub .text.* .gnu.linkonce.t.*)
|
|
*(.ltext .ltext.*)
|
|
}
|
|
|
|
PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
|
|
|
|
.rodata : {
|
|
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
|
*(.lrodata .lrodata.*)
|
|
}
|
|
|
|
/* Thread-local storage.
|
|
*
|
|
* The kernel really does use TLS: `__thread struct cpu *cpu` and
|
|
* `__thread struct proc *proc` (kernel/arch/x86_64/vm.c), reached through
|
|
* FS_BASE, which seginit() points at kernel_fs_base.
|
|
*
|
|
* These output sections are what make the linker emit a PT_TLS segment, and
|
|
* without a PT_TLS the local-exec relocations have nothing to resolve
|
|
* against: lld left every access as a bare `movq %fs:0x0`, so `cpu` and
|
|
* `proc` both aliased the thread pointer itself and the kernel died a few
|
|
* instructions into seginit. GNU ld happened to place an orphan .tbss well
|
|
* enough to work; that was luck, not correctness.
|
|
*
|
|
* Order matters and is checked by more than C: trapasm.S hardcodes `proc` at
|
|
* %fs:(-8). With cpu at TLS offset 0 and proc at 8 in a 16-byte block, the
|
|
* local-exec offsets come out as -16 and -8, which is the layout that file
|
|
* assumes. */
|
|
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
|
|
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
|
|
|
|
/* Adjust the address for the data segment to the next page */
|
|
. = ALIGN(0x1000);
|
|
|
|
/* Conventionally, Unix linkers provide pseudo-symbols
|
|
* etext, edata, and end, at the end of the text, data, and bss.
|
|
* For the kernel mapping, we need the address at the beginning
|
|
* of the data section, but that's not one of the conventional
|
|
* symbols, because the convention started before there was a
|
|
* read-only rodata section between text and data. */
|
|
PROVIDE(data = .);
|
|
|
|
/* The data segment */
|
|
.data : {
|
|
*(.data .data.*)
|
|
*(.ldata .ldata.*)
|
|
}
|
|
|
|
. = ALIGN(0x1000);
|
|
|
|
PROVIDE(edata = .);
|
|
|
|
.bss : {
|
|
*(.bss .bss.*)
|
|
*(.lbss .lbss.*)
|
|
*(COMMON)
|
|
}
|
|
|
|
. = ALIGN(0x1000);
|
|
|
|
PROVIDE(end = .);
|
|
|
|
/DISCARD/ : {
|
|
*(.eh_frame .rela.eh_frame .note.GNU-stack)
|
|
}
|
|
}
|
|
|
|
mboot_load_end = mboot_load_addr + (edata - begin);
|
|
mboot_bss_end = mboot_load_addr + (end - begin);
|
|
mboot_entry_addr = mboot_load_addr + (mboot_entry - begin);
|