History

Merge tag 'clang-lto-v5.12-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull more clang LTO updates from Kees Cook: "Clang LTO x86 enablement. Full disclosure: while this has _not_ been in linux-next (since it initially looked like the objtool dependencies weren't going to make v5.12), it has been under daily build and runtime testing by Sami for quite some time. These x86 portions have been discussed on lkml, with Peter, Josh, and others helping nail things down. The bulk of the changes are to get objtool working happily. The rest of the x86 enablement is very small. Summary: - Generate __mcount_loc in objtool (Peter Zijlstra) - Support running objtool against vmlinux.o (Sami Tolvanen) - Clang LTO enablement for x86 (Sami Tolvanen)" Link: https://lore.kernel.org/lkml/20201013003203.4168817-26-samitolvanen@google.com/ Link: https://lore.kernel.org/lkml/cover.1611263461.git.jpoimboe@redhat.com/ * tag 'clang-lto-v5.12-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: kbuild: lto: force rebuilds when switching CONFIG_LTO x86, build: allow LTO to be selected x86, cpu: disable LTO for cpu.c x86, vdso: disable LTO only for vDSO kbuild: lto: postpone objtool objtool: Split noinstr validation from --vmlinux x86, build: use objtool mcount tracing: add support for objtool mcount objtool: Don't autodetect vmlinux.o objtool: Fix __mcount_loc generation with Clang's assembler objtool: Add a pass for generating __mcount_loc

Linus Torvalds committed 5 years ago

Commit 414eece2 parents 6dd580b 5e9532516 files · +195 −33Browse files

Showing the changes to scripts (4 of 16 files). Show all

Unified · Split

4 files
  1. scripts/Makefile.build +2 −17
  2. scripts/Makefile.lib +12 −0
  3. scripts/Makefile.modfinal +16 −3
  4. scripts/link-vmlinux.sh +25 −3
