使用 LTO 时,负载/存储的 LD 验证失败,但没有提供太多信息



更新到 Xcode 10 后,我们的 C++ 代码库在使用 -Os 和 -flto 构建时不会链接。提供了以下错误:

ld: Explicit load/store type does not match pointee type of pointer operand (Producer: 'APPLE_1_1000.11.45.2_0' Reader: 'LLVM APPLE_1_1000.11.45.2_0') for architecture x86_64

(在最新的 Xcode 10.1 Beta 3 上也会出现同样的错误(

同样的代码在 Xcode 9 中构建得很好。可悲的是,链接器除了吐出上述错误消息外,没有提供更多信息。有关目标文件的一些信息将有助于尝试查明问题的确切来源。删除 -flto 可消除错误...

有人有任何调试建议/想法吗?我们尝试将"--trace"与ld一起使用以获取有关正在处理的文件的更多信息,但错误消息只是在跟踪的中间输出,错误与当时正在打印的输入文件之间没有明显的相关性。

这一切都闻起来非常像编译器错误,我已经通过错误跟踪器向Apple报告了这个问题。

任何额外的帮助将不胜感激。谢谢

在我的情况下,打开任何优化 -O1,2,3 都会吐出此错误(当 -flto 关闭时( 我跟踪它到以下问题。 我创建了一个类Algo_three - 以便我可以从函数返回 3 个值:

@interface Algo_three<T,V,W> : NSObject{
@public
T p_0;
V p_1;
W p_2;
}
+ (Algo_three<T,V,W>*) first:(T) f second:(V) s third:(W) t;
@end

我按如下方式使用它(在 .m 文件中(

+(Algo_three<NSManagedObjectContext*,NSManagedObjectContext*,NSError*>*) CreateCDContexts: ....
{
return [Algo_three first:ui_managedObjectContext second:sync_managedObjectContext third:nil];
}

收到3个值 - 这也很好。

Algo_three<NSManagedObjectContext*,NSManagedObjectContext*,NSError*> * two_contexts = [not_important_class CreateCDContexts: ... ];
//and here is accessing
self->ui_context = (NSManagedObjectContext*) two_contexts->p_0; //getting 1st value
self->sync_context = (NSManagedObjectContext*) two_contexts->p_1; //2nd value

注释掉最后两行消除了错误! 所以我向类 Algo_three 添加了三个访问器属性,它起作用了。 Algo_three类看起来像这样 (.h(。

@interface Algo_three<T,V,W> : NSObject{
@public
T p_0;
V p_1;
W p_2;
}
@property (strong,nonatomic) T first;
@property (strong,nonatomic) V second;
@property (strong,nonatomic) W third;
+ (Algo_three<T,V,W>*) first:(T) f second:(V) s third:(W) t;
@end

这些属性的实现 (.m(:

- (id) first{
return p_0;
}
-(void) setFirst:(id) obj{
self->p_0 = obj;
}
- (id) second{
return p_1;
}
-(void) setSecond:(id) obj{
self->p_1 = obj;
}
- (id) third{
return p_2;
}
-(void) setThird:(id) obj{
self->p_2 = obj;
}

而不是 ->p_0 访问是通过属性 .first、.second 完成的

self->ui_context = (NSManagedObjectContext*) two_contexts.first;
self->sync_context = (NSManagedObjectContext*) two_contexts.second;

最后我承认 - 编译器告诉我错误位于哪个文件中,尽管不是那么清楚。 XCode 10.1 (10B61(。我仔细检查了编译器错误之前的文件 - 我通过从命令行运行存档来确认它:

xcodebuild -scheme MY_PROJ archive

最新更新