duanhao1004
duanhao1004
2019-05-01 13:50

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

  • ar
  • clang
  • ios
  • cydia

I'm trying to build and run Go on a self-hosted jailbroken iOS device (Corellium virtual devices). Go bootstraps and can build and run regular binaries. However, Go archives fail to build because ar doesn't work:

$ 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

Optimistic as I am, I tried 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

I even switched Go to use 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

Now, ar (with symlinked ranlib) fails on even simple object files:

$ 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 works:

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

But segfaults on more complex object files as seen above.

Go can already successfully create archives using the Xcode ar tool. It's only the iOS native "cctools" version that fails.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答