scripts/Makefile.build+2−17
@@ -218,27 +218,11 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), · 217 unmodified lines
218218 endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
219219
220220 ifdef CONFIG_STACK_VALIDATION
221+ifndef CONFIG_LTO_CLANG
221222 ifneq ($(SKIP_STACK_VALIDATION),1)
222223
223224 __objtool_obj := $(objtree)/tools/objtool/objtool
224225
225−objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
226−
227−objtool_args += $(if $(part-of-module), --module,)
228−
229−ifndef CONFIG_FRAME_POINTER
230−objtool_args += --no-fp
231−endif
232−ifdef CONFIG_GCOV_KERNEL
233−objtool_args += --no-unreachable
234−endif
235−ifdef CONFIG_RETPOLINE
236− objtool_args += --retpoline
237−endif
238−ifdef CONFIG_X86_SMAP
239− objtool_args += --uaccess
240−endif
241−
242226 # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
243227 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
244228 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
@@ -250,6 +234,7 @@ objtool_obj = $(if $(patsubst y%,, \ · 5 unmodified lines
250234 $(__objtool_obj))
251235
252236 endif # SKIP_STACK_VALIDATION
237+endif # CONFIG_LTO_CLANG
253238 endif # CONFIG_STACK_VALIDATION
254239
255240 # Rebuild all objects when objtool changes, or is enabled/disabled.
scripts/Makefile.lib+12−0
@@ -222,6 +222,18 @@ dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \ · 221 unmodified lines
222222 $(addprefix -I,$(DTC_INCLUDE)) \
223223 -undef -D__DTS__
224224
225+# Objtool arguments are also needed for modfinal with LTO, so we define
226+# then here to avoid duplication.
227+objtool_args = \
228+ $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \
229+ $(if $(part-of-module), --module,) \
230+ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \
231+ $(if $(or $(CONFIG_GCOV_KERNEL),$(CONFIG_LTO_CLANG)), \
232+ --no-unreachable,) \
233+ $(if $(CONFIG_RETPOLINE), --retpoline,) \
234+ $(if $(CONFIG_X86_SMAP), --uaccess,) \
235+ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount,)
236+
225237 # Useful for describing the dependency of composite objects
226238 # Usage:
227239 # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
scripts/Makefile.modfinal+16−3
@@ -9,7 +9,7 @@ __modfinal: · 8 unmodified lines
99 include include/config/auto.conf
1010 include $(srctree)/scripts/Kbuild.include
1111
12−# for c_flags
12+# for c_flags and objtool_args
1313 include $(srctree)/scripts/Makefile.lib
1414
1515 # find all modules listed in modules.order
@@ -34,10 +34,23 @@ ifdef CONFIG_LTO_CLANG · 18 unmodified lines
3434 # With CONFIG_LTO_CLANG, reuse the object file we compiled for modpost to
3535 # avoid a second slow LTO link
3636 prelink-ext := .lto
37−endif
37+
38+# ELF processing was skipped earlier because we didn't have native code,
39+# so let's now process the prelinked binary before we link the module.
40+
41+ifdef CONFIG_STACK_VALIDATION
42+ifneq ($(SKIP_STACK_VALIDATION),1)
43+cmd_ld_ko_o += \
44+ $(objtree)/tools/objtool/objtool $(objtool_args) \
45+ $(@:.ko=$(prelink-ext).o);
46+
47+endif # SKIP_STACK_VALIDATION
48+endif # CONFIG_STACK_VALIDATION
49+
50+endif # CONFIG_LTO_CLANG
3851
3952 quiet_cmd_ld_ko_o = LD [M] $@
40− cmd_ld_ko_o = \
53+ cmd_ld_ko_o += \
4154 $(LD) -r $(KBUILD_LDFLAGS) \
4255 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
4356 -T scripts/module.lds -o $@ $(filter %.o, $^); \
scripts/link-vmlinux.sh+25−3
@@ -103,14 +103,36 @@ modpost_link() · 102 unmodified lines
103103
104104 objtool_link()
105105 {
106+ local objtoolcmd;
106107 local objtoolopt;
107108
109+ if [ "${CONFIG_LTO_CLANG} ${CONFIG_STACK_VALIDATION}" = "y y" ]; then
110+ # Don't perform vmlinux validation unless explicitly requested,
111+ # but run objtool on vmlinux.o now that we have an object file.
112+ if [ -n "${CONFIG_UNWINDER_ORC}" ]; then
113+ objtoolcmd="orc generate"
114+ fi
115+
116+ objtoolopt="${objtoolopt} --duplicate"
117+
118+ if [ -n "${CONFIG_FTRACE_MCOUNT_USE_OBJTOOL}" ]; then
119+ objtoolopt="${objtoolopt} --mcount"
120+ fi
121+ fi
122+
108123 if [ -n "${CONFIG_VMLINUX_VALIDATION}" ]; then
109− objtoolopt="check"
124+ objtoolopt="${objtoolopt} --noinstr"
125+ fi
126+
127+ if [ -n "${objtoolopt}" ]; then
128+ if [ -z "${objtoolcmd}" ]; then
129+ objtoolcmd="check"
130+ fi
131+ objtoolopt="${objtoolopt} --vmlinux"
110132 if [ -z "${CONFIG_FRAME_POINTER}" ]; then
111133 objtoolopt="${objtoolopt} --no-fp"
112134 fi
113− if [ -n "${CONFIG_GCOV_KERNEL}" ]; then
135+ if [ -n "${CONFIG_GCOV_KERNEL}" ] || [ -n "${CONFIG_LTO_CLANG}" ]; then
114136 objtoolopt="${objtoolopt} --no-unreachable"
115137 fi
116138 if [ -n "${CONFIG_RETPOLINE}" ]; then
@@ -120,7 +142,7 @@ objtool_link() · 3 unmodified lines
120142 objtoolopt="${objtoolopt} --uaccess"
121143 fi
122144 info OBJTOOL ${1}
123− tools/objtool/objtool ${objtoolopt} ${1}
145+ tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1}
124146 fi
125147 }
126148

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t