Clang error: A is unsupported with RISC-V linker relaxation (-mrelax) (err_drv_riscv_unsupported_with_linker_relaxation)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: A is unsupported with RISC-V linker relaxation (-mrelax) (since 15.0)
Type Error
Category None (since 15.0)
Internal Id err_drv_riscv_unsupported_with_linker_relaxation (since 15.0)
Internal Message %0 is unsupported with RISC-V linker relaxation (-mrelax) (since 15.0)
Regular Expression (?:error|fatal error)\: (.*?) is unsupported with RISC\-V linker relaxation \(\-mrelax\)
First Commit 2022-05-06 aef03c9b3bed [clang][auto-init] Deprecate -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clan...

Description

The error is issued by the Clang compiler when a feature or an option specified in the command line is not compatible with the RISC-V architecture's linker relaxation mechanism, indicated by the use of the -mrelax flag. This mechanism aims to optimize the generated code by relaxing certain constraints, allowing for smaller and more efficient binaries. However, not all features or options can be supported under this optimization process. When such an unsupported feature or option is encountered, the compiler generates this error message to inform the user about the incompatibility. The error message includes the specific feature or option that is unsupported in conjunction with -mrelax. Understanding the limitations of linker relaxation is crucial for developers targeting the RISC-V architecture, as it aids in making informed decisions regarding the use of certain compiler options and features in their projects.  
AI Generated

Example

In the following example, the Clang compiler is invoked with two specific flags: -target riscv64-unknown-elf and -mrelax, alongside the -gsplit-dwarf option. The -mrelax flag enables linker relaxation for RISC-V, a feature that aims to optimize the generated code. However, not all compiler flags are compatible with this relaxation process. The -gsplit-dwarf flag instructs the compiler to use split DWARF, a debugging information format designed to reduce the size of the debug information. Despite its utility, this debugging option is not supported when the linker relaxation feature is active for the RISC-V target. As a result, the Clang compiler outputs an error message, indicating that the -gsplit-dwarf flag is unsupported in combination with the RISC-V linker relaxation. This example illustrates the kind of compatibility issue that might arise when combining certain compiler options with the RISC-V architecture's linker relaxation feature.  
AI Generated


Flags -target riscv64-unknown-elf -xc -mrelax -gsplit-dwarf

[Try out in Compiler Explorer]

Source
// -gsplit-dwarf flag
int main() {}
Compiler Output
clang++: error: -gsplit-dwarf is unsupported with RISC-V linker relaxation (-mrelax)


Clang Internals (17.0.6)

Git Commit Message

[clang][auto-init] Deprecate -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang

GCC 12 has been released and contains unconditional support for
-ftrivial-auto-var-init=zero:
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-ftrivial-auto-var-init

Maintain compatibility with GCC, and remove the -enable flag for "zero"
mode. The flag is left to generate an "unused" warning, though, to not
break all the existing users. The flag will be fully removed in Clang 17.

Link: https://github.com/llvm/llvm-project/issues/44842

Reviewed By: nickdesaulniers, MaskRay, srhines, xbolva00

Differential Revision: https://reviews.llvm.org/D125142

Used in Clang Sources

This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.

clang/lib/Driver/ToolChains/Arch/RISCV.cpp (line 157)

void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector<StringRef> &Features) {
  // ...
  // -mrelax is default, unless -mno-relax is specified.
  if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) {
    // ...
    if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None)
      D.Diag(clang::diag::err_drv_riscv_unsupported_with_linker_relaxation) << A->getAsString(Args);