RISC-V: Disable DWARF5 with known broken LLVM versions
Subsystems (2)
v2 cover RISC-V: Disable DWARF5 with known broken LLVM versions
Hi all,
This series disables DWARF5 for LLVM versions where it is known to be broken due to linker relaxation:
https://github.com/llvm/llvm-project/commit/bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6
If I understand correctly, it sounds like GNU binutils has a similar issue but I am not sure of the status of the fixes and such, so I did not bother with checking for it but it should be easy to add if so desired.
---
Changes in v2:
- Added patch 3 with Fangrui's suggested improvements around CONFIG_AS_HAS_NON_CONST_LEB128.
- Pick up Fangrui's Reviewed-by on patch 1.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Nathan Chancellor (3):
riscv: Hoist linker relaxation disabling logic into Kconfig
riscv: Restrict DWARF5 when building with LLVM to known working versions lib/Kconfig.debug: Update AS_HAS_NON_CONST_LEB128 comment and name
arch/riscv/Kconfig | 14 ++++++++++++++ arch/riscv/Makefile | 4 +--- lib/Kconfig.debug | 12 +++++++----- 3 files changed, 22 insertions(+), 8 deletions(-)
---
base-commit: 2cc14f52aeb78ce3f29677c2de1f06c0e91471ab
change-id: 20231129-riscv-restrict-dwarf5-llvm-a9824bb974cb
Best regards,
Signature · 1 line
Nathan Chancellor <[email protected]>
PATCH v2 1/3 riscv: Hoist linker relaxation disabling logic into Kconfig
Certain configurations may need to be disabled if linker relaxation is in use, such as DWARF5 with ld.lld < 18. Hoist the logic of whether or not linker relaxation is in use into Kconfig so decisions can be made at configuration time.
--- arch/riscv/Kconfig | 5 +++++ arch/riscv/Makefile | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-)
arch/riscv/Kconfig +5 -0
@@ -181,6 +181,11 @@ config HAVE_SHADOW_CALL_STACK # https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/a484e843e6eeb51f0cb7b8819e50da6d2444d769 depends on $(ld-option,--no-relax-gp) +config RISCV_USE_LINKER_RELAXATION + def_bool y + # https://github.com/llvm/llvm-project/commit/6611d58f5bbcbec77262d392e2923e1d680f6985 + depends on !LD_IS_LLD || LLD_VERSION >= 150000 + config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT default 8
arch/riscv/Makefile +1 -3
@@ -43,8 +43,7 @@ else KBUILD_LDFLAGS += -melf32lriscv endif -ifeq ($(CONFIG_LD_IS_LLD),y) -ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y) +ifndef CONFIG_RISCV_USE_LINKER_RELAXATION KBUILD_CFLAGS += -mno-relax KBUILD_AFLAGS += -mno-relax ifndef CONFIG_AS_IS_LLVM
@@ -52,7 +51,6 @@ ifndef CONFIG_AS_IS_LLVM KBUILD_AFLAGS += -Wa,-mno-relax endif endif -endif ifeq ($(CONFIG_SHADOW_CALL_STACK),y) KBUILD_LDFLAGS += --no-relax-gp
Signature · 1 line
2.43.0
PATCH v2 2/3 riscv: Restrict DWARF5 when building with LLVM to known working versions
In reply to Nathan ChancellorLLVM prior to 18.0.0 would generate incorrect debug info for DWARF5 due to linker relaxation, which was worked around in clang by defaulting RISC-V to DWARF4 [1]. Unfortunately, this workaround does not work for the kernel because the DWARF version can be independently changed from the default in Kconfig.
Do not allow DWARF5 to be selected for RISC-V when using linker relaxation (ld.lld >= 15.0.0) and a version of LLVM that does not have the fixes (the integrated assembler [2] and ld.lld [3] < 18.0.0) necessary to generate the correct debug info.
--- arch/riscv/Kconfig | 9 +++++++++ lib/Kconfig.debug | 1 + 2 files changed, 10 insertions(+)
arch/riscv/Kconfig +9 -0
@@ -186,6 +186,15 @@ config RISCV_USE_LINKER_RELAXATION # https://github.com/llvm/llvm-project/commit/6611d58f5bbcbec77262d392e2923e1d680f6985 depends on !LD_IS_LLD || LLD_VERSION >= 150000 +# https://github.com/llvm/llvm-project/commit/bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6 +config ARCH_HAS_BROKEN_DWARF5 + def_bool y + depends on RISCV_USE_LINKER_RELAXATION + # https://github.com/llvm/llvm-project/commit/1df5ea29b43690b6622db2cad7b745607ca4de6a + depends on AS_IS_LLVM && AS_VERSION < 180000 + # https://github.com/llvm/llvm-project/commit/7ffabb61a5569444b5ac9322e22e5471cc5e4a77 + depends on LD_IS_LLD && LLD_VERSION < 180000 + config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT default 8
lib/Kconfig.debug +1 -0
@@ -282,6 +282,7 @@ config DEBUG_INFO_DWARF4 config DEBUG_INFO_DWARF5 bool "Generate DWARF Version 5 debuginfo" select DEBUG_INFO + depends on !ARCH_HAS_BROKEN_DWARF5 depends on !CC_IS_CLANG || AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_LEB128) help Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc
Signature · 1 line
2.43.0
PATCH v2 3/3 lib/Kconfig.debug: Update AS_HAS_NON_CONST_LEB128 comment and name
In reply to Nathan ChancellorFangrui noted that the comment around CONFIG_AS_HAS_NON_CONST_LEB128 could be made more accurate because explicit .sleb128 directives are not emitted, only .uleb128 directives are. Rename the symbol to CONFIG_AS_HAS_NON_CONST_ULEB128 as a result.
Further clarifications include replacing "symbol deltas" with the more accurate "label differences", noting that this issue has been resolved in newer binutils (2.41+), and it only occurs when a port uses RISC-V style linker relaxation.
--- lib/Kconfig.debug | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
lib/Kconfig.debug +6 -5
@@ -231,9 +231,10 @@ config DEBUG_INFO in the "Debug information" choice below, indicating that debug information will be generated for build targets. -# Clang is known to generate .{s,u}leb128 with symbol deltas with DWARF5, which -# some targets may not support: https://sourceware.org/bugzilla/show_bug.cgi?id=27215 -config AS_HAS_NON_CONST_LEB128 +# Clang generates .uleb128 with label differences for DWARF v5, a feature that +# older binutils ports do not support when utilizing RISC-V style linker +# relaxation: https://sourceware.org/bugzilla/show_bug.cgi?id=27215 +config AS_HAS_NON_CONST_ULEB128 def_bool $(as-instr,.uleb128 .Lexpr_end4 - .Lexpr_start3\n.Lexpr_start3:\n.Lexpr_end4:) choice
@@ -258,7 +259,7 @@ config DEBUG_INFO_NONE config DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT bool "Rely on the toolchain's implicit default DWARF version" select DEBUG_INFO - depends on !CC_IS_CLANG || AS_IS_LLVM || CLANG_VERSION < 140000 || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_LEB128) + depends on !CC_IS_CLANG || AS_IS_LLVM || CLANG_VERSION < 140000 || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_ULEB128) help The implicit default version of DWARF debug info produced by a toolchain changes over time.
@@ -283,7 +284,7 @@ config DEBUG_INFO_DWARF5 bool "Generate DWARF Version 5 debuginfo" select DEBUG_INFO depends on !ARCH_HAS_BROKEN_DWARF5 - depends on !CC_IS_CLANG || AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_LEB128) + depends on !CC_IS_CLANG || AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_ULEB128) help Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc 5.0+ accepts the -gdwarf-5 flag but only had partial support for some
Signature · 1 line
2.43.0
Re: [PATCH v2 2/3] riscv: Restrict DWARF5 when building with LLVM to known working versions
In reply to Nathan ChancellorQuoted 28 lines · Nathan Chancellor
LLVM prior to 18.0.0 would generate incorrect debug info for DWARF5 due to linker relaxation, which was worked around in clang by defaulting RISC-V to DWARF4 [1]. Unfortunately, this workaround does not work for the kernel because the DWARF version can be independently changed from the default in
Kconfig.Do not allow DWARF5 to be selected for RISC-V when using linker relaxation (ld.lld >= 15.0.0) and a version of LLVM that does not have the fixes (the integrated assembler [2] and ld.lld [3] < 18.0.0) necessary to generate the correct debug info.
Signed-off-by Nathan Chancellor <[email protected]>--- arch/riscv/Kconfig | 9 +++++++++ lib/Kconfig.debug | 1 + 2 files changed, 10 insertions(+)arch/riscv/Kconfig +0
-0@@ -186,6 +186,15 @@ config RISCV_USE_LINKER_RELAXATION # https://github.com/llvm/llvm-project/commit/6611d58f5bbcbec77262d392e2923e1d680f6985 depends on !LD_IS_LLD || LLD_VERSION >= 150000
arch/riscv/Kconfig config RISCV_USE_LINKER_RELAXATION · line 197
Quoted 10 lines
arch/riscv/Kconfig +9
-0+# https://github.com/llvm/llvm-project/commit/bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6 +config ARCH_HAS_BROKEN_DWARF5 + def_bool y + depends on RISCV_USE_LINKER_RELAXATION + # https://github.com/llvm/llvm-project/commit/1df5ea29b43690b6622db2cad7b745607ca4de6a + depends on AS_IS_LLVM && AS_VERSION < 180000 + # https://github.com/llvm/llvm-project/commit/7ffabb61a5569444b5ac9322e22e5471cc5e4a77 + depends on LD_IS_LLD && LLD_VERSION < 180000 +
LGTM. loongarch folks can add arch/loongarch/Kconfig after they finish their R_LARCH_ADD_ULEB128/R_LARCH_SUB_ULEB128 toolchain work.
Quoted 20 lines
arch/riscv/Kconfig +0
-0config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT default 8lib/Kconfig.debug +1
-1@@ -282,6 +282,7 @@ config DEBUG_INFO_DWARF4 config DEBUG_INFO_DWARF5 bool "Generate DWARF Version 5 debuginfo" select DEBUG_INFO + depends on !ARCH_HAS_BROKEN_DWARF5 depends on !CC_IS_CLANG || AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_LEB128) help Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc --2.43.0
Signature · 1 line
宋方睿
Re: [PATCH v2 3/3] lib/Kconfig.debug: Update AS_HAS_NON_CONST_LEB128 comment and name
In reply to Nathan ChancellorQuoted 22 lines · Nathan Chancellor
Fangrui noted that the comment around
CONFIG_AS_HAS_NON_CONST_LEB128could be made more accurate because explicit .sleb128 directives are not emitted, only .uleb128 directives are. Rename the symbol toCONFIG_AS_HAS_NON_CONST_ULEB128as a result.Further clarifications include replacing "symbol deltas" with the more accurate "label differences", noting that this issue has been resolved in newer binutils (2.41+), and it only occurs when a port uses RISC-V style linker relaxation.
Suggested-by Fangrui Song <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- lib/Kconfig.debug | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)lib/Kconfig.debug +0
-0@@ -231,9 +231,10 @@ config DEBUG_INFO in the "Debug information" choice below, indicating that debug
lib/Kconfig.debug config DEBUG_INFO · line 238
Quoted 10 lines
lib/Kconfig.debug +4
-3information will be generated for build targets. -# Clang is known to generate .{s,u}leb128 with symbol deltas with DWARF5, which -# some targets may not support: https://sourceware.org/bugzilla/show_bug.cgi?id=27215 -config AS_HAS_NON_CONST_LEB128 +# Clang generates .uleb128 with label differences for DWARF v5, a feature that +# older binutils ports do not support when utilizing RISC-V style linker +# relaxation: https://sourceware.org/bugzilla/show_bug.cgi?id=27215 +config AS_HAS_NON_CONST_ULEB128 def_bool $(as-instr,.uleb128 .Lexpr_end4 - .Lexpr_start3\n.Lexpr_start3:\n.Lexpr_end4:)
This seems like a good change. However the wording in your commit message seems misleading. This config only ever checked for .uleb128 with a label difference and would assume that sleb128 with label differences were supported. This seems more like a "bug" in the config name that this is fixing. My interpretation is that your commit describes why this issue was never caught (because sleb128 is not emitted), but not the root of why this change is necessary (because non-const sleb128 is not necessarily supported if non-const uleb128 is). Anyways, it's just a commit message so not something that is important to change.
Quoted 29 lines
lib/Kconfig.debug +2
-2choice@@ -258,7 +259,7 @@ config DEBUG_INFO_NONE config DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT bool "Rely on the toolchain's implicit default DWARF version" select DEBUG_INFO - depends on !CC_IS_CLANG || AS_IS_LLVM || CLANG_VERSION < 140000 || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_LEB128) + depends on !CC_IS_CLANG || AS_IS_LLVM || CLANG_VERSION < 140000 || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_ULEB128) help The implicit default version of DWARF debug info produced by a toolchain changes over time.@@ -283,7 +284,7 @@ config DEBUG_INFO_DWARF5 bool "Generate DWARF Version 5 debuginfo" select DEBUG_INFO depends on !ARCH_HAS_BROKEN_DWARF5 - depends on !CC_IS_CLANG || AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_LEB128) + depends on !CC_IS_CLANG || AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502 && AS_HAS_NON_CONST_ULEB128) help Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc 5.0+ accepts the -gdwarf-5 flag but only had partial support for someSignature · 8 lines
-- 2.43.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt
maintainerQuoted 11 lines · On Tue, 05 Dec 2023 15:53:49 PST (-0800), [email protected] wrote:
Hi all,
This series disables DWARF5 for LLVM versions where it is known to be broken due to linker relaxation:
https://github.com/llvm/llvm-project/commit/bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6
If I understand correctly, it sounds like GNU binutils has a similar issue but I am not sure of the status of the fixes and such, so I did not bother with checking for it but it should be easy to add if so desired.
Do you have any more info? All I know is this add/sub/set mess we've got, but that's a cross linking problem.
I queued this up for testing, should show up on for-next soon. Thanks!
Quoted 22 lines
---
Changes in v2:
- Added patch 3 with Fangrui's suggested improvements aroundCONFIG_AS_HAS_NON_CONST_LEB128.
- Pick up Fangrui's Reviewed-by on patch 1.
- Link to v1: https://lore.kernel.org/r/[email protected]---
Nathan Chancellor (3):
riscv: Hoist linker relaxation disabling logic intoKconfig
riscv: Restrict DWARF5 when building with LLVM to known working versionslib/Kconfig.debug: UpdateAS_HAS_NON_CONST_LEB128comment and namearch/riscv/Kconfig | 14 ++++++++++++++ arch/riscv/Makefile | 4 +--- lib/Kconfig.debug | 12 +++++++----- 3 files changed, 22 insertions(+), 8 deletions(-)---
base-commit:2cc14f52aeb78ce3f29677c2de1f06c0e91471ab
change-id: 20231129-riscv-restrict-dwarf5-llvm-a9824bb974cbBest regards,
This series was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:
Quoted 8 lines · On Tue, 05 Dec 2023 16:53:49 -0700 you wrote:
Hi all,
This series disables DWARF5 for LLVM versions where it is known to be broken due to linker relaxation:
https://github.com/llvm/llvm-project/commit/bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6
[...]
Here is the summary with links:
- [v2,1/3] riscv: Hoist linker relaxation disabling logic into Kconfig
https://git.kernel.org/riscv/c/55b71d2ce133 - [v2,2/3] riscv: Restrict DWARF5 when building with LLVM to known working versions https://git.kernel.org/riscv/c/ae84ff9a14a5 - [v2,3/3] lib/Kconfig.debug: Update AS_HAS_NON_CONST_LEB128 comment and name https://git.kernel.org/riscv/c/a4426641f00c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html