OS X 非法指令:Travis 中的 4 个-CI

OS X Illegal Instruction: 4 in Travis-CI

我有一个 Mac Mini(运行ning OS X 版本 10.11.6),我一直在尝试编译一个我想要的二进制文件 运行 在 Travis-CI OS X 服务器上。

我以前成功过(使用相同的设备)。但是这一次,我遇到了 Illegal Instruction 4 错误,您可以在 this line 上看到它。我的 Mac Mini 上没有出现此错误。该程序 运行 没问题。它只发生在 Travis-CI.

对该错误的快速堆栈溢出搜索得到了 this question, which shows that the error can be fixed by compiling the binaries with the -mmacosx-version-min=10.x flag. Well, I have tried that to no avail. To be more specific, I compiled by binary with the -mmacosx-version-min=10.9 flag, which I think should be fine considering that the Travis-CI OS X version is 10.11(这让我想知道为什么自从我在 OS X 10.11 上构建二进制文件以来,我一开始就遇到了这个错误)。

可以找到我要 运行 的二进制文件 here,如果我 运行 otool -l 在上面,我会看到这个部分:

Load command 9
cmd LC_VERSION_MIN_MACOSX
cmdsize 16
version 10.9
sdk 10.11

看起来不错。我编译它并在 OS X 10.9 的兼容模式下链接它,我在 OS X 10.11 机器上编译它。动态依赖似乎也没有问题:

Mac-mini:~ patrick$ otool -L ./osx64-genXrdPattern 
./osx64-genXrdPattern:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

这里是我构建二进制文件的 g++ 版本:

Mac-mini:~ patrick$ g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

所以我花了很多时间试图弄清楚:为什么我的二进制文件不会 运行 在 Travis-CI 上?为什么我总是收到 Illegal Instruction: 4?二进制文件似乎 运行 在我的 Mac Mini 上运行良好。如果有人知道问题出在哪里或对解决问题有任何建议,将不胜感激。谢谢!

编辑:顺便说一下,这个二进制文件的代码可以在 here, and I link it to the objcryst 库中找到。

Edit2:我尝试关闭编译器优化标志以查看优化是否发生了一些奇怪的事情。不过,即使关闭了编译器优化标志,我仍然得到相同的结果...

我给 Travis-CI 工作人员发了邮件,我收到了这个回复,我认为这解释了问题:

I had a look and I believe this can happen because we are using a mix of old Apple Xserves (from 2004) and new Mac Pros. We've had other customers writing in for the same reason and often, the call they were making required newer hardware to succeed. Hence, my hunch here is that you get this error when your build runs on an Xserve machine.

尽管 Travis-CI 是 运行 OS X 10.11,我猜旧的 Apple Xserve 硬件无法执行较新的 AppleClang 可以生成的所有指令。

我解决这个问题的方法是在 Travis-CI Xserve 机器上实际编译和 link 程序。我认为这有助于确保不会产生非法指令。该程序现在可以在 Travis-CI.

上成功运行