cowos

custom OS from scratch in C
git clone git://git.daat.foo/cowos.git
Log | Files | Refs | README | LICENSE

linker.ld (2202B)


      1 /* Tell the linker that we want an x86_64 ELF64 output file */
      2 OUTPUT_FORMAT(elf64-x86-64)
      3 
      4 /* We want the symbol kmain to be our entry point */
      5 ENTRY(kernel_main)
      6 
      7 /* Define the program headers we want so the bootloader gives us the right */
      8 /* MMU permissions; this also allows us to exert more control over the linking */
      9 /* process. */
     10 PHDRS
     11 {
     12         limine_requests PT_LOAD;
     13         text PT_LOAD;
     14         rodata PT_LOAD;
     15         data PT_LOAD;
     16 }
     17 
     18 SECTIONS
     19 {
     20         /* We want to be placed in the topmost 2GiB of the address space, for optimisations */
     21         /* and because that is what the Limine spec mandates. */
     22         /* Any address in this region will do, but often 0xffffffff80000000 is chosen as */
     23         /* that is the beginning of the region. */
     24         . = 0xffffffff80000000;
     25         
     26         /* Define a section to contain the Limine requests and assign it to its own PHDR */
     27         .limine_requests : {
     28                 KEEP(*(.limine_requests_start))
     29                 KEEP(*(.limine_requests))
     30                 KEEP(*(.limine_requests_end))
     31         } :limine_requests
     32         
     33         /* Move to the next memory page for .text */
     34         . = ALIGN(CONSTANT(MAXPAGESIZE));
     35         
     36         .text : {
     37                 *(.text .text.*)
     38         } :text
     39         
     40         /* Move to the next memory page for .rodata */
     41         . = ALIGN(CONSTANT(MAXPAGESIZE));
     42         
     43         .rodata : {
     44                 *(.rodata .rodata.*)
     45         } :rodata
     46         
     47         /* Move to the next memory page for .data */
     48         . = ALIGN(CONSTANT(MAXPAGESIZE));
     49         
     50         .data : {
     51                 *(.data .data.*)
     52         } :data
     53         
     54         /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */
     55         /* unnecessary zeros will be written to the binary. */
     56         /* If you need, for example, .init_array and .fini_array, those should be placed */
     57         /* above this. */
     58         .bss : {
     59                 *(.bss .bss.*)
     60                 *(COMMON)
     61         } :data
     62         
     63         /* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */
     64         /DISCARD/ : {
     65                 *(.eh_frame*)
     66                 *(.note .note.*)
     67         }
     68 }