Skip to content

Commit 80a4e6f

Browse files
committed
[Driver] Error for -gsplit-dwarf with RISC-V linker relaxation
-gsplit-dwarf produces a .dwo file which will not be processed by the linker. If .dwo files contain relocations, they will not be resolved. Therefore the practice is that .dwo files do not contain relocations. Address ranges and location description need to use forms/entry kinds indexing into .debug_addr (DW_FORM_addrx/DW_RLE_startx_endx/etc), which is currently not implemented. There is a difficult-to-read MC error with -gsplit-dwarf with RISC-V for both -mrelax and -mno-relax. ``` % clang --target=riscv64-linux-gnu -g -gsplit-dwarf -c a.c error: A dwo section may not contain relocations ``` We expect to fix -mno-relax soon, so report a driver error for -mrelax for now. Link: #56642 Reviewed By: compnerd, kito-cheng Differential Revision: https://reviews.llvm.org/D130190
1 parent e03664d commit 80a4e6f

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,4 +682,7 @@ def err_drv_invalid_empty_dxil_validator_version : Error<
682682
def warn_drv_sarif_format_unstable : Warning<
683683
"diagnostic formatting in SARIF mode is currently unstable">,
684684
InGroup<DiagGroup<"sarif-format-unstable">>;
685+
686+
def err_drv_riscv_unsupported_with_linker_relaxation : Error<
687+
"%0 is unsupported with RISC-V linker relaxation (-mrelax)">;
685688
}

clang/lib/Driver/ToolChains/Arch/RISCV.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "RISCV.h"
10+
#include "../Clang.h"
1011
#include "ToolChains/CommonArgs.h"
1112
#include "clang/Basic/CharInfo.h"
1213
#include "clang/Driver/Driver.h"
@@ -137,10 +138,17 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
137138
Features.push_back("+reserve-x31");
138139

139140
// -mrelax is default, unless -mno-relax is specified.
140-
if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
141+
if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) {
141142
Features.push_back("+relax");
142-
else
143+
// -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing
144+
// into .debug_addr, which is currently not implemented.
145+
Arg *A;
146+
if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None)
147+
D.Diag(clang::diag::err_drv_riscv_unsupported_with_linker_relaxation)
148+
<< A->getAsString(Args);
149+
} else {
143150
Features.push_back("-relax");
151+
}
144152

145153
// GCC Compatibility: -mno-save-restore is default, unless -msave-restore is
146154
// specified.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,9 +4034,7 @@ static void RenderDiagnosticsOptions(const Driver &D, const ArgList &Args,
40344034
options::OPT_fno_spell_checking);
40354035
}
40364036

4037-
enum class DwarfFissionKind { None, Split, Single };
4038-
4039-
static DwarfFissionKind getDebugFissionKind(const Driver &D,
4037+
DwarfFissionKind tools::getDebugFissionKind(const Driver &D,
40404038
const ArgList &Args, Arg *&Arg) {
40414039
Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
40424040
options::OPT_gno_split_dwarf);

clang/lib/Driver/ToolChains/Clang.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ class LLVM_LIBRARY_VISIBILITY LinkerWrapper final : public Tool {
198198
const char *LinkingOutput) const override;
199199
};
200200

201+
enum class DwarfFissionKind { None, Split, Single };
202+
203+
DwarfFissionKind getDebugFissionKind(const Driver &D,
204+
const llvm::opt::ArgList &Args,
205+
llvm::opt::Arg *&Arg);
206+
201207
} // end namespace tools
202208

203209
} // end namespace driver

clang/test/Driver/riscv-features.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@
3535
// RUN: not %clang -cc1 -triple riscv64-unknown-elf -target-feature +e 2>&1 | FileCheck %s -check-prefix=RV64-WITH-E
3636

3737
// RV64-WITH-E: error: invalid feature combination: standard user-level extension 'e' requires 'rv32'
38+
39+
// RUN: not %clang -c --target=riscv64-linux-gnu -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefix=ERR-SPLIT-DWARF
40+
// RUN: not %clang -c --target=riscv64 -gsplit-dwarf=single %s 2>&1 | FileCheck %s --check-prefix=ERR-SPLIT-DWARF
41+
// RUN: %clang -### -c --target=riscv64 -mno-relax -g -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefix=SPLIT-DWARF
42+
43+
// ERR-SPLIT-DWARF: error: -gsplit-dwarf{{.*}} is unsupported with RISC-V linker relaxation (-mrelax)
44+
// SPLIT-DWARF: "-split-dwarf-file"

0 commit comments

Comments
 (0)