fix(esp_system): enable linking with LLD on RISC-V targets

This commit is contained in:
Stefan Stipanovic
2026-08-13 21:23:36 +02:00
parent b2672c7937
commit d0ae774d59
17 changed files with 147 additions and 11 deletions
@@ -17,11 +17,16 @@
#define ASTDBG_ISR _tee_ns_intr_handler
#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD
.section .exception_vectors_table.text
.section .exception_vectors_table.text, "ax"
/* Prevent the compiler from generating 2-byte instruction in the vector tables */
.option push
.option norvc
/* The vector tables have a fixed layout, so keep linker relaxation from
* touching them: with relaxation enabled the assembler emits the .balign
* padding as R_RISCV_ALIGN-managed bytes, of which GNU ld may retain more
* than the exact amount, changing the table size between builds. */
.option norelax
/**
* Non-hardware vectored interrupt entry. MTVEC CSR points here.
@@ -56,6 +56,7 @@
.comment 0 : { *(.comment) }
.note.GNU-stack 0: { *(.note.GNU-stack) }
#include "ld.elf.internal.sections"
#if CONFIG_IDF_TARGET_ARCH_RISCV
.riscv.attributes 0: { *(.riscv.attributes) }
@@ -70,5 +71,18 @@
*/
*(.rela.*)
*(.got .got.plt) /* TODO: GCC-382 */
/**
* GNU ld removes them via --gc-sections; LLD treats them as GC roots,
* so they must be discarded explicitly to not trip --orphan-handling=error.
*/
*(.init)
*(.init_array)
*(.init_array.*)
*(.fini)
*(.fini_array)
*(.fini_array.*)
*(.eh_frame_hdr)
*(.eh_frame)
}
#endif
@@ -18,11 +18,13 @@ target_linker_script(${COMPONENT_LIB} INTERFACE "${heap_dir}/port/${target}/ld/$
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ld")
idf_component_get_property(esp_system_dir esp_system COMPONENT_DIR)
# Preprocess esp_tee.ld.in linker script to include configuration, becomes esp_tee.ld
add_custom_command(
OUTPUT ${ld_output}
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o ${ld_output} -I ${config_dir}
-I "${CMAKE_CURRENT_LIST_DIR}" ${ld_input}
-I "${CMAKE_CURRENT_LIST_DIR}" -I "${esp_system_dir}/ld" ${ld_input}
MAIN_DEPENDENCY ${ld_input}
DEPENDS ${sdkconfig_header}
COMMENT "Generating esp_tee.ld linker script..."