From c74e3642b3e99ba3e0c41a596625d66b1e0ffe8c Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Wed, 1 Sep 2021 15:33:44 +0930 Subject: [PATCH 1/3] bios: Fix PHDR link error binutils 2.34 contains stricter checks for sections that are not included in the linker script, resulting in this error: ld: bios.elf: error: PHDR segment not covered by LOAD segment From the 2.34 NEWS: The ld check for "PHDR segment not covered by LOAD segment" is more effective, catching cases that were wrongly allowed by previous versions of ld. If you see this error it is likely you are linking with a bad linker script or the binary you are building is not intended to be loaded by a dynamic loader. In the latter case --no-dynamic-linker is appropriate. As the BIOS runs bare metal, we do not need to emit a PHDR segment. Signed-off-by: Joel Stanley --- litex/soc/software/common.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/common.mak b/litex/soc/software/common.mak index ec14f40d2..f21291976 100644 --- a/litex/soc/software/common.mak +++ b/litex/soc/software/common.mak @@ -53,7 +53,7 @@ INCLUDES = -I$(SOC_DIRECTORY)/software/include/base \ COMMONFLAGS = $(DEPFLAGS) -Os $(CPUFLAGS) -g3 -fomit-frame-pointer -Wall -fno-builtin -nostdinc -fno-stack-protector $(INCLUDES) CFLAGS = $(COMMONFLAGS) -fexceptions -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes CXXFLAGS = $(COMMONFLAGS) -std=c++11 -I$(SOC_DIRECTORY)/software/include/basec++ -fexceptions -fno-rtti -ffreestanding -LDFLAGS = -nostdlib -nodefaultlibs -L$(BUILDINC_DIRECTORY) +LDFLAGS = -nostdlib -nodefaultlibs -Wl,--no-dynamic-linker -L$(BUILDINC_DIRECTORY) define compilexx $(CX) -c $(CXXFLAGS) $(1) $< -o $@ From d91c8dcfa218de3b69f6c3c20096f9a811bd7057 Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Wed, 1 Sep 2021 15:41:24 +0930 Subject: [PATCH 2/3] bios: Fix build-id link error New version of binutils contain stricter checks for sections that are not included in the linker script, resulting in this error: ld: error: no memory region specified for loadable section `.note.gnu.build-id' Disable this feature as there is no use for it on bare metal systems. Signed-off-by: Joel Stanley --- litex/soc/software/common.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/common.mak b/litex/soc/software/common.mak index f21291976..6d8f3f11e 100644 --- a/litex/soc/software/common.mak +++ b/litex/soc/software/common.mak @@ -53,7 +53,7 @@ INCLUDES = -I$(SOC_DIRECTORY)/software/include/base \ COMMONFLAGS = $(DEPFLAGS) -Os $(CPUFLAGS) -g3 -fomit-frame-pointer -Wall -fno-builtin -nostdinc -fno-stack-protector $(INCLUDES) CFLAGS = $(COMMONFLAGS) -fexceptions -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes CXXFLAGS = $(COMMONFLAGS) -std=c++11 -I$(SOC_DIRECTORY)/software/include/basec++ -fexceptions -fno-rtti -ffreestanding -LDFLAGS = -nostdlib -nodefaultlibs -Wl,--no-dynamic-linker -L$(BUILDINC_DIRECTORY) +LDFLAGS = -nostdlib -nodefaultlibs -Wl,--no-dynamic-linker -Wl,--build-id=none -L$(BUILDINC_DIRECTORY) define compilexx $(CX) -c $(CXXFLAGS) $(1) $< -o $@ From 722772a3d801ba07eeca745099b87f4dbf733e78 Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Wed, 1 Sep 2021 15:43:56 +0930 Subject: [PATCH 3/3] microwatt: Fix relocation error when linking When building with GCC 11: ../libbase/crt0.o: in function `_start': litex/soc/cores/cpu/microwatt/crt0.S:54:(.text+0x38): relocation truncated to fit: R_PPC64_GOT16_DS against symbol `_fdata' defined in .data section in bios.elf litex/soc/cores/cpu/microwatt/crt0.S:55:(.text+0x3c): relocation truncated to fit: R_PPC64_GOT16_DS against symbol `_edata' defined in .data section in bios.elf litex/soc/cores/cpu/microwatt/crt0.S:56:(.text+0x40): relocation truncated to fit: R_PPC64_GOT16_DS against symbol `_fdata_rom' defined in *ABS* section in bios.elf litex/soc/cores/cpu/microwatt/crt0.S:68:(.text+0x68): relocation truncated to fit: R_PPC64_GOT16_DS against symbol `_fbss' defined in .bss section in bios.elf litex/soc/cores/cpu/microwatt/crt0.S:69:(.text+0x6c): relocation truncated to fit: R_PPC64_GOT16_DS against symbol `_ebss' defined in .bss section in bios.elf litex/soc/cores/cpu/microwatt/crt0.S:80:(.text+0x90): relocation truncated to fit: R_PPC64_GOT16_DS against symbol `_fstack' defined in .bss section in bios.elf boot.o: in function `copy_file_from_sdcard_to_ram': litex/soc/software/bios/boot.c:622:(.text+0x18): relocation truncated to fit: R_PPC64_TOC16_DS against `.toc' litex/soc/software/bios/boot.c:627:(.text+0x5c): relocation truncated to fit: R_PPC64_TOC16_DS against `.toc'+8 litex/soc/software/bios/boot.c:633:(.text+0x8c): relocation truncated to fit: R_PPC64_TOC16_DS against `.toc'+10 litex/soc/software/bios/boot.c:639:(.text+0xdc): relocation truncated to fit: R_PPC64_TOC16_DS against `.toc'+18 litex/soc/software/bios/boot.c:650:(.text+0x128): additional relocation overflows omitted from the output This is because we pass -mcmodel=small. As the PowerPC ELF ABI describes, the small code model restricts the relocations to 16-bit offsets[1]. If we omit the option we get the default, which is the medium model allowing 32-bit offsets. http://openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240_19143.html Signed-off-by: Joel Stanley --- litex/soc/cores/cpu/microwatt/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/litex/soc/cores/cpu/microwatt/core.py b/litex/soc/cores/cpu/microwatt/core.py index 4c3c20a31..8b58fcf71 100644 --- a/litex/soc/cores/cpu/microwatt/core.py +++ b/litex/soc/cores/cpu/microwatt/core.py @@ -58,7 +58,6 @@ class Microwatt(CPU): flags += "-mlittle-endian " flags += "-mstrict-align " flags += "-fno-stack-protector " - flags += "-mcmodel=small " flags += "-D__microwatt__ " return flags