Qv2ray: Tracker: Support for macOS Big Sur M1

Created on 8 Jan 2021  ·  18Comments  ·  Source: Qv2ray/Qv2ray

  1. 为本体适配 macOS Big Sur M1 的编译并打包
  2. 为插件适配 macOS Big Sur M1 的编译并打包

    • [ ] QvPlugin-SS

    • [ ] QvPlugin-SSR

    • [ ] QvPlugin-Trojan

    • [ ] QvPlugin-Trojan-Go

    • [ ] QvPlugin-NaiveProxy

    • [ ] QvPlugin-Command

NewFeature help wanted platformacOS pr-welcome compiling

Most helpful comment

@DuckSoft 目前还在折腾arm64的原生编译,依赖项grpc有打包问题正在和brew排查,进度: https://github.com/Homebrew/discussions/discussions/485#discussioncomment-270702

homebrew-core#68575homebrew-core#68585 完成之后应该就可以编译一份Qv2ray 2.6.3的aarch64版了。

All 18 comments

@LER0ever quic 的问题好解决,编译时移除掉就好了

@LER0ever 希望来点给 macOS Big Sur M1 进行 Cross Build 的信息和提示。
同时,欢迎有志之士发点 PR、协助测试。咱因为没有 macOS 设备,也没有 M1 设备,完全帮不上忙。

多谢。

@DuckSoft 目前还在折腾arm64的原生编译,依赖项grpc有打包问题正在和brew排查,进度: https://github.com/Homebrew/discussions/discussions/485#discussioncomment-270702

homebrew-core#68575homebrew-core#68585 完成之后应该就可以编译一份Qv2ray 2.6.3的aarch64版了。

@LER0ever You may want to try compiling against the dev branch.

gRPC was not properly configured in the master branch code. (It used to be working, but not now)

You may want to try compiling against the dev branch.

@U-v-U 需要一些帮助,目前dev branch可以编译通过,但是无法运行,看错误应该是某个动态库的codesign问题

Crash Report:

Process:               qv2ray [20107]
Path:                  /Users/USER/*/qv2ray.app/Contents/MacOS/qv2ray
Identifier:            qv2ray
Version:               2.7.0-pre1 (2.7.0-pre1)
Code Type:             ARM-64 (Native)
Parent Process:        zsh [19179]
Responsible:           Terminal [2813]
User ID:               501

Date/Time:             2021-01-10 21:25:00.858 +0800
OS Version:            macOS 11.1 (20C69)
Report Version:        12
Anonymous UUID:        9881BD7B-6A7F-3CB4-A05E-74C7851C25BA

Sleep/Wake UUID:       486E98E4-A042-44B9-9B78-BEB986ED7790

Time Awake Since Boot: 110000 seconds
Time Since Wake:       34000 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_BAD_ACCESS (Code Signature Invalid)
Exception Codes:       0x0000000000000032, 0x0000000105358000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace CODESIGNING, Code 0x2

kernel messages:

VM Regions Near 0x105358000:
    __LINKEDIT                  1052b8000-105358000    [  640K] r--/r-- SM=COW  /Users/*/qv2ray.app/Contents/MacOS/qv2ray
--> mapped file                 105358000-10535c000    [   16K] r--/r-x SM=PRV  Object_id=4355a7d
    __TEXT                      1055a4000-105620000    [  496K] r-x/r-x SM=COW  /usr/lib/dyld

Application Specific Information:
dyld: launch, loading dependent libraries
@executable_path/../Frameworks/QtNetwork.framework/Versions/5/QtNetwork

