Open
Description
Bugzilla Link | 49681 |
Version | 11.0 |
OS | Windows NT |
CC | @triplef,@zygoloid |
Extended Description
Linking a file that references functions from the gnustep-2.0 runtime, but does not reference any Objective-C code, results in the following linker errors when using LLD:
lld-link: error: relocation against symbol in discarded section: __start_.objcrt$SEL
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __stop.objcrt$SEL
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __start_.objcrt$CLS
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __stop.objcrt$CLS
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __start_.objcrt$CLR
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __stop.objcrt$CLR
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __start_.objcrt$CAT
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __stop.objcrt$CAT
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __start_.objcrt$PCL
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __stop.objcrt$PCL
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __start_.objcrt$PCR
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __stop.objcrt$PCR
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __start_.objcrt$CAL
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __stop.objcrt$CAL
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __start_.objcrt$STR
>>> referenced by test-ffaa49.o:(.objc_init)
lld-link: error: relocation against symbol in discarded section: __stop.objcrt$STR
>>> referenced by test-ffaa49.o:(.objc_init)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Using link.exe only results in the following warnings:
libcmt.lib(exe_main.obj) : warning LNK4078: multiple '.CRT' sections found with different attributes (40400040)
libcmt.lib(initializers.obj) : warning LNK4254: section '.CRT' (C0000040) merged into '.rdata' (40000040) with different attributes
This can be reproduced e.g. as follows:
$ cat test.m
#include <objc/runtime.h>
int main(int argc, char *argv[]) {
objc_getClass("Test");
}
$ clang -fobjc-runtime=gnustep-2.0 -fuse-ld=lld -lobjc test.m
Adding any code that references Objective-C classes in the same file, e.g. [NSObject new]
, makes the linker errors disappear. Likewise using the gnustep-1.9 runtime does not expose this issue.
This is relevant when using Autoconf to check for the existence of runtime functions, as it will generate files like the above (minus the #include) to do so.