From 843b0c9d0f192aa9cf85fa7cdc27c5f8c4d0aa15 Mon Sep 17 00:00:00 2001 From: Hesham Almatary Date: Mon, 15 Jan 2024 16:25:18 +0000 Subject: [PATCH] elfloader/linker: Unify linker.lds in one file This allows to use the same file for both Arm and RISC-V. Furthermore, this new file is more portable and works with both LLVM/lld and GNU's ld, unlike the removed Arm's one which contains directives and sections that lld does not handle (e.g., .interp, INSERT BEFORE .hash). Signed-off-by: Hesham Almatary --- elfloader-tool/CMakeLists.txt | 2 +- elfloader-tool/src/arch-arm/linker.lds | 51 ------------------- .../src/{arch-riscv => }/linker.lds | 8 ++- 3 files changed, 8 insertions(+), 53 deletions(-) delete mode 100644 elfloader-tool/src/arch-arm/linker.lds rename elfloader-tool/src/{arch-riscv => }/linker.lds (89%) diff --git a/elfloader-tool/CMakeLists.txt b/elfloader-tool/CMakeLists.txt index 2a4d7884..9a49f10d 100644 --- a/elfloader-tool/CMakeLists.txt +++ b/elfloader-tool/CMakeLists.txt @@ -106,7 +106,7 @@ config_option( add_config_library(elfloader "${configure_string}") add_compile_options(-D_XOPEN_SOURCE=700 -ffreestanding -Wall -Werror -W -Wextra) -set(linkerScript "${CMAKE_CURRENT_LIST_DIR}/src/arch-${KernelArch}/linker.lds") +set(linkerScript "${CMAKE_CURRENT_LIST_DIR}/src/linker.lds") if(KernelArchRiscV) add_compile_options(-mcmodel=medany) endif() diff --git a/elfloader-tool/src/arch-arm/linker.lds b/elfloader-tool/src/arch-arm/linker.lds deleted file mode 100644 index f7de12cf..00000000 --- a/elfloader-tool/src/arch-arm/linker.lds +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -#include "image_start_addr.h" - -SECTIONS -{ - .interp : { *(.interp) } -} -INSERT BEFORE .hash; - -SECTIONS -{ - . = IMAGE_START_ADDR; - _text = .; - .start : - { - *(.text.start) - } -} -INSERT BEFORE .text; - -SECTIONS -{ - .bss (NOLOAD) : { - . = ALIGN(0x1000); - core_stack_alloc = .; - . += CONFIG_MAX_NUM_NODES * (1 << 12); - core_stack_alloc_end = .; - _bss = .; - *(.bss) - _bss_end = .; - } -} - -SECTIONS -{ - . = ALIGN(8); - ._archive_cpio : { - _archive_start = .; - *(._archive_cpio) - _archive_end = .; - } -} -INSERT AFTER .eh_frame; diff --git a/elfloader-tool/src/arch-riscv/linker.lds b/elfloader-tool/src/linker.lds similarity index 89% rename from elfloader-tool/src/arch-riscv/linker.lds rename to elfloader-tool/src/linker.lds index 2076b71a..c6d9338e 100644 --- a/elfloader-tool/src/arch-riscv/linker.lds +++ b/elfloader-tool/src/linker.lds @@ -55,8 +55,14 @@ SECTIONS *(.data.*) } . = ALIGN(16); - .bss : + .bss (NOLOAD) : { +#ifdef CONFIG_ARCH_ARM + . = ALIGN(0x1000); + core_stack_alloc = .; + . += CONFIG_MAX_NUM_NODES * (1 << 12); + core_stack_alloc_end = .; +#endif _bss = .; *(.sbss*) *(.bss)