From cd571e927d213b4c5af1a040da5b88b559f08258 Mon Sep 17 00:00:00 2001 From: "Leon M. Busch-George" Date: Thu, 25 Jan 2024 20:45:10 +0100 Subject: [PATCH 1/2] firmware: discard dynsym section With a bare-metal linkers (e.g. riscv64-elf-ld), there exists no dynsym section. The dynsym section is not used by OpenSBI, so just discard it if it exists. --- firmware/fw_base.ldS | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS index c15ccdbf66..79c0d75b44 100644 --- a/firmware/fw_base.ldS +++ b/firmware/fw_base.ldS @@ -50,12 +50,16 @@ /* End of the read-only data sections */ + /DISCARD/ : { + *(.dynsym) + } + /* * PMP regions must be to be power-of-2. RX/RW will have separate * regions, so ensure that the split is power-of-2. */ . = ALIGN(1 << LOG2CEIL((SIZEOF(.rodata) + SIZEOF(.text) - + SIZEOF(.dynsym) + SIZEOF(.rela.dyn)))); + + SIZEOF(.rela.dyn)))); PROVIDE(_fw_rw_start = .); From 708aa0b4971d038621bf4bc68bd97be2f73a1409 Mon Sep 17 00:00:00 2001 From: "Leon M. Busch-George" Date: Thu, 25 Jan 2024 20:50:56 +0100 Subject: [PATCH 2/2] check for --exclude-libs While writing to the dynsym is futile, the --exclude-libs options is not recognized by all linkers (e.g. riscv64-elf-ld.bfd) --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index de4e73a0e3..630e35f578 100644 --- a/Makefile +++ b/Makefile @@ -167,6 +167,9 @@ endif # Check whether the linker supports creating PIEs OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n) +# Check whether the linker supports --exclude-libs +OPENSBI_LD_EXCLUDE_LIBS := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) "-Wl,--exclude-libs,ALL" -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n) + # Check whether the compiler supports -m(no-)save-restore CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mno-save-restore -x c /dev/null -o /dev/null 2>&1 | grep -e "-save-restore" >/dev/null && echo n || echo y) @@ -375,7 +378,9 @@ ASFLAGS += $(firmware-asflags-y) ARFLAGS = rcs ELFFLAGS += $(USE_LD_FLAG) +ifeq ($(OPENSBI_LD_EXCLUDE_LIBS),y) ELFFLAGS += -Wl,--exclude-libs,ALL +endif ELFFLAGS += -Wl,--build-id=none ELFFLAGS += $(platform-ldflags-y) ELFFLAGS += $(firmware-ldflags-y)