Attention is currently required from: Julius Werner, Jérémy Compostella, Martin L Roth, Philipp Hug, ron minnich.

Arthur Heymans has uploaded this change for review.

View Change

YOU_SHALL_NOT_MERGE! get LTO working with clang (x86, aarch64, arm)

Very WIP.

Change-Id: If7c09e08203e62e4bd0547f0cd34370090cb12b6
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
---
M Makefile.mk
M src/Kconfig
M src/arch/arm/Makefile.mk
M src/arch/riscv/Makefile.mk
M src/arch/x86/Kconfig
M src/arch/x86/Makefile.mk
M src/arch/x86/bootblock.ld
M src/cpu/x86/reset16.S
M src/lib/program.ld
M util/cbfstool/cbfs-mkstage.c
M util/xcompile/xcompile
11 files changed, 43 insertions(+), 29 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/24/80724/1
diff --git a/Makefile.mk b/Makefile.mk
index bfd5a29..66baebd 100644
--- a/Makefile.mk
+++ b/Makefile.mk
@@ -365,7 +365,7 @@
cbfs-files-processor-struct= \
$(eval $(2): $(1) $(obj)/build.h $(obj)/fmap_config.h $(KCONFIG_AUTOHEADER); \
printf " CC+STRIP $(1)\n"; \
- $(CC_ramstage) -MMD $(CPPFLAGS_ramstage) $(CFLAGS_ramstage) --param asan-globals=0 $$(ramstage-c-ccopts) -include $(KCONFIG_AUTOHEADER) -MT $(2) -o $(2).tmp -c $(1) && \
+ $(CC_ramstage) -MMD $(CPPFLAGS_ramstage) $(CFLAGS_ramstage) --param asan-globals=0 $$(ramstage-c-ccopts) -include $(KCONFIG_AUTOHEADER) -MT $(2) -o $(2).tmp -c $(1) -fno-lto && \
$(OBJCOPY_ramstage) -O binary --only-section='.data*' --only-section='.bss*' --set-section-flags .bss*=alloc,contents,load $(2).tmp $(2); \
rm -f $(2).tmp) \
$(eval DEPENDENCIES += $(2).d)
@@ -496,7 +496,7 @@
CFLAGS_common += -Wshadow -Wdate-time -Wtype-limits -Wvla -Wold-style-definition
CFLAGS_common += -Wdangling-else -Wmissing-include-dirs
CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
-CFLAGS_common += -fstrict-aliasing -ffunction-sections -fdata-sections -fno-pie
+CFLAGS_common += -fstrict-aliasing -ffunction-sections -fdata-sections -fno-pie -Wno-single-bit-bitfield-constant-conversion -ffunction-sections -Wl,--no-eh-frame-hdr -ffreestanding
ifeq ($(CONFIG_COMPILER_GCC),y)
CFLAGS_common += -Wold-style-declaration
# Don't add these GCC specific flags when running scan-build
@@ -557,7 +557,7 @@
# Disable style checks for now
ADAFLAGS_common += -gnatyN

-LDFLAGS_common := -Wl,--gc-sections,--nmagic,-nostdlib,-static
+LDFLAGS_common := -Wl,--gc-sections,--nmagic,-nostdlib,-static -Wno-stack-usage -Wno-lto-type-mismatch -fuse-ld=lld -Wl,--no-eh-frame-hdr

# Workaround for RISC-V linker bug, merge back into above line when fixed.
# https://sourceware.org/bugzilla/show_bug.cgi?id=27180
diff --git a/src/Kconfig b/src/Kconfig
index 36304c2..2dd8e29 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -130,7 +130,7 @@
config LTO
bool "Use link time optimization (LTO)"
default n
- depends on COMPILER_GCC
+# depends on COMPILER_GCC
help
Compile with link time optimization. This can often decrease the
final binary size, but may increase compilation time.
diff --git a/src/arch/arm/Makefile.mk b/src/arch/arm/Makefile.mk
index b4531f3..ddf8fe4 100644
--- a/src/arch/arm/Makefile.mk
+++ b/src/arch/arm/Makefile.mk
@@ -45,11 +45,11 @@

$(objcbfs)/bootblock.debug: $$(bootblock-objs)
@printf " LINK $(subst $(obj)/,,$(@))\n"
- $(CC_bootblock) $(LDFLAGS_bootblock) -o $@ -L$(obj) -T $(call src-to-obj,bootblock,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(bootblock-objs)) -Wl,--end-group
+ $(CC_bootblock) $(CFLAGS_bootblock) $(LDFLAGS_bootblock) -o $@ -L$(obj) -T $(call src-to-obj,bootblock,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(bootblock-objs)) -Wl,--end-group

