1*3a759fb4Smortimer/* $OpenBSD: ld.script,v 1.12 2021/03/07 23:10:54 mortimer 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; 279718ab18Sguenther rodata PT_LOAD FLAGS (4); 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 44e2bb53a1SnaddyENTRY(start) 45414976a8SmlarkinSECTIONS 46414976a8Smlarkin{ 47414976a8Smlarkin __kernel_text_virt = __kernel_base_virt; 48414976a8Smlarkin __kernel_text_phys = __kernel_base_phys; 49*3a759fb4Smortimer .text ALIGN(__kernel_text_virt, __ALIGN_SIZE) : 50*3a759fb4Smortimer AT (ALIGN(__kernel_text_phys, __ALIGN_SIZE)) 51414976a8Smlarkin { 52414976a8Smlarkin __text_start = ABSOLUTE(.) & 0xfffff000; 53414976a8Smlarkin __text_size = SIZEOF(.text); 54414976a8Smlarkin __text_load = LOADADDR(.text); 55527d7fdfSderaadt locore0.o(.text) 56414976a8Smlarkin *(.text .text.*) 57b20d6be6Sderaadt } :text =0xcccccccc 5838d673b2Sbluhm 5938d673b2Sbluhm . = ALIGN(__ALIGN_SIZE); 6038d673b2Sbluhm __kernel_kutext_phys = . & 0xfffffff; 6138d673b2Sbluhm .kutext : AT (__kernel_kutext_phys) 6238d673b2Sbluhm { 6338d673b2Sbluhm __kutext_start = ABSOLUTE(.); 6438d673b2Sbluhm *(.kutext) 6538d673b2Sbluhm __kutext_end = ABSOLUTE(.); 6638d673b2Sbluhm } :text =0xcccccccc 6738d673b2Sbluhm 68414976a8Smlarkin PROVIDE (__etext = .); 69414976a8Smlarkin PROVIDE (etext = .); 70414976a8Smlarkin _etext = .; 71414976a8Smlarkin 72414976a8Smlarkin /* Move rodata to the next page, so we can nuke X and W bit on them */ 73414976a8Smlarkin . = ALIGN(__ALIGN_SIZE); 74414976a8Smlarkin __kernel_rodata_virt = .; 7557ae21efSmlarkin __kernel_rodata_phys = . & 0xfffffff; 76414976a8Smlarkin .rodata (__kernel_rodata_virt) : AT (__kernel_rodata_phys) 77414976a8Smlarkin { 78414976a8Smlarkin __rodata_start = ABSOLUTE(.); 79414976a8Smlarkin __rodata_size = SIZEOF(.rodata); 80414976a8Smlarkin __rodata_load = LOADADDR(.rodata); 81414976a8Smlarkin *(.rodata .rodata.*) 82414976a8Smlarkin *(.codepatch) 83414976a8Smlarkin *(.codepatchend) 84b20d6be6Sderaadt } :rodata =0xcccccccc 85176f97ecSderaadt . = ALIGN(0x1000); 86176f97ecSderaadt __kernel_randomdata_phys = . & 0xfffffff; 87176f97ecSderaadt .openbsd.randomdata : AT (__kernel_randomdata_phys) 88176f97ecSderaadt { 89f1bfbdc7Sguenther __retguard_start = ABSOLUTE(.); 90f1bfbdc7Sguenther *(.openbsd.randomdata.retguard .openbsd.randomdata.retguard.*) 91f1bfbdc7Sguenther /* XXX . = ALIGN(__ALIGN_SIZE); */ 92f1bfbdc7Sguenther __retguard_end = ABSOLUTE(.); 93f1bfbdc7Sguenther *(.openbsd.randomdata .openbsd.randomdata.*) 94b20d6be6Sderaadt } :rodata :openbsd_randomize =0xcccccccc 95176f97ecSderaadt . = ALIGN(0x1000); 96414976a8Smlarkin PROVIDE (erodata = .); 97414976a8Smlarkin _erodata = .; 98414976a8Smlarkin 99414976a8Smlarkin /* Move data to the next page, so we can add W bit on them */ 100414976a8Smlarkin . = ALIGN(__ALIGN_SIZE); 101414976a8Smlarkin __kernel_data_virt = .; 10257ae21efSmlarkin __kernel_data_phys = . & 0xfffffff; 103414976a8Smlarkin .data (__kernel_data_virt) : AT (__kernel_data_phys) 104414976a8Smlarkin { 105414976a8Smlarkin __data_start = ABSOLUTE(.); 106414976a8Smlarkin __data_size = SIZEOF(.data); 107414976a8Smlarkin __data_load = LOADADDR(.data); 108414976a8Smlarkin *(.data .data.*) 109b20d6be6Sderaadt } :data =0xcccccccc 11038d673b2Sbluhm 11138d673b2Sbluhm . = ALIGN(__ALIGN_SIZE); 11238d673b2Sbluhm __kernel_kudata_phys = . & 0xfffffff; 11338d673b2Sbluhm .kudata : AT (__kernel_kudata_phys) 11438d673b2Sbluhm { 11538d673b2Sbluhm __kudata_start = ABSOLUTE(.); 11638d673b2Sbluhm *(.kudata) 11738d673b2Sbluhm __kudata_end = ABSOLUTE(.); 11838d673b2Sbluhm } 11938d673b2Sbluhm 120414976a8Smlarkin . = ALIGN(0x1000); 121414976a8Smlarkin PROVIDE (edata = .); 122414976a8Smlarkin _edata = .; 123414976a8Smlarkin 124414976a8Smlarkin /* BSS starts right after padded data */ 125414976a8Smlarkin __kernel_bss_virt = .; 12657ae21efSmlarkin __kernel_bss_phys = . & 0xfffffff; 127414976a8Smlarkin .bss (__kernel_bss_virt) : AT (__kernel_bss_phys) 128414976a8Smlarkin { 129414976a8Smlarkin __bss_start = ABSOLUTE(.); 130414976a8Smlarkin __bss_size = SIZEOF(.bss); 131414976a8Smlarkin __bss_load = LOADADDR(.bss); 132414976a8Smlarkin *(.bss .bss.*) 133414976a8Smlarkin *(COMMON) 134414976a8Smlarkin /* Align after .bss to ensure correct alignment even if the 135414976a8Smlarkin * .bss section disappears because there are no input sections. 136414976a8Smlarkin */ 137414976a8Smlarkin . = ALIGN(0x1000); 138414976a8Smlarkin } :bss 139414976a8Smlarkin __kernel_bss_end = .; 1409bad4c31Smlarkin . = ALIGN(0x1000); 141414976a8Smlarkin _end = .; 142414976a8Smlarkin PROVIDE (end = .); 14357ae21efSmlarkin __kernel_end_phys = . & 0xfffffff; 144414976a8Smlarkin 145414976a8Smlarkin /* XXX - hack alert, since we are not C++, nuke these */ 146414976a8Smlarkin /DISCARD/ : 147414976a8Smlarkin { 148414976a8Smlarkin *(.note.GNU-stack) 149414976a8Smlarkin *(.eh_frame) 150414976a8Smlarkin } 151414976a8Smlarkin} 152