1*527d7fdfSderaadt/* $OpenBSD: ld.script,v 1.6 2017/05/31 19:18:18 deraadt Exp $ */ 2414976a8Smlarkin 3414976a8Smlarkin/* 4414976a8Smlarkin * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> 5414976a8Smlarkin * Copyright (c) 2009 Tobias Weingartner <weingart@tepid.org> 6414976a8Smlarkin * 7414976a8Smlarkin * Permission to use, copy, modify, and distribute this software for any 8414976a8Smlarkin * purpose with or without fee is hereby granted, provided that the above 9414976a8Smlarkin * copyright notice and this permission notice appear in all copies. 10414976a8Smlarkin * 11414976a8Smlarkin * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12414976a8Smlarkin * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13414976a8Smlarkin * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14414976a8Smlarkin * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15414976a8Smlarkin * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16414976a8Smlarkin * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17414976a8Smlarkin * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18414976a8Smlarkin */ 19414976a8Smlarkin 20414976a8SmlarkinOUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 21414976a8SmlarkinOUTPUT_ARCH(i386) 22414976a8Smlarkin 23414976a8Smlarkin/* Define how we want out ELF binary to look like. */ 24414976a8SmlarkinPHDRS 25414976a8Smlarkin{ 26414976a8Smlarkin text PT_LOAD FILEHDR PHDRS; 27414976a8Smlarkin rodata PT_LOAD; 28414976a8Smlarkin data PT_LOAD; 29414976a8Smlarkin bss PT_LOAD; 30176f97ecSderaadt openbsd_randomize PT_OPENBSD_RANDOMIZE; 31414976a8Smlarkin} 32414976a8Smlarkin 33414976a8Smlarkin/* 34414976a8Smlarkin * If we want the text/rodata/data sections aligned on 2M boundaries, 35414976a8Smlarkin * we could use the following instead. Note, file size would increase 36414976a8Smlarkin * due to necessary padding. 37414976a8Smlarkin * 38414976a8Smlarkin *__ALIGN_SIZE = 0x200000; 39414976a8Smlarkin */ 40414976a8Smlarkin__ALIGN_SIZE = 0x1000; 41414976a8Smlarkin__kernel_base_virt = 0xd0200000 + SIZEOF_HEADERS; 4257ae21efSmlarkin__kernel_base_phys = __kernel_base_virt & 0xfffffff; 43414976a8Smlarkin 44414976a8Smlarkin/* We use physical address to jump to kernel */ 45414976a8Smlarkinstart_phys = LOADADDR(.text) + (start - __kernel_base_virt); 46414976a8SmlarkinENTRY(start_phys) 47414976a8SmlarkinSECTIONS 48414976a8Smlarkin{ 49414976a8Smlarkin __kernel_text_virt = __kernel_base_virt; 50414976a8Smlarkin __kernel_text_phys = __kernel_base_phys; 51414976a8Smlarkin .text (__kernel_text_virt) : AT (__kernel_text_phys) 52414976a8Smlarkin { 53414976a8Smlarkin __text_start = ABSOLUTE(.) & 0xfffff000; 54414976a8Smlarkin __text_size = SIZEOF(.text); 55414976a8Smlarkin __text_load = LOADADDR(.text); 56*527d7fdfSderaadt locore0.o(.text) 57414976a8Smlarkin *(.text .text.*) 58414976a8Smlarkin } :text 59414976a8Smlarkin PROVIDE (__etext = .); 60414976a8Smlarkin PROVIDE (etext = .); 61414976a8Smlarkin _etext = .; 62414976a8Smlarkin 63414976a8Smlarkin /* Move rodata to the next page, so we can nuke X and W bit on them */ 64414976a8Smlarkin . = ALIGN(__ALIGN_SIZE); 65414976a8Smlarkin __kernel_rodata_virt = .; 6657ae21efSmlarkin __kernel_rodata_phys = . & 0xfffffff; 67414976a8Smlarkin .rodata (__kernel_rodata_virt) : AT (__kernel_rodata_phys) 68414976a8Smlarkin { 69414976a8Smlarkin __rodata_start = ABSOLUTE(.); 70414976a8Smlarkin __rodata_size = SIZEOF(.rodata); 71414976a8Smlarkin __rodata_load = LOADADDR(.rodata); 72414976a8Smlarkin *(.rodata .rodata.*) 73414976a8Smlarkin *(.codepatch) 74414976a8Smlarkin *(.codepatchend) 75414976a8Smlarkin } :rodata 76176f97ecSderaadt . = ALIGN(0x1000); 77176f97ecSderaadt __kernel_randomdata_phys = . & 0xfffffff; 78176f97ecSderaadt .openbsd.randomdata : AT (__kernel_randomdata_phys) 79176f97ecSderaadt { 80176f97ecSderaadt *(.openbsd.randomdata) 813576c567Sderaadt } :rodata :openbsd_randomize 82176f97ecSderaadt . = ALIGN(0x1000); 83414976a8Smlarkin PROVIDE (erodata = .); 84414976a8Smlarkin _erodata = .; 85414976a8Smlarkin 86414976a8Smlarkin /* Move data to the next page, so we can add W bit on them */ 87414976a8Smlarkin . = ALIGN(__ALIGN_SIZE); 88414976a8Smlarkin __kernel_data_virt = .; 8957ae21efSmlarkin __kernel_data_phys = . & 0xfffffff; 90414976a8Smlarkin .data (__kernel_data_virt) : AT (__kernel_data_phys) 91414976a8Smlarkin { 92414976a8Smlarkin __data_start = ABSOLUTE(.); 93414976a8Smlarkin __data_size = SIZEOF(.data); 94414976a8Smlarkin __data_load = LOADADDR(.data); 95414976a8Smlarkin *(.data .data.*) 96414976a8Smlarkin } :data 97414976a8Smlarkin . = ALIGN(0x1000); 98414976a8Smlarkin PROVIDE (edata = .); 99414976a8Smlarkin _edata = .; 100414976a8Smlarkin 101414976a8Smlarkin /* BSS starts right after padded data */ 102414976a8Smlarkin __kernel_bss_virt = .; 10357ae21efSmlarkin __kernel_bss_phys = . & 0xfffffff; 104414976a8Smlarkin .bss (__kernel_bss_virt) : AT (__kernel_bss_phys) 105414976a8Smlarkin { 106414976a8Smlarkin __bss_start = ABSOLUTE(.); 107414976a8Smlarkin __bss_size = SIZEOF(.bss); 108414976a8Smlarkin __bss_load = LOADADDR(.bss); 109414976a8Smlarkin *(.bss .bss.*) 110414976a8Smlarkin *(COMMON) 111414976a8Smlarkin /* Align after .bss to ensure correct alignment even if the 112414976a8Smlarkin * .bss section disappears because there are no input sections. 113414976a8Smlarkin */ 114414976a8Smlarkin . = ALIGN(0x1000); 115414976a8Smlarkin } :bss 116414976a8Smlarkin __kernel_bss_end = .; 1179bad4c31Smlarkin . = ALIGN(0x1000); 118414976a8Smlarkin _end = .; 119414976a8Smlarkin PROVIDE (end = .); 12057ae21efSmlarkin __kernel_end_phys = . & 0xfffffff; 121414976a8Smlarkin 122414976a8Smlarkin /* XXX - hack alert, since we are not C++, nuke these */ 123414976a8Smlarkin /DISCARD/ : 124414976a8Smlarkin { 125414976a8Smlarkin *(.note.GNU-stack) 126414976a8Smlarkin *(.eh_frame) 127414976a8Smlarkin } 128414976a8Smlarkin} 129