Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

objtool: Fix seg fault with gold linker

Objtool segfaults when the gold linker is used with
CONFIG_MODVERSIONS=y and CONFIG_UNWINDER_ORC=y.

With CONFIG_MODVERSIONS=y, the .o file gets passed to the linker before
being passed to objtool. The gold linker seems to strip unused ELF
symbols by default, which confuses objtool and causes the seg fault when
it's trying to generate ORC metadata.

Objtool should really be running immediately after GCC anyway, without a
linker call in between. Change the makefile ordering so that objtool is
called before the linker.

Reported-and-tested-by: Markus <M4rkusXXL@web.de>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: ee9f8fce9964 ("x86/unwind: Add the ORC unwinder")
Link: http://lkml.kernel.org/r/355f04da33581f4a3bf82e5b512973624a1e23a2.1516025651.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Josh Poimboeuf and committed by
Ingo Molnar
2a0098d7 28d437d5

+10 -4
+10 -4
scripts/Makefile.build
··· 270 270 objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable) 271 271 endif 272 272 273 + ifdef CONFIG_MODVERSIONS 274 + objtool_o = $(@D)/.tmp_$(@F) 275 + else 276 + objtool_o = $(@) 277 + endif 278 + 273 279 # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory 274 280 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file 275 281 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file 276 282 cmd_objtool = $(if $(patsubst y%,, \ 277 283 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ 278 - $(__objtool_obj) $(objtool_args) "$(@)";) 284 + $(__objtool_obj) $(objtool_args) "$(objtool_o)";) 279 285 objtool_obj = $(if $(patsubst y%,, \ 280 286 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ 281 287 $(__objtool_obj)) ··· 297 291 define rule_cc_o_c 298 292 $(call echo-cmd,checksrc) $(cmd_checksrc) \ 299 293 $(call cmd_and_fixdep,cc_o_c) \ 300 - $(cmd_modversions_c) \ 301 294 $(call echo-cmd,objtool) $(cmd_objtool) \ 295 + $(cmd_modversions_c) \ 302 296 $(call echo-cmd,record_mcount) $(cmd_record_mcount) 303 297 endef 304 298 305 299 define rule_as_o_S 306 300 $(call cmd_and_fixdep,as_o_S) \ 307 - $(cmd_modversions_S) \ 308 - $(call echo-cmd,objtool) $(cmd_objtool) 301 + $(call echo-cmd,objtool) $(cmd_objtool) \ 302 + $(cmd_modversions_S) 309 303 endef 310 304 311 305 # List module undefined symbols (or empty line if not enabled)