Bug 16096 – Linking to static library: can't parse __DATA/__objc_imageinfo

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2016-05-30T12:50:00Z
Last change time
2016-10-01T11:47:39Z
Assigned to
nobody
Creator
freeslave93

Comments

Comment #0 by freeslave93 — 2016-05-30T12:50:10Z
I have two files. The one has Objective-C functions and interface declarations written in D. Another file is main app and it imports the first and uses its functions. Imported file: http://codepad.org/jqdBb6sh Main file: http://codepad.org/0gKBqKxi When I compile them in one command it runs without problems. dmd main.d domaindir.d -L-framework -LFoundation But I want domaindir.d to be static library and link main.d against this library. So I do: dmd -lib domaindir.d dmd main.d -I. -L-framework -LFoundation domaindir.a The second command prints warning: ld: warning: can't parse __DATA/__objc_imageinfo section in domaindir.a(domaindir_5_397.o) When I try to run ./main it fails: 2016-04-30 13:05:55.733 main[15762:685588] *** NSForwarding: warning: selector (0x1040f5e58) for message 'defaultManager' does not match selector known to Objective C runtime (0x7fff8aeed3af)-- abort 2016-04-30 13:05:55.734 main[15762:685588] +[NSFileManager defaultManager]: unrecognized selector sent to class 0x7fff7baaad28 2016-04-30 13:05:55.736 main[15762:685588] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSFileManager defaultManager]: unrecognized selector sent to class 0x7fff7baaad28' *** First throw call stack: ( 0 CoreFoundation 0x00007fff95fab03c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff99ac176e objc_exception_throw + 43 2 CoreFoundation 0x00007fff95fadfad +[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x00007fff95ef3e24 ___forwarding___ + 1028 4 CoreFoundation 0x00007fff95ef3998 _CF_forwarding_prep_0 + 120 5 main 0x00000001040baf58 D9domaindir9domainDirFNemmbZAya + 56 6 main 0x00000001040ba9cb _Dmain + 283 7 main 0x00000001040d515c D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 40 8 main 0x00000001040d5090 D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFMDFZvZv + 36 9 main 0x00000001040d5101 D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZv + 45 10 main 0x00000001040d5090 D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFMDFZvZv + 36 11 main 0x00000001040d4ff6 _d_run_main + 498 12 main 0x00000001040baa80 main + 16 13 libdyld.dylib 0x00007fff92ee25c9 start + 1 14 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6 Using dmd v2.071.0 on OS X 10.10.5
Comment #1 by doob — 2016-06-08T11:20:17Z
It seems to be some kind of problem with the -lib flag. If you compile with -c to create an object file and the create a library using "ar" it works. You can use that as a workaround until I can come up with a fix for the -lib flag.
Comment #2 by doob — 2016-06-08T15:12:47Z
There's some difference in the order the code is generate depending on if the -lib flag is passed or not. If the flag is passed, no __objc_imageinfo section is outputted.
Comment #3 by doob — 2016-06-13T08:11:37Z
Comment #4 by github-bugzilla — 2016-06-14T08:25:54Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/65b2b91ce8c6f90bdb8feb72fcd1c27e166cc471 Fix issue 16096 - compiling Objective-C code with -lib is broken When compiling Objective-C code as a library with DMD using the -lib switch. Then creating an executable using the library the linker outputs the following warning: Linking to static library: can't parse __DATA/__objc_imageinfo The resulting executable is broken due to no image info or selectors had been outputted in the binary. https://github.com/dlang/dmd/commit/4a7dbcddacd29fae424d9bf21cf33b68aca9610e Merge pull request #5862 from jacob-carlborg/issue_16096 Fix issue 16096 - compiling Objective-C code with -lib is broken
Comment #5 by github-bugzilla — 2016-10-01T11:47:39Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/65b2b91ce8c6f90bdb8feb72fcd1c27e166cc471 Fix issue 16096 - compiling Objective-C code with -lib is broken https://github.com/dlang/dmd/commit/4a7dbcddacd29fae424d9bf21cf33b68aca9610e Merge pull request #5862 from jacob-carlborg/issue_16096