Attention is currently required from: Raul Rangel, Stefan Reinauer, Julius Werner, Jacob Garber, Iru Cai, Elyes Haouas.
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/40811 )
Change subject: arch,toolchain,xcompile: Use the compiler frontend as a linker ......................................................................
Patch Set 15:
(1 comment)
Patchset:
PS11:
Using clang it fails with: […]
`make V=1` shows the command and adding `-v` results in:
``` $ clang -v -nostdlib -r -o build/smm/smm.o -Wl,--whole-archive,--start-group build/smm/mainboard/emulation/qemu-q35/static.o build/smm/acpi/acpi_pm.o build/smm/arch/x86/memcpy.o build/smm/arch/x86/memmove_32.o build/smm/arch/x86/memset.o build/smm/arch/x86/mmap_boot.o build/smm/commonlib/bsd/cbfs_mcache.o build/smm/commonlib/bsd/cbfs_private.o build/smm/commonlib/bsd/elog.o build/smm/commonlib/iobuf.o build/smm/commonlib/mem_pool.o build/smm/commonlib/region.o build/smm/console/die.o build/smm/console/post.o build/smm/cpu/x86/pae/pgtbl.o build/smm/cpu/x86/smi_trigger.o build/smm/cpu/x86/smm/save_state.o build/smm/cpu/x86/smm/smm_module_handler.o build/smm/cpu/x86/tsc/delay_tsc.o build/smm/device/device_const.o build/smm/device/pci_ops.o build/smm/drivers/pc80/pc/i8254.o build/smm/drivers/pc80/rtc/mc146818rtc.o build/smm/lib/boot_device.o build/smm/lib/cbfs.o build/smm/lib/crc_byte.o build/smm/lib/delay.o build/smm/lib/fmap.o build/smm/lib/halt.o build/smm/lib/hexdump.o build/smm/lib/memcmp.o build/smm/lib/reset.o build/smm/lib/string.o build/smm/lib/version.o build/smm/mainboard/emulation/qemu-q35/memmap.o build/smm/mainboard/emulation/qemu-q35/smi.o build/smm/southbridge/intel/common/gpio.o build/smm/southbridge/intel/common/pmbase.o build/smm/southbridge/intel/common/pmutil.o build/smm/southbridge/intel/common/smihandler.o build/smm/southbridge/intel/i82801ix/smihandler.o -Wl,--no-whole-archive /usr/lib/gcc/x86_64-linux-gnu/12/32/libgcc.a -Wl,--end-group Debian clang version 14.0.6 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64 "/usr/bin/ld" --hash-style=both --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o build/smm/smm.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/lib -L/usr/lib -r --whole-archive --start-group build/smm/mainboard/emulation/qemu-q35/static.o build/smm/acpi/acpi_pm.o build/smm/arch/x86/memcpy.o build/smm/arch/x86/memmove_32.o build/smm/arch/x86/memset.o build/smm/arch/x86/mmap_boot.o build/smm/commonlib/bsd/cbfs_mcache.o build/smm/commonlib/bsd/cbfs_private.o build/smm/commonlib/bsd/elog.o build/smm/commonlib/iobuf.o build/smm/commonlib/mem_pool.o build/smm/commonlib/region.o build/smm/console/die.o build/smm/console/post.o build/smm/cpu/x86/pae/pgtbl.o build/smm/cpu/x86/smi_trigger.o build/smm/cpu/x86/smm/save_state.o build/smm/cpu/x86/smm/smm_module_handler.o build/smm/cpu/x86/tsc/delay_tsc.o build/smm/device/device_const.o build/smm/device/pci_ops.o build/smm/drivers/pc80/pc/i8254.o build/smm/drivers/pc80/rtc/mc146818rtc.o build/smm/lib/boot_device.o build/smm/lib/cbfs.o build/smm/lib/crc_byte.o build/smm/lib/delay.o build/smm/lib/fmap.o build/smm/lib/halt.o build/smm/lib/hexdump.o build/smm/lib/memcmp.o build/smm/lib/reset.o build/smm/lib/string.o build/smm/lib/version.o build/smm/mainboard/emulation/qemu-q35/memmap.o build/smm/mainboard/emulation/qemu-q35/smi.o build/smm/southbridge/intel/common/gpio.o build/smm/southbridge/intel/common/pmbase.o build/smm/southbridge/intel/common/pmutil.o build/smm/southbridge/intel/common/smihandler.o build/smm/southbridge/intel/i82801ix/smihandler.o --no-whole-archive /usr/lib/gcc/x86_64-linux-gnu/12/32/libgcc.a --end-group /usr/bin/ld: relocatable linking with relocations from format elf32-i386 (build/smm/mainboard/emulation/qemu-q35/static.o) to format elf64-x86-64 (build/smm/smm.o) is not supported clang: error: linker command failed with exit code 1 (use -v to see invocation) ```
Replacing `-m elf_x86_64` by `-m elf_i386` helps:
``` $ "/usr/bin/ld" --hash-style=both --build-id --eh-frame-hdr -m elf_i386 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o build/smm/smm.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/lib -L/usr/lib -r --whole-archive --start-group build/smm/mainboard/emulation/qemu-q35/static.o build/smm/acpi/acpi_pm.o build/smm/arch/x86/memcpy.o build/smm/arch/x86/memmove_32.o build/smm/arch/x86/memset.o build/smm/arch/x86/mmap_boot.o build/smm/commonlib/bsd/cbfs_mcache.o build/smm/commonlib/bsd/cbfs_private.o build/smm/commonlib/bsd/elog.o build/smm/commonlib/iobuf.o build/smm/commonlib/mem_pool.o build/smm/commonlib/region.o build/smm/console/die.o build/smm/console/post.o build/smm/cpu/x86/pae/pgtbl.o build/smm/cpu/x86/smi_trigger.o build/smm/cpu/x86/smm/save_state.o build/smm/cpu/x86/smm/smm_module_handler.o build/smm/cpu/x86/tsc/delay_tsc.o build/smm/device/device_const.o build/smm/device/pci_ops.o build/smm/drivers/pc80/pc/i8254.o build/smm/drivers/pc80/rtc/mc146818rtc.o build/smm/lib/boot_device.o build/smm/lib/cbfs.o build/smm/lib/crc_byte.o build/smm/lib/delay.o build/smm/lib/fmap.o build/smm/lib/halt.o build/smm/lib/hexdump.o build/smm/lib/memcmp.o build/smm/lib/reset.o build/smm/lib/string.o build/smm/lib/version.o build/smm/mainboard/emulation/qemu-q35/memmap.o build/smm/mainboard/emulation/qemu-q35/smi.o build/smm/southbridge/intel/common/gpio.o build/smm/southbridge/intel/common/pmbase.o build/smm/southbridge/intel/common/pmutil.o build/smm/southbridge/intel/common/smihandler.o build/smm/southbridge/intel/i82801ix/smihandler.o --no-whole-archive /usr/lib/gcc/x86_64-linux-gnu/12/32/libgcc.a --end-group $ ```
Passing `-m32` to the compiler frontend helps:
``` $ clang -v -m32 -nostdlib -r -o build/smm/smm.o -Wl,--whole-archive,--start-group build/smm/mainboard/emulation/qemu-q35/static.o build/smm/acpi/acpi_pm.o build/smm/arch/x86/memcpy.o build/smm/arch/x86/memmove_32.o build/smm/arch/x86/memset.o build/smm/arch/x86/mmap_boot.o build/smm/commonlib/bsd/cbfs_mcache.o build/smm/commonlib/bsd/cbfs_private.o build/smm/commonlib/bsd/elog.o build/smm/commonlib/iobuf.o build/smm/commonlib/mem_pool.o build/smm/commonlib/region.o build/smm/console/die.o build/smm/console/post.o build/smm/cpu/x86/pae/pgtbl.o build/smm/cpu/x86/smi_trigger.o build/smm/cpu/x86/smm/save_state.o build/smm/cpu/x86/smm/smm_module_handler.o build/smm/cpu/x86/tsc/delay_tsc.o build/smm/device/device_const.o build/smm/device/pci_ops.o build/smm/drivers/pc80/pc/i8254.o build/smm/drivers/pc80/rtc/mc146818rtc.o build/smm/lib/boot_device.o build/smm/lib/cbfs.o build/smm/lib/crc_byte.o build/smm/lib/delay.o build/smm/lib/fmap.o build/smm/lib/halt.o build/smm/lib/hexdump.o build/smm/lib/memcmp.o build/smm/lib/reset.o build/smm/lib/string.o build/smm/lib/version.o build/smm/mainboard/emulation/qemu-q35/memmap.o build/smm/mainboard/emulation/qemu-q35/smi.o build/smm/southbridge/intel/common/gpio.o build/smm/southbridge/intel/common/pmbase.o build/smm/southbridge/intel/common/pmutil.o build/smm/southbridge/intel/common/smihandler.o build/smm/southbridge/intel/i82801ix/smihandler.o -Wl,--no-whole-archive /usr/lib/gcc/x86_64-linux-gnu/12/32/libgcc.a -Wl,--end-group Debian clang version 14.0.6 Target: i386-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: 32;@m32 "/usr/bin/ld" --hash-style=both --build-id --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o build/smm/smm.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12/32 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../lib32 -L/lib/../lib32 -L/usr/lib/../lib32 -L/lib -L/usr/lib -r --whole-archive --start-group build/smm/mainboard/emulation/qemu-q35/static.o build/smm/acpi/acpi_pm.o build/smm/arch/x86/memcpy.o build/smm/arch/x86/memmove_32.o build/smm/arch/x86/memset.o build/smm/arch/x86/mmap_boot.o build/smm/commonlib/bsd/cbfs_mcache.o build/smm/commonlib/bsd/cbfs_private.o build/smm/commonlib/bsd/elog.o build/smm/commonlib/iobuf.o build/smm/commonlib/mem_pool.o build/smm/commonlib/region.o build/smm/console/die.o build/smm/console/post.o build/smm/cpu/x86/pae/pgtbl.o build/smm/cpu/x86/smi_trigger.o build/smm/cpu/x86/smm/save_state.o build/smm/cpu/x86/smm/smm_module_handler.o build/smm/cpu/x86/tsc/delay_tsc.o build/smm/device/device_const.o build/smm/device/pci_ops.o build/smm/drivers/pc80/pc/i8254.o build/smm/drivers/pc80/rtc/mc146818rtc.o build/smm/lib/boot_device.o build/smm/lib/cbfs.o build/smm/lib/crc_byte.o build/smm/lib/delay.o build/smm/lib/fmap.o build/smm/lib/halt.o build/smm/lib/hexdump.o build/smm/lib/memcmp.o build/smm/lib/reset.o build/smm/lib/string.o build/smm/lib/version.o build/smm/mainboard/emulation/qemu-q35/memmap.o build/smm/mainboard/emulation/qemu-q35/smi.o build/smm/southbridge/intel/common/gpio.o build/smm/southbridge/intel/common/pmbase.o build/smm/southbridge/intel/common/pmutil.o build/smm/southbridge/intel/common/smihandler.o build/smm/southbridge/intel/i82801ix/smihandler.o --no-whole-archive /usr/lib/gcc/x86_64-linux-gnu/12/32/libgcc.a --end-group $ ```
Also passing `$(CFLAGS_common)` to the SMM targets results in:
clang: error: argument unused during compilation: '-nostdinc' [-Werror,-Wunused-command-line-argument]
and it does not contain `-m32`.
So linking works with the coreboot toolchain, when passing `$(CFLAGS_smm)` and `$(CFLAGS_smmstub)`. Some boards fail to build with clang, as the LLVM linker LLD is not found:
LINK cbfs/fallback/verstage.debug clang-15: error: unable to execute command: Executable "ld.lld" doesn't exist! clang-15: error: ld.lld command failed with exit code 1 (use -v to see invocation) make[2]: *** [src/arch/arm/Makefile.inc:64: /cb-build/coreboot-gerrit.0/clang/GOOGLE_BERKNIP/cbfs/fallback/verstage.debug] Error 1
With the Debian toolchain it links with GCC, but it fails later:
``` $ make V=1 […] clang -pipe -g -nostdinc -std=gnu11 -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wno-trigraphs -Wimplicit-fallthrough -Wshadow -Wdate-time -Wtype-limits -Wvla -Wold-style-definition -Wdangling-else -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -fno-pie -Werror -Os -target i386-elf -m32 -Wl,-b,elf32-i386 -Wl,-melf_i386 -Qunused-arguments -m32 -Wno-unused-variable -Wno-unused-function -Wno-tautological-compare -Wno-shift-overflow -Wno-address-of-packed-member -Wno-initializer-overrides -fbracket-depth=2048 -march=i686 -mno-mmx -Wl,--gc-sections,--nmagic,-nostdlib,-static -Wl,--emit-relocs -z defs -Bsymbolic -T build/rmodules_x86_32/lib/rmodule.ld -Wl,--defsym=__heap_size=0 -o build/smm/smm.elf -Wl,--whole-archive,--start-group build/smm/smm.o -Wl,--end-group /usr/bin/ld: build/smm/smm.o: warning: relocation in read-only section `.rodata.southbridge_smi' /usr/bin/ld: warning: build/smm/smm.elf has a LOAD segment with RWX permissions /usr/bin/ld: warning: creating DT_TEXTREL in a PIE /usr/bin/ld: warning: .note.gnu.build-id section discarded, --build-id ignored x86_64-linux-gnu-nm -n build/smm/smm.elf > build/smm/smm.map build/util/cbfstool/rmodtool -i build/smm/smm.elf -o build/smm/smm.elf.rmod E: Relocations apply to an invalid section: 0 E: Couldn't parse ELF! free(): double free detected in tcache 2 make: *** [src/lib/Makefile.inc:342: build/smm/smm.elf.rmod] Abgebrochen (Speicherauszug erstellt) ```