Sam Elliott | 120c737 | 2020-11-03 15:14:46 +0000 | [diff] [blame] | 1 | /* Copyright lowRISC contributors. */ |
| 2 | /* Licensed under the Apache License, Version 2.0, see LICENSE for details. */ |
| 3 | /* SPDX-License-Identifier: Apache-2.0 */ |
| 4 | |
| 5 | /** |
| 6 | * Partial Linker Script for OpenTitan Device Executables |
| 7 | * |
| 8 | * This Linker Script controls all the sections that we need in the ELF file for |
| 9 | * a device executable, but which are not mapped into memory or otherwise |
| 10 | * allocated on the device itself. |
| 11 | * |
| 12 | * These contain amongst other things: |
| 13 | * - debugging information needed by DV logging, |
| 14 | * - DWARF Sections |
| 15 | * - RISC-V Attributes sections |
| 16 | * |
| 17 | * This is also where we specify the sections to discard, because it is a common |
| 18 | * file between all our other linker scripts. |
| 19 | * |
| 20 | * This partial linker script requires the main linker script to define the |
| 21 | * following symbols: |
| 22 | * - _dv_log_offset |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * Start DV Sections. |
| 27 | * |
| 28 | * The following sections are used by DV to implement logging in an |
| 29 | * alternate way, which enables simulation speed up by completely avoiding |
| 30 | * any string format processing or even the actual transmission of log data |
| 31 | * to a real peripheral. |
| 32 | * |
| 33 | * These sections are marked as dummy so that they can still be extracted |
| 34 | * using readelf or similar utilities. As such, the content in these sections |
| 35 | * is not relevant for the actual SW code and can be safely discarded. |
| 36 | */ |
| 37 | |
| 38 | /** |
| 39 | * The following section contains log fields constructed from the logs using |
| 40 | * the log_fields_t struct defined in sw/device/lib/runtime/log.h. The size of |
| 41 | * each log field is fixed - 20 bytes. |
| 42 | */ |
| 43 | .logs.fields _dv_log_offset (INFO): { |
Miguel Young de la Sota | 7e71aa7 | 2022-04-04 12:12:18 -0400 | [diff] [blame] | 44 | /* Force this section to always be emitted. The logs extraction script expects |
| 45 | * this section to be present in the ELF file, but the linker will not emit it |
Miguel Young de la Sota | 3aeb9a2 | 2022-04-06 10:14:06 -0400 | [diff] [blame] | 46 | * if there are no outputs (i.e, the *(.logs.fields) statement) with contents. |
Miguel Young de la Sota | 7e71aa7 | 2022-04-04 12:12:18 -0400 | [diff] [blame] | 47 | * |
| 48 | * However, almost any assignment will implicitly create even an empty section, |
| 49 | * including the very silly . = . (set the program counter to itself). |
| 50 | * |
| 51 | * See https://sourceware.org/binutils/docs-2.29/ld/Output-Section-Discarding.html. */ |
| 52 | . = .; |
Sam Elliott | 120c737 | 2020-11-03 15:14:46 +0000 | [diff] [blame] | 53 | *(.logs.fields) |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * End DV Sections |
| 58 | */ |
| 59 | |
| 60 | /* ELF-internal Sections. */ |
| 61 | .symtab 0x0 : { *(.symtab) } |
| 62 | .strtab 0x0 : { *(.strtab) } |
| 63 | .shstrtab 0x0 : { *(.shstrtab) } |
| 64 | |
| 65 | /* Preserve RISC-V Attributes */ |
| 66 | .riscv.attributes 0x0 : { *(.riscv.attributes) } |
| 67 | |
| 68 | /* Preserve Debug Info in ELF Files */ |
| 69 | .debug_info 0x0 : { *(.debug_info) } |
| 70 | .debug_abbrev 0x0 : { *(.debug_abbrev) } |
| 71 | .debug_aranges 0x0 : { *(.debug_aranges) } |
| 72 | .debug_line 0x0 : { *(.debug_line) } |
| 73 | .debug_loc 0x0 : { *(.debug_loc) } |
| 74 | .debug_ranges 0x0 : { *(.debug_ranges) } |
| 75 | .debug_str 0x0 : { *(.debug_str) } |
| 76 | .debug_frame 0x0 : { *(.debug_frame) } |
Vincent Palatin | a353e5b | 2021-11-03 09:24:47 +0100 | [diff] [blame] | 77 | .debug_line_str 0x0 : { *(.debug_line_str) } |
| 78 | .debug_loclists 0x0 : { *(.debug_loclists) } |
| 79 | .debug_rnglists 0x0 : { *(.debug_rnglists) } |
Luís Marques | a5f7a0f | 2022-03-23 11:08:54 +0100 | [diff] [blame] | 80 | .debug_addr 0x0 : { *(.debug_addr) } |
| 81 | .debug_str_offsets 0x0 : { *(.debug_str_offsets) } |
Sam Elliott | 120c737 | 2020-11-03 15:14:46 +0000 | [diff] [blame] | 82 | |
| 83 | /* Discarded Sections (Not needed in device images). */ |
| 84 | /DISCARD/ : { |
| 85 | /* We don't keep unwind information */ |
| 86 | *(.eh_frame) |
| 87 | *(.eh_frame_hdr) |
| 88 | |
| 89 | /* Compiler Information */ |
| 90 | *(.comment) |
| 91 | *(.comment.*) |
| 92 | |
| 93 | /* Other Notes */ |
| 94 | *(.note) |
| 95 | *(.note.*) |
| 96 | |
| 97 | /* Relocations */ |
| 98 | *(.rela.*) |
| 99 | *(.rela.dyn) |
| 100 | |
| 101 | /* STAB Debugging Info - We Use DWARF */ |
| 102 | *(.stab) |
| 103 | *(.stab.*) |
| 104 | *(.stabstr) |
Sam Elliott | 1d1ac6c | 2020-11-04 19:03:20 +0000 | [diff] [blame] | 105 | |
| 106 | /* COMMON Sections */ |
| 107 | *(COMMON) |
Sam Elliott | 120c737 | 2020-11-03 15:14:46 +0000 | [diff] [blame] | 108 | } |