$(objcbfs)/decompressor.debug: $$(decompressor-objs)
@printf " LINK $(subst $(obj)/,,$(@))\n"
- $(CC_bootblock) $(LDFLAGS_bootblock) -o $@ -L$(obj) -T $(call src-to-obj,decompressor,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(decompressor-objs)) -Wl,--end-group
+ $(CC_bootblock) $(CFLAGS_bootblock) $(LDFLAGS_bootblock) -o $@ -L$(obj) -T $(call src-to-obj,decompressor,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(decompressor-objs)) -Wl,--end-group

endif # CONFIG_ARCH_BOOTBLOCK_ARM

@@ -61,7 +61,7 @@

$(objcbfs)/verstage.debug: $$(verstage-objs)
@printf " LINK $(subst $(obj)/,,$(@))\n"
- $(CC_verstage) $(LDFLAGS_verstage) -o $@ -L$(obj) -T $(call src-to-obj,verstage,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(verstage-objs)) -Wl,--end-group
+ $(CC_verstage) $(CFLAGS_verstage) $(LDFLAGS_verstage) -o $@ -L$(obj) -T $(call src-to-obj,verstage,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(verstage-objs)) -Wl,--end-group

verstage-y += boot.c
verstage-y += div0.c
@@ -94,7 +94,7 @@

$(objcbfs)/romstage.debug: $$(romstage-objs)
@printf " LINK $(subst $(obj)/,,$(@))\n"
- $(CC_romstage) $(LDFLAGS_romstage) -o $@ -L$(obj) -T $(call src-to-obj,romstage,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(romstage-objs)) -Wl,--end-group
+ $(CC_romstage) $(CFLAGS_romstage) $(LDFLAGS_romstage) -o $@ -L$(obj) -T $(call src-to-obj,romstage,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(romstage-objs)) -Wl,--end-group

endif # CONFIG_ARCH_ROMSTAGE_ARM

@@ -107,6 +107,9 @@
ramstage-y += stages.c
ramstage-y += div0.c
ramstage-y += eabi_compat.c
+
+$(call src-to-obj,ramstage,$(dir)/eabi_compat.c): CFLAGS_ramstage += -fno-lto
+
ramstage-y += boot.c
ramstage-y += tables.c
ramstage-y += memset.S
@@ -124,6 +127,6 @@

$(objcbfs)/ramstage.debug: $$(ramstage-objs)
@printf " CC $(subst $(obj)/,,$(@))\n"
- $(CC_ramstage) $(LDFLAGS_ramstage) -o $@ -L$(obj) -T $(call src-to-obj,ramstage,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(ramstage-objs)) -Wl,--end-group
+ $(CC_ramstage) $(CFLAGS_ramstage) $(LDFLAGS_ramstage) $(COMPILER_RT_FLAGS_ramstage) -o $@ -L$(obj) -T $(call src-to-obj,ramstage,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(ramstage-objs)) -Wl,--no-whole-archive $(COMPILER_RT_ramstage) -Wl,--end-group

