Skip to content

[TargetLoweringObjectFile] Handle riscv BE #155166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

djtodoro
Copy link
Collaborator

Add DWARF exception handling support for riscv big-endian targets.
More CodeGen changes related to riscvbe are coming.

@llvmbot
Copy link
Member

llvmbot commented Aug 24, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Djordje Todorovic (djtodoro)

Changes

Add DWARF exception handling support for riscv big-endian targets.
More CodeGen changes related to riscvbe are coming.


Full diff: https://github.com/llvm/llvm-project/pull/155166.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (+2)
  • (modified) llvm/test/CodeGen/RISCV/dwarf-eh.ll (+16)
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index d19ef923ef740..739dcc7f4c868 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -247,6 +247,8 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
     break;
   case Triple::riscv32:
   case Triple::riscv64:
+  case Triple::riscv32be:
+  case Triple::riscv64be:
     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
     PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
                           dwarf::DW_EH_PE_sdata4;
diff --git a/llvm/test/CodeGen/RISCV/dwarf-eh.ll b/llvm/test/CodeGen/RISCV/dwarf-eh.ll
index 39cc0d52c9fe1..dd9e9e59206ac 100644
--- a/llvm/test/CodeGen/RISCV/dwarf-eh.ll
+++ b/llvm/test/CodeGen/RISCV/dwarf-eh.ll
@@ -14,6 +14,22 @@
 ; RUN:     | FileCheck %s
 ; RUN: llc -mtriple=riscv64 --code-model=medium -relocation-model=pic < %s \
 ; RUN:     | FileCheck %s
+; RUN: llc -mtriple=riscv32be --code-model=small  < %s \
+; RUN:     | FileCheck %s
+; RUN: llc -mtriple=riscv32be --code-model=medium < %s \
+; RUN:     | FileCheck %s
+; RUN: llc -mtriple=riscv32be --code-model=small  -relocation-model=pic < %s \
+; RUN:     | FileCheck %s
+; RUN: llc -mtriple=riscv32be --code-model=medium -relocation-model=pic < %s \
+; RUN:     | FileCheck %s
+; RUN: llc -mtriple=riscv64be --code-model=small  < %s \
+; RUN:     | FileCheck %s
+; RUN: llc -mtriple=riscv64be --code-model=medium < %s \
+; RUN:     | FileCheck %s
+; RUN: llc -mtriple=riscv64be --code-model=small  -relocation-model=pic < %s \
+; RUN:     | FileCheck %s
+; RUN: llc -mtriple=riscv64be --code-model=medium -relocation-model=pic < %s \
+; RUN:     | FileCheck %s
 
 declare void @throw_exception()
 

Add DWARF exception handling support for riscv big-endian targets.
More CodeGen changes related to riscvbe are coming.
@djtodoro djtodoro force-pushed the pr/riscvbe-codegen-tl branch from 7579839 to b0f2c48 Compare August 24, 2025 14:57
Copy link
Member

@lenary lenary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worries that this is the sort of place where a) big-endian data vs little-endian instructions will be a problem, and b) if we're using LLVM to both read and write in the test, and it is getting endianness wrong, then we won't necessarily see the issue in tests.

Have you separately cross-verified the reading and writing of dwarf data against binutils?

@djtodoro
Copy link
Collaborator Author

I'm a bit worries that this is the sort of place where a) big-endian data vs little-endian instructions will be a problem, and b) if we're using LLVM to both read and write in the test, and it is getting endianness wrong, then we won't necessarily see the issue in tests.

Have you separately cross-verified the reading and writing of dwarf data against binutils?

Yes, I checked it and it works. I am not sure if it can be incorporated into the llvm's testing infra somehow...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants