Skip to content

Commit 45bd895

Browse files
nathanchancewilldeacon
authored andcommitted
arm64: Improve HAVE_DYNAMIC_FTRACE_WITH_REGS selection for clang
Will and Anders reported that using just 'CC=clang' with CONFIG_FTRACE=y and CONFIG_STACK_TRACER=y would result in an error while linking: aarch64-linux-gnu-ld: .init.data has both ordered [`__patchable_function_entries' in init/main.o] and unordered [`.meminit.data' in mm/sparse.o] sections aarch64-linux-gnu-ld: final link failed: bad value This error was exposed by commit f12b034 ("scripts/Makefile.clang: default to LLVM_IAS=1") in combination with binutils older than 2.36. When '-fpatchable-function-entry' was implemented in LLVM, two code paths were added for adding the section attributes, one for the integrated assembler and another for GNU as, due to binutils deficiencies at the time. If the integrated assembler was used, attributes that GNU ld < 2.36 could not handle were added, presumably with the assumption that use of the integrated assembler meant the whole LLVM stack was being used, namely ld.lld. Prior to the kernel change previously mentioned, that assumption was valid, as there were three commonly used combinations of tools for compiling, assembling, and linking respectively: $ make CC=clang (clang, GNU as, GNU ld) $ make LLVM=1 (clang, GNU as, ld.lld) $ make LLVM=1 LLVM_IAS=1 (clang, integrated assembler, ld.lld) After the default switch of the integrated assembler, the second and third commands become equivalent and the first command means "clang, integrated assembler, and GNU ld", which was not a combination that was considered when the aforementioned LLVM change was implemented. It is not possible to go back and fix LLVM, as this change was implemented in the 10.x series, which is no longer supported. To workaround this on the kernel side, split out the selection of HAVE_DYNAMIC_FTRACE_WITH_REGS to two separate configurations, one for GCC and one for clang. The GCC config inherits the '-fpatchable-function-entry' check. The Clang config does not it, as '-fpatchable-function-entry' is always available for LLVM 11.0.0 and newer, which is the supported range of versions for the kernel. The Clang config makes sure that the user is using GNU as or the integrated assembler with ld.lld or GNU ld 2.36 or newer, which will avoid the error above. Link: ClangBuiltLinux#1507 Link: ClangBuiltLinux#788 Link: https://lore.kernel.org/YlCA5PoIjF6nhwYj@dev-arch.thelio-3990X/ Link: https://sourceware.org/bugzilla/show_bug.cgi?id=26256 Link: llvm/llvm-project@7fa5290 Link: llvm/llvm-project@853a264 Reported-by: Anders Roxell <anders.roxell@linaro.org> Reported-by: Will Deacon <will@kernel.org> Tested-by: Will Deacon <will@kernel.org> Signed-off-by: Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20220413181420.3522187-1-nathan@kernel.org Signed-off-by: Will Deacon <will@kernel.org>
1 parent e5c2377 commit 45bd895

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

arch/arm64/Kconfig

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ config ARM64
175175
select HAVE_DEBUG_KMEMLEAK
176176
select HAVE_DMA_CONTIGUOUS
177177
select HAVE_DYNAMIC_FTRACE
178-
select HAVE_DYNAMIC_FTRACE_WITH_REGS \
179-
if $(cc-option,-fpatchable-function-entry=2)
180178
select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY \
181179
if DYNAMIC_FTRACE_WITH_REGS
182180
select HAVE_EFFICIENT_UNALIGNED_ACCESS
@@ -228,6 +226,17 @@ config ARM64
228226
help
229227
ARM 64-bit (AArch64) Linux support.
230228

229+
config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_REGS
230+
def_bool CC_IS_CLANG
231+
# https://github.com/ClangBuiltLinux/linux/issues/1507
232+
depends on AS_IS_GNU || (AS_IS_LLVM && (LD_IS_LLD || LD_VERSION >= 23600))
233+
select HAVE_DYNAMIC_FTRACE_WITH_REGS
234+
235+
config GCC_SUPPORTS_DYNAMIC_FTRACE_WITH_REGS
236+
def_bool CC_IS_GCC
237+
depends on $(cc-option,-fpatchable-function-entry=2)
238+
select HAVE_DYNAMIC_FTRACE_WITH_REGS
239+
231240
config 64BIT
232241
def_bool y
233242

0 commit comments

Comments
 (0)