[llvm-bugs] [Bug 51475] lld-macho doesn't force-load ObjC archive members before resolving their symbols

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 31 18:01:09 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51475

Vy Nguyen <vyng at google.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #15 from Vy Nguyen <vyng at google.com> ---
Repro case:
// Foo.h
#import <Foundation/Foundation.h>

@interface Foo : NSObject
@end
// Foo.m
#import "Foo.h"

@implementation Foo {
  NSString* _privateDupSym;
}
- (void)prepareForReuse {
  _privateDupSym = nil;
}
@end

Put both files in a directory called "one".
Copy the dir to "two".

clang -c -ObjC one/Foo.m -o one/Foo.o
clang -c -ObjC two/Foo.m -o two/Foo.o

llvm-ar r libDup.a one/Foo.o two/Foo.o

LD64 allows linking this.
ld  -demangle -dynamic -bundle   -arch "x86_64" -platform_version macos 10.15
11.0   -syslibroot
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
 -ObjC -lc++ -lobjc -lSystem  -framework Foundation  libDup.a


LLD doesn't:
$ ../bin/ld64.lld.darwinnew   -demangle -dynamic -bundle   -arch "x86_64"
-platform_version macos 10.15 11.0   -syslibroot
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
 -ObjC -lc++ -lobjc -lSystem  -framework Foundation  libDup.a 
ld64.lld.darwinnew: warning: libDup.a(Foo.o) has version 11.0.0, which is newer
than target minimum of 10.15
ld64.lld.darwinnew: warning: libDup.a(Foo.o) has version 11.0.0, which is newer
than target minimum of 10.15
ld64.lld.darwinnew: error: duplicate symbol: _OBJC_METACLASS_$_Foo
>>> defined in libDup.a(Foo.o)
>>> defined in libDup.a(Foo.o)

ld64.lld.darwinnew: error: duplicate symbol: _OBJC_CLASS_$_Foo
>>> defined in libDup.a(Foo.o)
>>> defined in libDup.a(Foo.o)


-------------------------------------------
However, it seems this is a bug in LD64. It keeps a map symbol=>ar member, and
it *iterates* that for -ObjC. (So it discards duplicates symbols).
(Also if you put -force_load or -all_load the archive, then it'd also complain
about the duplicate symbols).

We probably don't want LLD to do this.
I'll re-close this bug - sorry!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210901/943814fc/attachment-0001.html>


More information about the llvm-bugs mailing list