APP开启bitcode,生成.xcarchive文件,对.xcarchive文件做混淆加固


#22

另外你用的是原版的clang吗


#23

对,原版(Xcode10)和Hikari都一样,同样的错误


#24

我这里原版clang没遇到这个问题啊:

clang -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk 123.m -fobjc-arc
123.m:2:17: warning: cannot find interface declaration for 'OBDemo'
@implementation OBDemo
                ^
123.m:8:67: warning: values of type 'NSInteger' should not be used as format
      arguments; add an explicit cast to 'long' instead [-Wformat]
        NSString *str = [NSString stringWithFormat:@"Hello -> %d",i];
                                                              ~~  ^
                                                              %ld (long)
123.m:12:17: warning: incomplete format specifier [-Wformat]
        NSLog(@"%",array);
                ^
123.m:20:17: warning: values of type 'NSUInteger' should not be used as format
      arguments; add an explicit cast to 'unsigned long' instead [-Wformat]
    NSLog(@"%d",p.length);
            ~~  ^~~~~~~~
            %lu (unsigned long)
123.m:2:17: warning: class 'OBDemo' defined without specifying a base class
      [-Wobjc-root-class]
@implementation OBDemo
                ^
123.m:2:23: note: add a super class to fix this problem
@implementation OBDemo
                      ^
                       : NSObject 
5 warnings generated.
Undefined symbols for architecture arm64:
  "start", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

#25
λ : >>> clang -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk 123.m -fobjc-arc -S -emit-llvm
123.m:2:17: warning: cannot find interface declaration for 'OBDemo'
@implementation OBDemo
                ^
123.m:8:67: warning: values of type 'NSInteger' should not be used as format
      arguments; add an explicit cast to 'long' instead [-Wformat]
        NSString *str = [NSString stringWithFormat:@"Hello -> %d",i];
                                                              ~~  ^
                                                              %ld (long)
123.m:12:17: warning: incomplete format specifier [-Wformat]
        NSLog(@"%",array);
                ^
123.m:20:17: warning: values of type 'NSUInteger' should not be used as format
      arguments; add an explicit cast to 'unsigned long' instead [-Wformat]
    NSLog(@"%d",p.length);
            ~~  ^~~~~~~~
            %lu (unsigned long)
123.m:2:17: warning: class 'OBDemo' defined without specifying a base class
      [-Wobjc-root-class]
@implementation OBDemo
                ^
123.m:2:23: note: add a super class to fix this problem
@implementation OBDemo
                      ^
                       : NSObject 
5 warnings generated.
naville @ navilledeMacBook-Pro in ~/Development/HikariRelease 
λ : >>> bin/llvm-as 123.ll
naville @ navilledeMacBook-Pro in ~/Development/HikariRelease 
λ : >>> bin/llvm-nm 123.bc
---------------- t +[OBDemo P1]
---------------- t +[OBDemo myName]
                 U _NSLog
                 U _OBJC_CLASS_$_NSArray
                 U _OBJC_CLASS_$_NSString
---------------- D _OBJC_CLASS_$_OBDemo
---------------- D _OBJC_METACLASS_$_OBDemo
                 U ___CFConstantStringClassReference
                 U __objc_empty_cache
                 U _objc_msgSend
                 U _objc_retain
                 U _objc_retainAutoreleasedReturnValue
                 U _objc_storeStrong

#26

我的意思是,你不混淆用原版clang编译有这个问题吗,就同样步骤,但是不走opt


#27

我重新试了一次

clang -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -fobjc-arc -c OBDemo.bc -o OBDemo.o
warning: overriding the module target triple with arm64-apple-ios5.0.0 [-Woverride-module]
1 warning generated.
Sc:~ qaq$ ar -crs arm64.a OBDemo.o
Sc:~ qaq$ ranlib arm64.a

结果打包成.a 拖进工程还是报错

Undefined symbols for architecture arm64:
  "_clang.arc.use", referenced from:
      +[OBDemo myName] in arm64.a(OBDemo.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

nm命令出来看了,应该是没有混淆的!

---------------- t +[OBDemo P1]
---------------- t +[OBDemo myName]
                 U _NSLog
                 U _OBJC_CLASS_$_NSArray
                 U _OBJC_CLASS_$_NSObject
                 U _OBJC_CLASS_$_NSString
---------------- D _OBJC_CLASS_$_OBDemo
                 U _OBJC_METACLASS_$_NSObject
---------------- D _OBJC_METACLASS_$_OBDemo
                 U ___CFConstantStringClassReference
                 U __objc_empty_cache
                 U _clang.arc.use
                 U _objc_msgSend
                 U _objc_release
                 U _objc_retainAutoreleasedReturnValue

#28

hmmmm我没法复现你的问题啊


#29

奇怪的是我把源码中语法糖(@[str2])删掉之后就正常编译了!


#30

啊这就跟我观察到的IR的问题解释通了,我研究一下上上流问问


#31

之前看Hikari的原帖我看到有人反馈过,是环境的问题.我刚刚换了台电脑…一切正常 玄学呀~
多次尝试后补充: xcodeproj版本太老导致的报错,新建一个工程放入混淆之后的库一切正常,感谢张总的指导了~


#32

并不是。看起来只是前端的锅,我拿llvm的复现了下好像确实有问题,我到mailing list上问了还没人回我


#33

是的,新旧xcodeproj工程默认引用了静态库,新工程没有引用,所以能正常编译 :rofl: 看来还是我高兴太早了