gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
434 stars 118 forks source link

windows objc runtime assertion fail when compile my own code with debug enabled #112

Closed ghost closed 5 years ago

ghost commented 5 years ago

my code is (main.mm):

#include <iostream>

extern "C" id class_createInstance(Class, size_t);

@interface Test

+ (instancetype)alloc;

- (void)test;

@end

@implementation Test

+ (instancetype)alloc { return class_createInstance(self, 0); }

- (void)test { std::cout << "Hello World!\n"; }

@end

int main() { Test *test = [Test alloc]; [test test]; return 0; }

and the command I use to compile is: clang-cl main.mm -fobjc-runtime=gnustep-2.0 -o main.exe /Zi /link objc.lib and when I run my program (main.exe), it will trigger assertion fail on file loader.c in line 223 and 224 then crash. note that if I remove "/Zi" and compile my code, my program will run successfully and print a "Hello World!" on console.

davidchisnall commented 5 years ago

It looks as if /Zi enables incremental linking. As documented, incremental linking does not work until link.exe gains a feature to exclude specific sections from gaining extra padding. Try adding /INCREMENTAL:NO, or linking with lld-link.exe.