Thread 0 Crashed:
0   dyld                            0x0000000105600780 bcmp + 16
1   dyld                            0x00000001055c1408 ImageLoaderMachO::validateFirstPages(linkedit_data_command const*, int, unsigned char const*, unsigned long, long long, ImageLoader::LinkContext const&) + 136
2   dyld                            0x00000001055c83b8 ImageLoaderMachOCompressed::instantiateFromFile(char const*, int, unsigned char const*, unsigned long, unsigned long long, unsigned long long, stat const&, unsigned int, unsigned int, linkedit_data_command const*, encryption_info_command const*, ImageLoader::LinkContext const&) + 268
3   dyld                            0x00000001055bfffc ImageLoaderMachO::instantiateFromFile(char const*, int, unsigned char const*, unsigned long, unsigned long long, unsigned long long, stat const&, ImageLoader::LinkContext const&) + 172
4   dyld                            0x00000001055a8290 dyld::loadPhase6(int, stat const&, char const*, dyld::LoadContext const&) + 668
5   dyld                            0x00000001055b0dd8 dyld::loadPhase5(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 1328
6   dyld                            0x00000001055b0824 dyld::loadPhase4(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 208
7   dyld                            0x00000001055b033c dyld::loadPhase3(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 600
8   dyld                            0x00000001055afcf0 dyld::loadPhase1(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 212
9   dyld                            0x00000001055a7e0c dyld::loadPhase0(char const*, char const*, dyld::LoadContext const&, unsigned int&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 468
10  dyld                            0x00000001055a79b0 dyld::load(char const*, dyld::LoadContext const&, unsigned int&) + 196
11  dyld                            0x00000001055b177c dyld::libraryLocator(char const*, bool, char const*, ImageLoader::RPathChain const*, unsigned int&) + 56
12  dyld                            0x00000001055bb9d4 ImageLoader::recursiveLoadLibraries(ImageLoader::LinkContext const&, bool, ImageLoader::RPathChain const&, char const*) + 344
13  dyld                            0x00000001055ba1ac ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, bool, ImageLoader::RPathChain const&, char const*) + 160
14  dyld                            0x00000001055aa5f4 dyld::link(ImageLoader*, bool, bool, ImageLoader::RPathChain const&, unsigned int) + 328
15  dyld                            0x00000001055ac928 dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 6764
16  dyld                            0x00000001055a5258 dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*) + 476
17  dyld                            0x00000001055a5038 _dyld_start + 56

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000105358000   x1: 0x000000016ae6d340   x2: 0x0000000000000c50   x3: 0x0000000000040001
    x4: 0x0000000000000003   x5: 0x0000000000000000   x6: 0x0000000105628280   x7: 0x0000000000000000
    x8: 0x0000000000000000   x9: 0x000000016ae6dae0  x10: 0x0000000000000001  x11: 0x0001803000000000
   x12: 0x0000000000000032  x13: 0x0004000000000000  x14: 0x0000000000156f98  x15: 0x000000016ae6da60
   x16: 0x00000000000000c5  x17: 0x0000000000000000  x18: 0x0000000000000000  x19: 0x000000010562daf0
   x20: 0x0000000000000c60  x21: 0x000000016ae6d340  x22: 0x0000000105358000  x23: 0x0000000000000003
   x24: 0x000000016ae6df90  x25: 0x000000016ae75458  x26: 0x000000016ae755d0  x27: 0x000000016ae6d340
   x28: 0x000000000000000c   fp: 0x000000016ae6cd40   lr: 0x00000001055c1408
    sp: 0x000000016ae6cd00   pc: 0x0000000105600780 cpsr: 0x20000000
   far: 0x0000000105358000  esr: 0x92000007


Binary Images:
       0x104f88000 -        0x105293fff +com.github.qv2ray (2.7.0-pre1 - 2.7.0-pre1) <7AB548EC-4D55-3525-96F0-1D7D52230A7F> /Users/USER/*/qv2ray.app/Contents/MacOS/qv2ray
       0x1055a4000 -        0x10561ffff  dyld (832.7.1) <B7DB9E8A-A898-3C11-91A0-2B0264F05CB6> /usr/lib/dyld
       0x19b1c2000 -        0x19b51ffff  com.apple.security (7.0 - 59754.60.13) <495AE9B1-FAB5-3409-A758-B837B872CD61> /System/Library/Frameworks/Security.framework/Versions/A/Security
       0x1acf74000 -        0x1acf77fff  com.apple.Cocoa (6.11 - 23) <E07A10C4-E5C3-39CD-9231-C91BF75E29DB> /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa
       0x1b4fec000 -        0x1b4feffff  com.apple.Carbon (160 - 164) <9455FEDB-56A3-38DD-8473-41826E74C4CC> /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 12977907
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=487.2M resident=0K(0%) swapped_out_or_unallocated=487.2M(100%)
Writable regions: Total=8400K written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=8400K(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
STACK GUARD                       56.0M        1 
Stack                             8176K        1 
__AUTH                             2176        1 
__AUTH_CONST                       189K        1 
__DATA                             317K        5 
__DATA_CONST                       218K        3 
__DATA_DIRTY                         6K        1 
__LINKEDIT                       480.3M        4 
__OBJC_CONST                         6K        1 
__TEXT                            7096K        5 
mapped file                         16K        1 
===========                     =======  ======= 
TOTAL                            551.9M       24 

做的修改主要有两个

  1. 将Homebrew aarch64的lib路径加入了DIRS变量
  2. 合并了backward-cpp最新的master branch代码,因为其中包括了对Apple Silicon的fix: https://github.com/bombela/backward-cpp/pull/201
diff --git a/3rdparty/backward-cpp b/3rdparty/backward-cpp
--- a/3rdparty/backward-cpp
+++ b/3rdparty/backward-cpp
@@ -1 +1 @@
-Subproject commit 42c350d16545a2fb89ba2fea815b9bbf69de66d8
+Subproject commit 42c350d16545a2fb89ba2fea815b9bbf69de66d8-dirty
diff --git a/cmake/deployment.cmake b/cmake/deployment.cmake
index 362826f8..edb5167d 100644
--- a/cmake/deployment.cmake
+++ b/cmake/deployment.cmake
@@ -71,6 +71,7 @@ if(QV2RAY_QT6)
 else()
     list(APPEND DIRS "${Qt5Widgets_DIR}/../..")
 endif()
+list(APPEND DIRS "/opt/homebrew/lib")
 list(APPEND DIRS "/usr/local/lib")
 list(APPEND DIRS "/usr/lib")

git diff for backward-cpp

diff --cc backward.hpp
index 2c929a7,e79e262..0000000
--- a/backward.hpp
+++ b/backward.hpp
@@@ -682,10 -708,11 +708,12 @@@ public
    size_t size() const { return 0; }
    Trace operator[](size_t) const { return Trace(); }
    size_t load_here(size_t = 0) { return 0; }
-   size_t load_from(void *, size_t = 0) { return 0; }
+   size_t load_from(void *, size_t = 0, void * = nullptr, void * = nullptr) {
+     return 0;
+   }
    size_t thread_id() const { return 0; }
    void skip_n_firsts(size_t) {}
 +  bool can_safely_backtrace() { return true; }
  };

  class StackTraceImplBase {
@@@ -3398,9 -3593,9 +3626,9 @@@ public
                          FORMAT_MESSAGE_FROM_SYSTEM |
                          FORMAT_MESSAGE_IGNORE_INSERTS,
                      NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                     (LPTSTR)&lpMsgBuf, 0, NULL);
+                     (char*)&lpMsgBuf, 0, NULL);

 -      printf(lpMsgBuf);
 +      // printf(lpMsgBuf);

        // abort();
      }
@@@ -3978,18 -4177,16 +4210,24 @@@ public
  #else
  #warning ":/ sorry, ain't know no nothing none not of your architecture!"
  #endif
+     if (error_addr) {
+       st.load_from(error_addr, 32, reinterpret_cast<void *>(uctx),
+                    info->si_addr);
+     } else {
+       st.load_here(32, reinterpret_cast<void *>(uctx), info->si_addr);
+     }

 -    Printer printer;
 -    printer.address = true;
 -    printer.print(st, stderr);
 +    if (st.can_safely_backtrace()) {
 +      if (error_addr) {
 +        st.load_from(error_addr, 32);
 +      } else {
 +        st.load_here(32);
 +      }
 +
 +      Printer printer;
 +      printer.address = true;
 +      printer.print(st, stderr);
 +    }

  #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
      psiginfo(info, nullptr);

编译指令

mkdir build && cd build
export OPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl/
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(pwd)/root/
cmake --build . --parallel 6
cmake --install .

賭五毛錢是 rpath 问题。


update: 不太妙……EXC_BAD_ACCESS (Code Signature Invalid)
可能需要什么代码签名之类的东西?

https://github.com/mas-cli/mas/issues/308#issuecomment-749804230
基本石锤了,要 ad-hoc sign

On the production Apple Silicon machines, Go binaries are killed at start. #38485 (comment)

It looks like all binaries need to be codesigned now, and indeed running codesign -s - on them lets them run correctly.

This stops go test and go run from working, and requires an extra step after go build to get a functional binary.

This also affects the bootstrapped compiler itself.

https://github.com/golang/go/issues/42684

mas-cli/mas#308 (comment)
基本石锤了,要 ad-hoc sign

rongyi in LER0ever-MacBookAir in ~/Code/Qt/Qv2ray/build on  dev [!?] at 22:03:28 
∅ codesign -dv --verbose=4 qv2ray.app                                                  
Executable=/Users/rongyi/Code/Qt/Qv2ray/build/qv2ray.app/Contents/MacOS/qv2ray
Identifier=qv2ray
Format=app bundle with Mach-O thin (arm64)
CodeDirectory v=20400 size=30911 flags=0x20002(adhoc,linker-signed) hashes=963+0 location=embedded
VersionPlatform=1
VersionMin=720896
VersionSDK=721152
Hash type=sha256 size=32
CandidateCDHash sha256=b5ecbcbdf8dc70b84803b3ee9ca92ce26a5adf15
CandidateCDHashFull sha256=b5ecbcbdf8dc70b84803b3ee9ca92ce26a5adf15636a643add83ba6e71076176
Hash choices=sha256
CMSDigest=b5ecbcbdf8dc70b84803b3ee9ca92ce26a5adf15636a643add83ba6e71076176
CMSDigestType=2
Executable Segment base=0
Executable Segment limit=3194880
Executable Segment flags=0x1
Page size=4096
CDHash=b5ecbcbdf8dc70b84803b3ee9ca92ce26a5adf15
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements=none

rongyi in LER0ever-MacBookAir in ~/Code/Qt/Qv2ray/build on  dev [!?] at 22:03:58 
∅ codesign --verify --deep --verbose qv2ray.app/Contents/MacOS/qv2ray
qv2ray.app/Contents/MacOS/qv2ray: code has no resources but signature indicates they must be present

貌似显示的确是ad-hoc sign,并且ad-hoc sign不应该是自动的么

https://github.com/golang/go/issues/38485#issuecomment-729301832
看样子要给所有库全都签一遍……

上面日志里:

Application Specific Information:
dyld: launch, loading dependent libraries
@executable_path/../Frameworks/QtNetwork.framework/Versions/5/QtNetwork

是不是得给 qv2ray.app/Contents/Frameworks 里面的也全签了

@DuckSoft 试过了,如果运行codesign -s -给无论是MacOS下的二进制还是Frameworks下的dylib,都会收到提示

qv2ray.app/Contents/Frameworks/QtNetwork.framework: is already signed

所以的确是已经签过了的

I got no idea. That's very sad.

Hitting the same problem with a Go project today... Upstream report https://openradar.appspot.com/FB8914243 "_arm64: Copying a new Mach-O executable to an inode that previously contained a different Mach-O executable produces something that incorrectly fails code signature verification and won’t run_" (via https://bugs.llvm.org/show_bug.cgi?id=46644#c7)

Screen Shot 2021-01-14 at 2 24 00 PM

貌似M1下二进制的移动会触发某些机制,导致运行时kernel认为codesign不通过,而macdeployqt估计需要移动Qt5Core之类的framework估计也是撞了一把相同的bug,anyway等一波Apple的回复。

一位勇士 @ymshenyu 成功了。等一下分享。

Was this page helpful?
0 / 5 - 0 ratings