使用ar或libtool创建静态存档在越狱iOS上失败

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用ar或libtool创建静态存档在越狱iOS上失败相关的知识,希望对你有一定的参考价值。

我正在尝试在自托管的越狱ios设备(Corellium虚拟设备)上构建和运行Go。去bootstraps,可以构建和运行常规二进制文件。但是,Go归档无法构建,因为ar不起作用:

$ dpkg -S /usr/bin/clang /usr/bin/ar /usr/bin/libtool
org.coolstar.llvm-clang64: /usr/bin/clang
org.coolstar.cctools: /usr/bin/ar
org.coolstar.cctools: /usr/bin/libtool
$ apt policy org.coolstar.cctools org.coolstar.llvm-clang64
org.coolstar.cctools:
  Installed: 895
  Candidate: 895
  Version table:
 *** 895 500
        500 http://apt.thebigboss.org/repofiles/cydia stable/main iphoneos-arm Packages
        100 /Library/dpkg/status
org.coolstar.llvm-clang64:
  Installed: 5.0.1-2
  Candidate: 5.0.1-2
  Version table:
 *** 5.0.1-2 500
        500 http://apt.thebigboss.org/repofiles/cydia stable/main iphoneos-arm Packages
        100 /Library/dpkg/status

$ ../bin/go build -buildmode=c-archive -ldflags="-v" -work ../misc/ios/detect.go
WORK=/tmp/go-build734936238
# command-line-arguments
HEADER = -H1 -T0x2000 -R0x1000
 0.00 deadcode
 0.05 symsize = 0
 0.08 pclntab=740717 bytes, funcdata total 185492 bytes
 0.08 dodata
 0.08 symsize = 0
 0.08 symsize = 0
 0.09 dynreloc
 0.09 dwarf
 0.12 asmb
 0.13 datblk
 0.14 reloc
 0.20 sym
 0.22 header
archive: ar -q -c -s $WORK/b001/exe/a.out.a /tmp/go-link-569975294/go.o /tmp/go-link-569975294/000000.o /tmp/go-link-569975294/000001.o /tmp/go-link-569975294/000002.o /tmp/go-link-569975294/000003.o /tmp/go-link-569975294/000004.o /tmp/go-link-569975294/000005.o /tmp/go-link-569975294/000006.o /tmp/go-link-569975294/000007.o /tmp/go-link-569975294/000008.o /tmp/go-link-569975294/000009.o /tmp/go-link-569975294/000010.o /tmp/go-link-569975294/000011.o /tmp/go-link-569975294/000012.o /tmp/go-link-569975294/000013.o /tmp/go-link-569975294/000014.o
/var/mobile/go-tip/pkg/tool/darwin_arm64/link: running ar failed: exit status 1
fatal error: ar: can't find or exec: /usr/bin/arm64-apple-darwin14-ranlib (No such file or directory)
ar: internal ranlib command failed

像我一样乐观,我尝试了symlinking ranlib:

# ln -s /usr/bin/ranlib /usr/bin/arm64-apple-darwin14-ranlib
$ ../bin/go build -buildmode=c-archive -ldflags="-v" -work ../misc/ios/detect.go
WORK=/tmp/go-build239621581
# command-line-arguments
HEADER = -H1 -T0x2000 -R0x1000
 0.00 deadcode
 0.06 symsize = 0
 0.08 pclntab=740717 bytes, funcdata total 185492 bytes
 0.08 dodata
 0.09 symsize = 0
 0.09 symsize = 0
 0.09 dynreloc
 0.10 dwarf
 0.12 asmb
 0.13 datblk
 0.15 reloc
 0.20 sym
 0.22 header
archive: ar -q -c -s $WORK/b001/exe/a.out.a /tmp/go-link-618780113/go.o /tmp/go-link-618780113/000000.o /tmp/go-link-618780113/000001.o /tmp/go-link-618780113/000002.o /tmp/go-link-618780113/000003.o /tmp/go-link-618780113/000004.o /tmp/go-link-618780113/000005.o /tmp/go-link-618780113/000006.o /tmp/go-link-618780113/000007.o /tmp/go-link-618780113/000008.o /tmp/go-link-618780113/000009.o /tmp/go-link-618780113/000010.o /tmp/go-link-618780113/000011.o /tmp/go-link-618780113/000012.o /tmp/go-link-618780113/000013.o /tmp/go-link-618780113/000014.o
/var/mobile/go-tip/pkg/tool/darwin_arm64/link: running ar failed: exit status 1
/usr/bin/arm64-apple-darwin14-ranlib: archive member: $WORK/b001/exe/a.out.a(go.o) offset in archive not a multiple of 8 (must be since member is an 64-bit object file)
fatal error: ar: fatal error in /usr/bin/arm64-apple-darwin14-ranlib

我甚至切换到使用libtool:

$ ../bin/go build -buildmode=c-archive -ldflags="-v" -work ../misc/ios/detect.go
WORK=/tmp/go-build502332895
# command-line-arguments
HEADER = -H1 -T0x2000 -R0x1000
 0.00 deadcode
 0.04 symsize = 0
 0.08 pclntab=740717 bytes, funcdata total 185492 bytes
 0.08 dodata
 0.08 symsize = 0
 0.09 symsize = 0
 0.09 dynreloc
 0.10 dwarf
 0.12 asmb
 0.14 datblk
 0.15 reloc
 0.20 sym
 0.22 header
archive: libtool -static -o $WORK/b001/exe/a.out.a /tmp/go-link-320669019/go.o /tmp/go-link-320669019/000000.o /tmp/go-link-320669019/000001.o /tmp/go-link-320669019/000002.o /tmp/go-link-320669019/000003.o /tmp/go-link-320669019/000004.o /tmp/go-link-320669019/000005.o /tmp/go-link-320669019/000006.o /tmp/go-link-320669019/000007.o /tmp/go-link-320669019/000008.o /tmp/go-link-320669019/000009.o /tmp/go-link-320669019/000010.o /tmp/go-link-320669019/000011.o /tmp/go-link-320669019/000012.o /tmp/go-link-320669019/000013.o /tmp/go-link-320669019/000014.o
/var/mobile/go-tip/pkg/tool/darwin_arm64/link: running libtool failed: signal: segmentation fault

现在,即使是简单的对象文件,ar(带符号链接的ranlib)也会失败:

$ cat blah.c
int blah() {
    return 0;
}
$ clang -c blah.c
$ ar -q -c -s blah.a blah.o
/usr/bin/arm64-apple-darwin14-ranlib: archive member: blah.a(blah.o) offset in archive not a multiple of 8 (must be since member is an 64-bit object file)

Libtool的工作原理:

$ libtool -static -o blah.a blah.o

但是如上所示,对更复杂的目标文件进行了段错误。

Go已经可以使用Xcode ar工具成功创建存档。这只是iOS原生的“cctools”版本失败了。

答案

我使用llvm-ar解决了这个问题。命令行标志略有不同,但至少我现在有一个工作档案。

以上是关于使用ar或libtool创建静态存档在越狱iOS上失败的主要内容,如果未能解决你的问题,请参考以下文章

IOS如何打越狱包xcode无证书打包ios应用

(原)用xcode9编译出ios越狱机程序使用的dylib

iOS 6.x 在越狱时打开命令行

iOS-ARKit创建多用户AR体验-Creating a Multiuser AR Experience

iOS-ARKit创建多用户AR体验-Creating a Multiuser AR Experience

ios14越狱到最高版本后出现这些漏洞