Skip to content
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

[LoongArch64] Modify dwarfReg in native llvm-libunwind to be consistent with the LoongArch manual. #106308

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Buffers;
using System.Diagnostics;
using Internal.TypeSystem;
using static ILCompiler.ObjectWriter.DwarfNative;

Expand Down Expand Up @@ -162,7 +163,10 @@ public static int DwarfRegNum(TargetArchitecture architecture, int regNum)
};

case TargetArchitecture.LoongArch64:
Debug.Assert(regNum <= 64);
sunlijun-610 marked this conversation as resolved.
Show resolved Hide resolved
// Normal registers are directly mapped
if (regNum >= 33)
regNum = regNum - 33 + 64; // FP
return regNum;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_RISCV 64
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_VE 143
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_S390X 83
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH 64
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH 95

#if defined(_LIBUNWIND_IS_NATIVE_ONLY)
# if defined(__linux__)
Expand Down
64 changes: 32 additions & 32 deletions src/native/external/llvm-libunwind/include/libunwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -1286,38 +1286,38 @@ enum {
UNW_LOONGARCH_R29 = 29,
UNW_LOONGARCH_R30 = 30,
UNW_LOONGARCH_R31 = 31,
UNW_LOONGARCH_F0 = 32,
UNW_LOONGARCH_F1 = 33,
UNW_LOONGARCH_F2 = 34,
UNW_LOONGARCH_F3 = 35,
UNW_LOONGARCH_F4 = 36,
UNW_LOONGARCH_F5 = 37,
UNW_LOONGARCH_F6 = 38,
UNW_LOONGARCH_F7 = 39,
UNW_LOONGARCH_F8 = 40,
UNW_LOONGARCH_F9 = 41,
UNW_LOONGARCH_F10 = 42,
UNW_LOONGARCH_F11 = 43,
UNW_LOONGARCH_F12 = 44,
UNW_LOONGARCH_F13 = 45,
UNW_LOONGARCH_F14 = 46,
UNW_LOONGARCH_F15 = 47,
UNW_LOONGARCH_F16 = 48,
UNW_LOONGARCH_F17 = 49,
UNW_LOONGARCH_F18 = 50,
UNW_LOONGARCH_F19 = 51,
UNW_LOONGARCH_F20 = 52,
UNW_LOONGARCH_F21 = 53,
UNW_LOONGARCH_F22 = 54,
UNW_LOONGARCH_F23 = 55,
UNW_LOONGARCH_F24 = 56,
UNW_LOONGARCH_F25 = 57,
UNW_LOONGARCH_F26 = 58,
UNW_LOONGARCH_F27 = 59,
UNW_LOONGARCH_F28 = 60,
UNW_LOONGARCH_F29 = 61,
UNW_LOONGARCH_F30 = 62,
UNW_LOONGARCH_F31 = 63,
UNW_LOONGARCH_F0 = 64,
Copy link
Member

@jkotas jkotas Aug 14, 2024

Choose a reason for hiding this comment

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

This is vendored project from https://github.com/llvm/llvm-project/blob/main/libunwind/include/libunwind.h#L1269 . Is this a bug in the upstream project? If yes, could you please make sure that this fix is upstreamed to https://github.com/llvm/llvm-project as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks very much~!
You are right.
The jit/unwindloongarch64.cpp is too old.

we have to follow the latest la-abi speci https://github.com/loongson/la-abi-specs/blob/release/ladwarf.adoc
And we have to modify this file https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/unwindarm64.cpp#L21

Also thanks @filipnavara

We will close this PR and push a new PR to modify the unwindarm64.cpp.

UNW_LOONGARCH_F1 = 65,
UNW_LOONGARCH_F2 = 66,
UNW_LOONGARCH_F3 = 67,
UNW_LOONGARCH_F4 = 68,
UNW_LOONGARCH_F5 = 69,
UNW_LOONGARCH_F6 = 70,
UNW_LOONGARCH_F7 = 71,
UNW_LOONGARCH_F8 = 72,
UNW_LOONGARCH_F9 = 73,
UNW_LOONGARCH_F10 = 74,
UNW_LOONGARCH_F11 = 75,
UNW_LOONGARCH_F12 = 76,
UNW_LOONGARCH_F13 = 77,
UNW_LOONGARCH_F14 = 78,
UNW_LOONGARCH_F15 = 79,
UNW_LOONGARCH_F16 = 80,
UNW_LOONGARCH_F17 = 81,
UNW_LOONGARCH_F18 = 82,
UNW_LOONGARCH_F19 = 83,
UNW_LOONGARCH_F20 = 84,
UNW_LOONGARCH_F21 = 85,
UNW_LOONGARCH_F22 = 86,
UNW_LOONGARCH_F23 = 87,
UNW_LOONGARCH_F24 = 88,
UNW_LOONGARCH_F25 = 89,
UNW_LOONGARCH_F26 = 90,
UNW_LOONGARCH_F27 = 91,
UNW_LOONGARCH_F28 = 92,
UNW_LOONGARCH_F29 = 93,
UNW_LOONGARCH_F30 = 94,
UNW_LOONGARCH_F31 = 95,
};

#endif
2 changes: 2 additions & 0 deletions src/native/external/llvm-libunwind/src/Registers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5332,6 +5332,8 @@ inline bool Registers_loongarch::validRegister(int regNum) const {
return true;
if (regNum < 0 || regNum > UNW_LOONGARCH_F31)
return false;
if (regNum > UNW_LOONGARCH_R31 && regNum < UNW_LOONGARCH_F0)
return false;
return true;
}

Expand Down
Loading