endif # CONFIG_ARCH_RAMSTAGE_ARM
diff --git a/src/arch/riscv/Makefile.mk b/src/arch/riscv/Makefile.mk
index 926116e..04ca9c1 100644
--- a/src/arch/riscv/Makefile.mk
+++ b/src/arch/riscv/Makefile.mk
@@ -80,7 +80,7 @@
@printf " LINK $(subst $(obj)/,,$(@))\n"
$(CC_bootblock) $(LDFLAGS_bootblock) -o $@ -L$(obj) \
-T $(call src-to-obj,bootblock,$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--whole-archive,--start-group $(filter-out %.ld,$(bootblock-objs)) \
- $(LIBGCC_FILE_NAME_bootblock) -Wl,--end-group $(COMPILER_RT_bootblock)
+ $(LIBGCC_FILE_NAME_bootblock) -Wl,--end-group $(COMPILER_RT_bootblock) -Wl,--relax-gp

bootblock-c-ccopts += $(riscv_flags)
bootblock-S-ccopts += $(riscv_asm_flags)
diff --git a/src/arch/x86/Kconfig b/src/arch/x86/Kconfig
index 0c11653..395aa55 100644
--- a/src/arch/x86/Kconfig
+++ b/src/arch/x86/Kconfig
@@ -5,6 +5,7 @@
select PCI
select RELOCATABLE_MODULES
select HAVE_ASAN_IN_RAMSTAGE
+# select FIXED_BOOTBLOCK_SIZE

if ARCH_X86

diff --git a/src/arch/x86/Makefile.mk b/src/arch/x86/Makefile.mk
index 0973cc7..225106d 100644
--- a/src/arch/x86/Makefile.mk
+++ b/src/arch/x86/Makefile.mk
@@ -63,7 +63,7 @@

$$(objcbfs)/$(1).debug: $$$$($(1)-libs) $$$$($(1)-objs)
@printf " LINK $$(subst $$(obj)/,,$$(@))\n"
- $$(CC_$(1)) $$(LDFLAGS_$(1)) -o $$@ -L$$(obj) $$(COMPILER_RT_FLAGS_$(1)) -Wl,--whole-archive,--start-group $$(filter-out %.ld,$$($(1)-objs)) $$($(1)-libs) -Wl,--no-whole-archive $$(COMPILER_RT_$(1)) -Wl,--end-group -T $(call src-to-obj,$(1),$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--oformat $(2)
+ $$(CC_$(1)) $$(LDFLAGS_$(1)) -o $$@ -L$$(obj) $$(COMPILER_RT_FLAGS_$(1)) -Wl,--whole-archive,--start-group $$(filter-out %.ld,$$($(1)-objs)) $$($(1)-libs) -Wl,--no-whole-archive $$(COMPILER_RT_$(1)) -Wl,--end-group -T $(call src-to-obj,$(1),$(CONFIG_MEMLAYOUT_LD_FILE)) -Wl,--oformat,$(2)
endef

###############################################################################
diff --git a/src/arch/x86/bootblock.ld b/src/arch/x86/bootblock.ld
index d59eb27..1d744f7 100644
--- a/src/arch/x86/bootblock.ld
+++ b/src/arch/x86/bootblock.ld
@@ -16,8 +16,9 @@
#if CONFIG(FIXED_BOOTBLOCK_SIZE)
. = _ebootblock - CONFIG_C_ENV_BOOTBLOCK_SIZE;
#else
- . = BOOTBLOCK_TOP - PROGRAM_SZ;
- . = ALIGN(64);
+ . = 0xffffff00 - PROGRAM_SZ;
+ . = ALIGN(4096);
+ . -= 4096;
#endif

_bootblock = .;
@@ -29,9 +30,9 @@
* may cause the total size of a section to change when the start
* address gets applied.
*/
- PROGRAM_SZ = SIZEOF(.text) + 512;
+ PROGRAM_SZ = SIZEOF(.text);

- . = MIN(_ECFW_PTR, MIN(_ID_SECTION, _FIT_POINTER)) - EARLYASM_SZ;
+ . = _ID_SECTION - EARLYASM_SZ;
. = CONFIG(SIPI_VECTOR_IN_ROM) ? ALIGN(4096) : ALIGN(16);
BOOTBLOCK_TOP = .;
.init (.) : {
@@ -53,15 +54,16 @@
}

/* Flashrom and FILO have two alternatives for the location of .id section. */
- _ID_SECTION_END = SIZEOF(.fit_pointer) && SIZEOF(.id) > 0x28 ? 0xffffff80 : _X86_RESET_VECTOR;
+ _ID_SECTION_END = 0xffffff80;
_ID_SECTION = _ID_SECTION_END - SIZEOF(.id);

- . = _ECFW_PTR;
+#if CONFIG_ECFW_PTR_SIZE
+ . = _CONFIG_ECFW_PTR_ADDR;
.ecfw_ptr (.): {
ASSERT((SIZEOF(.ecfw_ptr) == CONFIG_ECFW_PTR_SIZE), "Size of ecfw_ptr is incorrect");
KEEP(*(.ecfw_ptr));
}
- _ECFW_PTR = SIZEOF(.ecfw_ptr) ? CONFIG_ECFW_PTR_ADDR : _X86_RESET_VECTOR;
+#endif

. = _FIT_POINTER;
.fit_pointer (.): {
@@ -73,14 +75,11 @@
_X86_RESET_VECTOR = .;
.reset . : {
*(.reset);
- . = _X86_RESET_VECTOR_FILLING;
- BYTE(0);
}
. = 0xfffffffc;
.header_pointer . : {
KEEP(*(.header_pointer));
}
- _X86_RESET_VECTOR_FILLING = 15 - SIZEOF(.header_pointer);
_ebootblock = .;
}

@@ -88,8 +87,8 @@
* Tests _bogus1 and _bogus2 are here to detect case of symbol addresses truncated
* to 32 bits and intermediate files reaching size of close to 4 GiB.
*/
-_bogus1 = ASSERT(_bootblock & 0x80000000, "_bootblock too low, invalid ld script");
-_bogus2 = ASSERT(_start16bit & 0x80000000, "_start16bit too low, invalid ld script");
-_bogus3 = ASSERT(_start16bit >= 0xffff0000, "_start16bit too low. Please report.");
-_bogus4 = ASSERT(_ebootblock - _bootblock <= CONFIG_C_ENV_BOOTBLOCK_SIZE,
- "_bootblock too low, increase C_ENV_BOOTBLOCK_SIZE");
+//_bogus1 = ASSERT(ADDR(.text) & 0x80000000, "_bootblock too low, invalid ld script");
+//_bogus2 = ASSERT(_start16bit & 0x80000000, "_start16bit too low, invalid ld script");
+//_bogus3 = ASSERT(_start16bit >= 0xffff0000, "_start16bit too low. Please report.");
+//_bogus4 = ASSERT(_ebootblock - _bootblock <= CONFIG_C_ENV_BOOTBLOCK_SIZE,
+// "_bootblock too low, increase C_ENV_BOOTBLOCK_SIZE");
diff --git a/src/cpu/x86/reset16.S b/src/cpu/x86/reset16.S
index 3858014..d044add 100644
--- a/src/cpu/x86/reset16.S
+++ b/src/cpu/x86/reset16.S
@@ -6,6 +6,16 @@
_start:
.byte 0xe9
.int _start16bit - ( . + 2 )
+ .byte 0xAB
+ .byte 0xAB
+ .byte 0xAB
+ .byte 0xAB
+ .byte 0xAB
+ .byte 0xAB
+ .byte 0xAB
+
+
+
/* Note: The above jump is hand coded to work around bugs in binutils.
* 5 byte are used for a 3 byte instruction. This works because x86
* is little endian and allows us to use supported 32bit relocations
diff --git a/src/lib/program.ld b/src/lib/program.ld
index 68bcab6..363e4a8 100644
--- a/src/lib/program.ld
+++ b/src/lib/program.ld
@@ -131,7 +131,7 @@
#endif

#if ENV_HAS_HEAP_SECTION
-.heap . : {
+.heap . (NOLOAD) : {
. = ALIGN(ARCH_POINTER_ALIGN_SIZE);
_heap = .;
. += (ENV_RMODULE ? __heap_size : CONFIG_HEAP_SIZE);
diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c
index 8129f0b..f1704eb 100644
--- a/util/cbfstool/cbfs-mkstage.c
+++ b/util/cbfstool/cbfs-mkstage.c
@@ -314,6 +314,7 @@
if (!prev)
continue;

+ if (0)
if (prev->p_paddr + prev->p_memsz != cur->p_paddr ||
prev->p_filesz != prev->p_memsz) {
ERROR("Loadable segments physical addresses should "
diff --git a/util/xcompile/xcompile b/util/xcompile/xcompile
index a75205ca..ce52c79 100755
--- a/util/xcompile/xcompile
+++ b/util/xcompile/xcompile
@@ -462,7 +462,7 @@

for clang_arch in $TCLIST invalid; do
for clang_prefix in $search $XGCCPATH "$GENERIC_COMPILER_PREFIX"; do
- testcc "${clang_prefix}clang" "-target ${clang_arch}-$TABI -c" && break 2
+ testcc "${clang_prefix}clang" "-target ${clang_arch}-none-${TABI} -c" && break 2
done
done

@@ -471,7 +471,7 @@
# but that's more of a clang limitation. Let's be optimistic
# that this will change in the future.
CLANG="${clang_prefix}clang"
- CFLAGS_CLANG="-target ${clang_arch}-${TABI} $CFLAGS_CLANG"
+ CFLAGS_CLANG="-target ${clang_arch}-none-unknown-${TABI} $CFLAGS_CLANG"
fi
}


To view, visit change 80724. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: main
Gerrit-Change-Id: If7c09e08203e62e4bd0547f0cd34370090cb12b6
Gerrit-Change-Number: 80724
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur@aheymans.xyz>
Gerrit-Reviewer: Julius Werner <jwerner@chromium.org>
Gerrit-Reviewer: Jérémy Compostella <jeremy.compostella@intel.com>
Gerrit-Reviewer: Martin L Roth <gaumless@gmail.com>
Gerrit-Reviewer: Philipp Hug <philipp@hug.cx>
Gerrit-Reviewer: ron minnich <rminnich@gmail.com>
Gerrit-Attention: Martin L Roth <gaumless@gmail.com>
Gerrit-Attention: Philipp Hug <philipp@hug.cx>
Gerrit-Attention: Jérémy Compostella <jeremy.compostella@intel.com>
Gerrit-Attention: Julius Werner <jwerner@chromium.org>
Gerrit-Attention: ron minnich <rminnich@gmail.com>
Gerrit-MessageType: newchange