aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/ToolChain.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2023-08-14 08:26:52 -0700
committerFangrui Song <i@maskray.me>2023-08-14 08:26:52 -0700
commitbbc0f99f3bc96f1db16f649fc21dd18e5b0918f6 (patch)
treecd92adb3599f722583453cd80c65f64df16c4811 /clang/lib/Driver/ToolChain.cpp
parent2827aa9dafa7e0c45697bf4fc5b067cae26623c4 (diff)
downloadllvm-bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6.zip
llvm-bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6.tar.gz
llvm-bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6.tar.bz2
[Driver] Default riscv*- triples to -fdebug-default-version=4
This adds a RISC-V special case to ToolChain::GetDefaultDwarfVersion, affecting Linux/Haiku/RISCVToolChain. DWARF v5 .debug_loclists/.debug_rnglists's DW_LLE_offset_pair/DW_RLE_offset_pair entry kinds utilitize `.uleb128 A-B` directives where A and B reference local labels in code sections. When A and B are separated by a RISC-V linker-relaxable instruction, A-B is incorrectly folded without a relocation, causing incorrect debug information. ``` void ext(void); int foo(int x) {ext(); return 0;} // DW_AT_location [DW_FORM_loclistx] of a DW_TAG_formal_parameter references a DW_LLE_offset_pair that can be incorrect after linker relaxation. int ext(void); void foo() { { int ret = ext(); if (__builtin_expect(ret, 0)) ext(); } } // DW_AT_ranges [DW_FORM_rnglistx] of a DW_TAG_lexical_block references a DW_RLE_offset_pair that can be incorrect after linker relaxation. ``` D157657 will implement R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128 relocations, fixing the issue, but the relocation is only supported by bleeding-edge binutils 2.41 and not by lld/ELF yet. The goal is to make the emitted DWARF correct after linking. Many users don't care about the default DWARF version, but a linker error will be unacceptable. Let's just downgrade the default DWARF version, before binutils>=2.41 is more widely available. An alternative compatibility option is to add a toggle to DwarfDebug.cpp, but that doesn't seem like a good idea. Reviewed By: asb, kito-cheng Differential Revision: https://reviews.llvm.org/D157663
Diffstat (limited to 'clang/lib/Driver/ToolChain.cpp')
-rw-r--r--clang/lib/Driver/ToolChain.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index d60fdbc..8dafc3d 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -427,6 +427,12 @@ ToolChain::getDefaultUnwindTableLevel(const ArgList &Args) const {
return UnwindTableLevel::None;
}
+unsigned ToolChain::GetDefaultDwarfVersion() const {
+ // TODO: Remove the RISC-V special case when R_RISCV_SET_ULEB128 linker
+ // support becomes more widely available.
+ return getTriple().isRISCV() ? 4 : 5;
+}
+
Tool *ToolChain::getClang() const {
if (!Clang)
Clang.reset(new tools::Clang(*this, useIntegratedBackend()));