diff --git a/Makefile b/Makefile index 74ed0a10a9de..64db14e7ceea 100644 --- a/Makefile +++ b/Makefile @@ -827,7 +827,7 @@ LD_FLAGS_LTO_CLANG := -mllvm -import-instr-limit=5 KBUILD_LDFLAGS += $(LD_FLAGS_LTO_CLANG) KBUILD_LDFLAGS_MODULE += $(LD_FLAGS_LTO_CLANG) -KBUILD_LDFLAGS_MODULE += -T $(srctree)/scripts/module-lto.lds +KBUILD_LDFLAGS_MODULE += -T scripts/module-lto.lds # allow disabling only clang LTO where needed DISABLE_LTO_CLANG := -fno-lto diff --git a/scripts/Makefile b/scripts/Makefile index 61affa300d25..b3447edcb718 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -31,6 +31,8 @@ always := $(hostprogs-y) $(hostprogs-m) # The following hostprogs-y programs are only build on demand hostprogs-y += unifdef +extra-$(CONFIG_LTO_CLANG) += module-lto.lds + # These targets are used internally to avoid "is up to date" messages PHONY += build_unifdef build_unifdef: $(obj)/unifdef diff --git a/scripts/module-lto.lds b/scripts/module-lto.lds.S similarity index 68% rename from scripts/module-lto.lds rename to scripts/module-lto.lds.S index 5ba0e9461e13..c0f4fdeb84a0 100644 --- a/scripts/module-lto.lds +++ b/scripts/module-lto.lds.S @@ -1,3 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include + /* * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and * -ffunction-sections, which increases the size of the final module. @@ -18,5 +21,14 @@ SECTIONS { .rela.rodata : { *(.rela.rodata .rela.rodata.[0-9a-zA-Z_]*) } .rela.text : { *(.rela.text .rela.text.[0-9a-zA-Z_]*) } .rodata : { *(.rodata .rodata.[0-9a-zA-Z_]*) } - .text : { *(.text .text.[0-9a-zA-Z_]*) } + + /* + * With CFI_CLANG, ensure __cfi_check is at the beginning of the + * .text section, and that the section is aligned to page size. + */ + .text : ALIGN(PAGE_SIZE) { + *(.text.__cfi_check) + *(.text .text.[0-9a-zA-Z_]* .text..L.cfi*) + } + }