ARM: Emit __gnu_mcount_nc when using Clang 10.0.0 or newer
PATCH 1/1 ARM: Emit __gnu_mcount_nc when using Clang 10.0.0 or newer
Currently, multi_v7_defconfig + CONFIG_FUNCTION_TRACER fails to build with clang:
arm-linux-gnueabi-ld: kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' follow
clang can emit a working mcount symbol, __gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot because the calling convention was not correct. Now that it is fixed, add this to the command line when clang is 10.0.0 or newer so everything works properly.
--- arch/arm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/Makefile +6 -0
@@ -112,6 +112,12 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 100000; echo $$?),0) +CFLAGS_ABI +=-meabi gnu +endif +endif + # Accept old syntax despite ".syntax unified" AFLAGS_NOWARN :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W)
Signature · 1 line
2.23.0
Quoted 16 lines · Nathan Chancellor
Currently,
multi_v7_defconfig+CONFIG_FUNCTION_TRACERfails to build with clang:arm-linux-gnueabi-ld:
kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' follow
Quoted 6 lines
clang can emit a working mcount symbol,
__gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot because the calling convention was not correct. Now that it is fixed, add this to the command line when clang is 10.0.0 or newer so everything works properly.
Cool, finally function tracing with Clang :-)
Quoted 6 lines
Link:
https://github.com/llvm/llvm-project/commit/16fa8b09702378bacfa3d07081afe6b353b99e60Signed-off-by Nathan Chancellor <[email protected]>
--
Stefan
Quoted 20 lines
--- arch/arm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)arch/arm/Makefile +6
-0@@ -112,6 +112,12 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 100000; echo $$?),0) +CFLAGS_ABI +=-meabi gnu +endif +endif + # Accept old syntax despite ".syntax unified" AFLAGS_NOWARN :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W)
Quoted 35 lines · Nathan Chancellor
Currently,
multi_v7_defconfig+CONFIG_FUNCTION_TRACERfails to build with clang:arm-linux-gnueabi-ld:
kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' followclang can emit a working mcount symbol,
__gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot because the calling convention was not correct. Now that it is fixed, add this to the command line when clang is 10.0.0 or newer so everything works properly.Signed-off-by Nathan Chancellor <[email protected]>--- arch/arm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)arch/arm/Makefile +0
-0
arch/arm/Makefile ifeq ($(CONFIG_ARM_UNWIND),y) · line 119
Quoted 8 lines
arch/arm/Makefile +5
-0@@ -112,6 +112,12 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 100000; echo $$?),0) +CFLAGS_ABI +=-meabi gnu +endif +endif
Is this also correct/needed when CONFIG_AEABI is not set?
Quoted 36 lines · Nathan Chancellor
Currently,
multi_v7_defconfig+CONFIG_FUNCTION_TRACERfails to build with clang:arm-linux-gnueabi-ld:
kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' followclang can emit a working mcount symbol,
__gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot because the calling convention was not correct. Now that it is fixed, add this to the command line when clang is 10.0.0 or newer so everything works properly.Signed-off-by Nathan Chancellor <[email protected]>--- arch/arm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)arch/arm/Makefile +0
-0
arch/arm/Makefile ifeq ($(CONFIG_ARM_UNWIND),y) · line 120
Quoted 9 lines
arch/arm/Makefile +6
-0@@ -112,6 +112,12 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 100000; echo $$?),0) +CFLAGS_ABI +=-meabi gnu +endif +endif +
Thanks for the patch! I think this is one of the final issues w/ 32b ARM configs when building w/ Clang.
I'm not super enthused about the version check. The flag is indeed not recognized by GCC, but I think it would actually be more concise with $(cc-option) and no compiler or version check.
Further, I think that the working __gnu_mcount_nc in Clang would better be represented as marking the arch/arm/KConfig option for CONFIG_FUNCTION_TRACER for dependent on a version of Clang greater than or equal to Clang 10, not conditionally adding this flag. (We should always add the flag when supported, IMO. __gnu_mcount_nc's calling convention being broken is orthogonal to the choice of __gnu_mcount_nc vs mcount, and it's the former's that should be checked, not the latter as in this patch.
Quoted 6 lines
arch/arm/Makefile +0
-1# Accept old syntax despite ".syntax unified" AFLAGS_NOWARN :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W) --2.23.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 55 lines · Nick Desaulniers
Quoted 36 lines · Nathan Chancellor
Currently,
multi_v7_defconfig+CONFIG_FUNCTION_TRACERfails to build with clang:arm-linux-gnueabi-ld:
kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' followclang can emit a working mcount symbol,
__gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot because the calling convention was not correct. Now that it is fixed, add this to the command line when clang is 10.0.0 or newer so everything works properly.Signed-off-by Nathan Chancellor <[email protected]>--- arch/arm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)arch/arm/Makefile +0
-0arch/arm/Makefile ifeq ($(CONFIG_ARM_UNWIND),y) · line 120
Quoted 9 lines
arch/arm/Makefile +6
-0@@ -112,6 +112,12 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 100000; echo $$?),0) +CFLAGS_ABI +=-meabi gnu +endif +endif +Thanks for the patch! I think this is one of the final issues w/ 32b ARM configs when building w/ Clang.
I'm not super enthused about the version check. The flag is indeed not recognized by GCC, but I think it would actually be more concise with $(cc-option) and no compiler or version check.
Quoted 8 lines
Further, I think that the working
__gnu_mcount_ncin Clang would better be represented as marking thearch/arm/KConfigoption forCONFIG_FUNCTION_TRACERfor dependent on a version of Clang greater than or equal to Clang 10, not conditionally adding this flag. (We should always add the flag when supported, IMO. __gnu_mcount_nc's calling convention being broken is orthogonal to the choice of__gnu_mcount_ncvs mcount, and it's the former's that should be checked, not the latter as in this patch.
I will test with or without CONFIG_AEABI like Matthias asked and I will implement your Kconfig suggestion if it passes all of my tests. The reason that I did it this way is because I didn't want a user to end up with a non-booting kernel since -meabi gnu works with older versions of clang at build time, the issue happens at boot time but the Kconfig suggestion + cc-option should fix that.
I should have a v2 out this evening.
Cheers,
Nathan
Quoted 65 lines · Nathan Chancellor
Quoted 55 lines · Nick Desaulniers
Quoted 36 lines · Nathan Chancellor
Currently,
multi_v7_defconfig+CONFIG_FUNCTION_TRACERfails to build with clang:arm-linux-gnueabi-ld:
kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' followclang can emit a working mcount symbol,
__gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot because the calling convention was not correct. Now that it is fixed, add this to the command line when clang is 10.0.0 or newer so everything works properly.Signed-off-by Nathan Chancellor <[email protected]>--- arch/arm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)arch/arm/Makefile +0
-0arch/arm/Makefile ifeq ($(CONFIG_ARM_UNWIND),y) · line 120
Quoted 9 lines
arch/arm/Makefile +6
-0@@ -112,6 +112,12 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 100000; echo $$?),0) +CFLAGS_ABI +=-meabi gnu +endif +endif +Thanks for the patch! I think this is one of the final issues w/ 32b ARM configs when building w/ Clang.
I'm not super enthused about the version check. The flag is indeed not recognized by GCC, but I think it would actually be more concise with $(cc-option) and no compiler or version check.
Quoted 8 lines
Further, I think that the working
__gnu_mcount_ncin Clang would better be represented as marking thearch/arm/KConfigoption forCONFIG_FUNCTION_TRACERfor dependent on a version of Clang greater than or equal to Clang 10, not conditionally adding this flag. (We should always add the flag when supported, IMO. __gnu_mcount_nc's calling convention being broken is orthogonal to the choice of__gnu_mcount_ncvs mcount, and it's the former's that should be checked, not the latter as in this patch.
Quoted 6 lines
I will test with or without
CONFIG_AEABIlike Matthias asked and I will implement yourKconfigsuggestion if it passes all of my tests. The reason that I did it this way is because I didn't want a user to end up with a non-booting kernel since -meabi gnu works with older versions of clang at build time, the issue happens at boot time but theKconfigsuggestion + cc-option should fix that.
I agree with Nathan here, I'd rather prefer the build system to fail building rather than runtime error.
If we decide we want to have it building despite it not building a functional kernel, we should at least add a #warning...
--
Stefan
Quoted 5 lines
I should have a v2 out this evening.
Cheers,
Nathan
Quoted 74 lines · Stefan Agner
Quoted 65 lines · Nathan Chancellor
Quoted 55 lines · Nick Desaulniers
Quoted 36 lines · Nathan Chancellor
Currently,
multi_v7_defconfig+CONFIG_FUNCTION_TRACERfails to build with clang:arm-linux-gnueabi-ld:
kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' followclang can emit a working mcount symbol,
__gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot because the calling convention was not correct. Now that it is fixed, add this to the command line when clang is 10.0.0 or newer so everything works properly.Signed-off-by Nathan Chancellor <[email protected]>--- arch/arm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)arch/arm/Makefile +0
-0arch/arm/Makefile ifeq ($(CONFIG_ARM_UNWIND),y) · line 120
Quoted 9 lines
arch/arm/Makefile +6
-0@@ -112,6 +112,12 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 100000; echo $$?),0) +CFLAGS_ABI +=-meabi gnu +endif +endif +Thanks for the patch! I think this is one of the final issues w/ 32b ARM configs when building w/ Clang.
I'm not super enthused about the version check. The flag is indeed not recognized by GCC, but I think it would actually be more concise with $(cc-option) and no compiler or version check.
Quoted 8 lines
Further, I think that the working
__gnu_mcount_ncin Clang would better be represented as marking thearch/arm/KConfigoption forCONFIG_FUNCTION_TRACERfor dependent on a version of Clang greater than or equal to Clang 10, not conditionally adding this flag. (We should always add the flag when supported, IMO. __gnu_mcount_nc's calling convention being broken is orthogonal to the choice of__gnu_mcount_ncvs mcount, and it's the former's that should be checked, not the latter as in this patch.Quoted 6 lines
I will test with or without
CONFIG_AEABIlike Matthias asked and I will implement yourKconfigsuggestion if it passes all of my tests. The reason that I did it this way is because I didn't want a user to end up with a non-booting kernel since -meabi gnu works with older versions of clang at build time, the issue happens at boot time but theKconfigsuggestion + cc-option should fix that.
Quoted 5 lines
I agree with Nathan here, I'd rather prefer the build system to fail building rather than runtime error.
If we decide we want to have it building despite it not building a functional kernel, we should at least add a #warning...
Just to be clear...I was suggesting a build failure, but for __gnu_mcount_nc not having the correct calling convention in older clang releases, which is orthogonal to passing -meabi gnu. This patch uses the __gnu_mcount_nc calling convention problem to justify a version check for a flag that while closely related, is not actually the problem, IMO.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 81 lines · Nick Desaulniers
Quoted 74 lines · Stefan Agner
Quoted 65 lines · Nathan Chancellor
Quoted 55 lines · Nick Desaulniers
Quoted 36 lines · Nathan Chancellor
Currently,
multi_v7_defconfig+CONFIG_FUNCTION_TRACERfails to build with clang:arm-linux-gnueabi-ld:
kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' followclang can emit a working mcount symbol,
__gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot because the calling convention was not correct. Now that it is fixed, add this to the command line when clang is 10.0.0 or newer so everything works properly.Signed-off-by Nathan Chancellor <[email protected]>--- arch/arm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)arch/arm/Makefile +0
-0arch/arm/Makefile ifeq ($(CONFIG_ARM_UNWIND),y) · line 120
Quoted 9 lines
arch/arm/Makefile +6
-0@@ -112,6 +112,12 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 100000; echo $$?),0) +CFLAGS_ABI +=-meabi gnu +endif +endif +Thanks for the patch! I think this is one of the final issues w/ 32b ARM configs when building w/ Clang.
I'm not super enthused about the version check. The flag is indeed not recognized by GCC, but I think it would actually be more concise with $(cc-option) and no compiler or version check.
Quoted 8 lines
Further, I think that the working
__gnu_mcount_ncin Clang would better be represented as marking thearch/arm/KConfigoption forCONFIG_FUNCTION_TRACERfor dependent on a version of Clang greater than or equal to Clang 10, not conditionally adding this flag. (We should always add the flag when supported, IMO. __gnu_mcount_nc's calling convention being broken is orthogonal to the choice of__gnu_mcount_ncvs mcount, and it's the former's that should be checked, not the latter as in this patch.Quoted 6 lines
I will test with or without
CONFIG_AEABIlike Matthias asked and I will implement yourKconfigsuggestion if it passes all of my tests. The reason that I did it this way is because I didn't want a user to end up with a non-booting kernel since -meabi gnu works with older versions of clang at build time, the issue happens at boot time but theKconfigsuggestion + cc-option should fix that.Quoted 5 lines
I agree with Nathan here, I'd rather prefer the build system to fail building rather than runtime error.
If we decide we want to have it building despite it not building a functional kernel, we should at least add a #warning...
Quoted 6 lines
Just to be clear...I was suggesting a build failure, but for
__gnu_mcount_ncnot having the correct calling convention in older clang releases, which is orthogonal to passing-meabi gnu. This patch uses the__gnu_mcount_nccalling convention problem to justify a version check for a flag that while closely related, is not actually the problem, IMO.
I am not entirely sure what you mean. -meabi gnu has always produced a buildable kernel (see Stefan's original report [1]), it just doesn't boot and that all happens silently.
[1]: https://lore.kernel.org/linux-arm-kernel/[email protected]/
Okay, after doing some further testing...
Disabling CONFIG_AEABI does not work with clang, I get a ton of failures around undefined references to __aeabi_idivmod and __aeabi_uidivmod. I don't think this is worth looking into given that CONFIG_AEABI is not selectable when CONFIG_CPU_V6 or CONFIG_CPU_V7 is selected, which is what we primarily care about.. We currently build and boot multi_v5_defconfig but it has CONFIG_AEABI set in it. As a result, I don't think we need to care about it with this patch.
This diff would also solve the issue without the need for the version check in the Makefile, as it is the combination of -meabi gnu and -pg that causes the boot issue and -pg gets added when CONFIG_FUNCTION_TRACER is enabled. Would that be preferred? I do not think adding cc-option is necessary given that we know GCC universally does not support this flag; there is no point in adding a small penalty with cc-option to either compiler.
Cheers,
Nathan
================================================
arch/arm/Kconfig +1 -1
@@ -83,7 +83,7 @@ config ARM select HAVE_FAST_GUP if ARM_LPAE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL && !CC_IS_CLANG - select HAVE_FUNCTION_TRACER if !XIP_KERNEL + select HAVE_FUNCTION_TRACER if !XIP_KERNEL && (CC_IS_GCC || CLANG_VERSION >= 100000) select HAVE_GCC_PLUGINS select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7) select HAVE_IDE if PCI || ISA || PCMCIA
arch/arm/Makefile +4 -0
@@ -115,6 +115,10 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +CFLAGS_ABI +=-meabi gnu +endif + # Accept old syntax despite ".syntax unified" AFLAGS_NOWARN :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W)
Nick Desaulniers
Reviewed-byQuoted 13 lines · Nathan Chancellor
Quoted 11 lines · Nick Desaulniers
Quoted 10 lines · Stefan Agner
Quoted 8 lines · Nathan Chancellor
Quoted 1 line · Nick Desaulniers
On Wed, Aug 28, 2019 at 11:27 PM Nathan Chancellor
I will test with or without
CONFIG_AEABIlike Matthias asked and I will implement yourKconfigsuggestion if it passes all of my tests. The reason that I did it this way is because I didn't want a user to end up with a non-booting kernel since -meabi gnu works with older versions of clang at build time, the issue happens at boot time but theKconfigsuggestion + cc-option should fix that.
Quoted 7 lines
Disabling
CONFIG_AEABIdoes not work with clang, I get a ton of failures around undefined references to__aeabi_idivmodand__aeabi_uidivmod. I don't think this is worth looking into given thatCONFIG_AEABIis not selectable whenCONFIG_CPU_V6orCONFIG_CPU_V7is selected, which is what we primarily care about.. We currently build and bootmulti_v5_defconfigbut it hasCONFIG_AEABIset in it. As a result, I don't think we need to care about it with this patch.
The plan of record is to never support !CONFIG_AEBI (ie OABI) w/ Clang. See also my commit currently in linux-next:
ARM: 8875/1: Kconfig: default to AEABI w/ Clang
https://github.com/ClangBuiltLinux/linux/issues/482
so !AEABI is a moot point. If we ever changed our minds, then yes we should additionally guard on !CONFIG_AEABI, but I feel like that's a highly unlikely scenario at this point.
Quoted 32 lines
This diff would also solve the issue without the need for the version check in the
Makefile, as it is the combination of -meabi gnu and -pg that causes the boot issue and -pg gets added whenCONFIG_FUNCTION_TRACERis enabled. Would that be preferred? I do not think adding cc-option is necessary given that we know GCC universally does not support this flag; there is no point in adding a small penalty with cc-option to either compiler.Cheers,
Nathan================================================
arch/arm/Kconfig +1
-1@@ -83,7 +83,7 @@ config ARM select HAVE_FAST_GUP if ARM_LPAE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL && !CC_IS_CLANG - select HAVE_FUNCTION_TRACER if !XIP_KERNEL + select HAVE_FUNCTION_TRACER if !XIP_KERNEL && (CC_IS_GCC || CLANG_VERSION >= 100000) select HAVE_GCC_PLUGINS select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7) select HAVE_IDE if PCI || ISA || PCMCIAarch/arm/Makefile +0
-0
arch/arm/Makefile ifeq ($(CONFIG_ARM_UNWIND),y) · line 120
Quoted 6 lines
arch/arm/Makefile +3
-0@@ -115,6 +115,10 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +CFLAGS_ABI +=-meabi gnu +endif
Quoted 4 lines
arch/arm/Makefile +1
-0+ # Accept old syntax despite ".syntax unified" AFLAGS_NOWARN :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W)
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 11 lines · Nick Desaulniers
Quoted 8 lines · Nathan Chancellor
arch/arm/Makefile +0
-0@@ -115,6 +115,10 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif
Quoted 2 lines
arch/arm/Makefile ifeq ($(CONFIG_ARM_UNWIND),y) · line 119
Quoted 2 lines
arch/arm/Makefile +2
-0+ifeq ($(CONFIG_CC_IS_CLANG),y) +CFLAGS_ABI +=-meabi gnu
Needs a space. +=-.
Signature · 2 lines
Thanks, ~Nick Desaulniers
PATCH v2 1/1 ARM: Emit __gnu_mcount_nc when using Clang 10.0.0 or newer
In reply to Nathan ChancellorCurrently, multi_v7_defconfig + CONFIG_FUNCTION_TRACER fails to build with clang:
arm-linux-gnueabi-ld: kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' follow
clang can emit a working mcount symbol, __gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot with '-pg' because the calling convention was not correct. Always build with '-meabi gnu' when using clang but ensure that '-pg' (which is added with CONFIG_FUNCTION_TRACER and its prereq CONFIG_HAVE_FUNCTION_TRACER) cannot be added with it unless this is fixed (which means using clang 10.0.0 and newer).
---
v1 -> v2:
* Add Nick and Stefan's reviewed by tags
* Move version check from Makefile to Kconfig. This prevents '-pg` from ever being added if '-meabi gnu' would produce a non-booting kernel and it allows clang 9.0.0 and earlier to build and link all*config kernels because the function tracer can't be selected.
arch/arm/Kconfig | 2 +- arch/arm/Makefile | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
arch/arm/Kconfig +1 -1
@@ -83,7 +83,7 @@ config ARM select HAVE_FAST_GUP if ARM_LPAE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL && !CC_IS_CLANG - select HAVE_FUNCTION_TRACER if !XIP_KERNEL + select HAVE_FUNCTION_TRACER if !XIP_KERNEL && (CC_IS_GCC || CLANG_VERSION >= 100000) select HAVE_GCC_PLUGINS select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7) select HAVE_IDE if PCI || ISA || PCMCIA
arch/arm/Makefile +4 -0
@@ -115,6 +115,10 @@ ifeq ($(CONFIG_ARM_UNWIND),y) CFLAGS_ABI +=-funwind-tables endif +ifeq ($(CONFIG_CC_IS_CLANG),y) +CFLAGS_ABI += -meabi gnu +endif + # Accept old syntax despite ".syntax unified" AFLAGS_NOWARN :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W)
Signature · 1 line
2.23.0
Quoted 24 lines · Nathan Chancellor
Currently,
multi_v7_defconfig+CONFIG_FUNCTION_TRACERfails to build with clang:arm-linux-gnueabi-ld:
kernel/softirq.o: in function `_local_bh_enable':
softirq.c:(.text+0x504): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `__local_bh_enable_ip':
softirq.c:(.text+0x58c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `do_softirq':
softirq.c:(.text+0x6c8): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_enter':
softirq.c:(.text+0x75c): undefined reference to `mcount'
arm-linux-gnueabi-ld:kernel/softirq.o: in function `irq_exit':
softirq.c:(.text+0x840): undefined reference to `mcount'
arm-linux-gnueabi-ld: kernel/softirq.o:softirq.c:(.text+0xa50): more undefined references to `mcount' followclang can emit a working mcount symbol,
__gnu_mcount_nc, when '-meabi gnu' is passed to it. Until r369147 in LLVM, this was broken and caused the kernel not to boot with '-pg' because the calling convention was not correct. Always build with '-meabi gnu' when using clang but ensure that '-pg' (which is added withCONFIG_FUNCTION_TRACERand its prereqCONFIG_HAVE_FUNCTION_TRACER) cannot be added with it unless this is fixed (which means using clang 10.0.0 and newer).
Quoted 6 lines
Reviewed-by Nick Desaulniers <[email protected]>Reviewed-by Stefan Agner <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>