lkml.org 
[lkml]   [2022]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 22/29] Kbuild: Prepare !CLANG whole module objtool
Massage the Kbuild stuff to allow running objtool on whole modules.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
Makefile | 2 ++
scripts/Makefile.build | 25 ++++++++++++++++---------
scripts/Makefile.lib | 2 +-
3 files changed, 19 insertions(+), 10 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -907,6 +907,8 @@ ifdef CONFIG_LTO
KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO)
KBUILD_AFLAGS += -fno-lto
export CC_FLAGS_LTO
+BUILD_LTO := y
+export BUILD_LTO
endif

ifdef CONFIG_CFI_CLANG
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -88,7 +88,7 @@ endif

targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))

-ifdef CONFIG_LTO_CLANG
+ifdef BUILD_LTO
targets-for-modules += $(patsubst %.o, %.lto.o, $(filter %.o, $(obj-m)))
endif

@@ -230,6 +230,7 @@ objtool := $(objtree)/tools/objtool/objt
objtool_args = \
$(if $(CONFIG_UNWINDER_ORC),orc generate,check) \
$(if $(part-of-module), --module) \
+ $(if $(BUILD_LTO), --lto) \
$(if $(CONFIG_FRAME_POINTER),, --no-fp) \
$(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\
$(if $(CONFIG_RETPOLINE), --retpoline) \
@@ -242,11 +243,16 @@ cmd_gen_objtooldep = $(if $(objtool-enab

endif # CONFIG_STACK_VALIDATION

-ifdef CONFIG_LTO_CLANG
+ifdef BUILD_LTO

# Skip objtool for LLVM bitcode
$(obj)/%.o: objtool-enabled :=

+# objtool was skipped for LLVM bitcode, run it now that we have compiled
+# modules into native code
+$(obj)/%.lto.o: objtool-enabled = y
+$(obj)/%.lto.o: part-of-module := y
+
else

# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
@@ -292,21 +298,22 @@ ifdef CONFIG_LTO_CLANG
# Module .o files may contain LLVM bitcode, compile them into native code
# before ELF processing
quiet_cmd_cc_lto_link_modules = LTO [M] $@
-cmd_cc_lto_link_modules = \
+ cmd_cc_lto_link_modules = \
$(LD) $(ld_flags) -r -o $@ \
$(shell [ -s $(@:.lto.o=.o.symversions) ] && \
echo -T $(@:.lto.o=.o.symversions)) \
--whole-archive $(filter-out FORCE,$^) \
$(cmd_objtool)
-
-# objtool was skipped for LLVM bitcode, run it now that we have compiled
-# modules into native code
-$(obj)/%.lto.o: objtool-enabled = y
-$(obj)/%.lto.o: part-of-module := y
+else
+quiet_cmd_cc_lto_link_modules = LD [M] $@
+ cmd_cc_lto_link_modules = \
+ $(LD) $(ld_flags) -r -o $@ \
+ $(filter-out FORCE,$^) \
+ $(cmd_objtool)
+endif

$(obj)/%.lto.o: $(obj)/%.o FORCE
$(call if_changed,cc_lto_link_modules)
-endif

cmd_mod = { \
echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -230,7 +230,7 @@ dtc_cpp_flags = -Wp,-MMD,$(depfile).pre
$(addprefix -I,$(DTC_INCLUDE)) \
-undef -D__DTS__

-ifeq ($(CONFIG_LTO_CLANG),y)
+ifdef BUILD_LTO
# With CONFIG_LTO_CLANG, .o files in modules might be LLVM bitcode, so we
# need to run LTO to compile them into native code (.lto.o) before further
# processing.

\
 
 \ /
  Last update: 2022-02-18 18:16    [W:0.951 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site