yitter/IdGenerator

對ARM架構DLL的支持

Opened this issue · 2 comments

lolove commented

你好,最近嘗試在ARM架構上開發ASP.NET專案,發現動態庫中的dll只支援x64架構。想請問是否有支持arm架構的dll庫,或是我可以怎麼編譯出支援arm架構的dll庫?謝謝

抱歉,最近因为换了手机,导致2FA登录有问题,一直没有回复。
你说的动态库是哪个?注册 WorkerId 的那个吗?

感謝你的回覆,以下是我遇到的問題:

問題描述

我嘗試將regworkerid專案編譯成動態庫(dylib)以支援MacOS M系列芯片(arm64架構),但在編譯過程中遇到了segmentation fault錯誤。

環境資訊

  • 操作系統:MacOS (M系列芯片)
  • Go版本:1.24.1
  • 目標:生成dylib動態庫以支援C#調用

目前的C#代碼

我的C#代碼需要調用以下三個方法:

  • RegisterOne
  • UnRegister
  • Validate
public class YitIdInitHelper
{
    //定义dll路径
    public const string RegWorkerId_DLL_NAME = "lib\\regworkerid_lib_v1.3.1\\yitidgengo.dll";
    
    [DllImport(RegWorkerId_DLL_NAME, EntryPoint = "RegisterOne", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
    private static extern ushort RegisterOne(string ip, int port, string password, int maxWorkerId);

    [DllImport(RegWorkerId_DLL_NAME, EntryPoint = "UnRegister", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
    private static extern void UnRegister();

    [DllImport(RegWorkerId_DLL_NAME, EntryPoint = "Validate", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
    private static extern int Validate(int workerId);

    // 调用方法...
}

編譯命令

CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o ./libyitidgengo.dylib -buildmode=c-shared main.go

錯誤信息

執行時出現segmentation fault錯誤,具體為:

unexpected fault address 0x18e0
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18e0 pc=0x1364e1148]

從堆棧跟踪來看,錯誤發生在:

main.RegisterOne(0x1400006ae38?, 0x18eb, 0x1711633a0, 0x3f, 0x366ca174, 0x95bbc08, 0x6)
    /Users/xxx/Downloads/IdGenerator-master 2/Go/regworkerid/main.go:46 +0x50

相關資源

感謝任何幫助!