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

            Bug ID: 51475
           Summary: lld-macho unconditionally loads all contents of an
                    archive (unlike ld64)
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: MachO
          Assignee: unassignedb...@nondot.org
          Reporter: v...@google.com
                CC: g...@fb.com, jezr...@gmail.com,
                    llvm-bugs@lists.llvm.org, smee...@fb.com

NOTE: I don't think ld64 is being reasonable here but can anyone please
double-check for me in case I've missed something obvious? :)


Repro:

- Make the following files:

```

echo '#import <Foundation/Foundation.h> \n extern NSString *const
SuperImportantSymbol;' >  Constants.h && \
echo '#import "Constants.h" \n NSString *const SuperImportantSymbol =
@"SuperImportant";' > Constants.m && \
echo '#import <Foundation/Foundation.h> \n @interface FooUser  : NSObject \n +
(NSString *)fooMeth; \n@end' > FooUser.h && \
echo '#import "FooUser.h" \n #import "Constants.h" \n @implementation FooUser
\n +(NSString *)fooMeth { return SuperImportantSymbol; }\n @end' > FooUser.m 
&& \
echo '#import <Foundation/Foundation.h> \n @interface DYNFakeImpl : NSObject \n
+(NSString *)fakeMeth; \n @end' > DYNFakeImpl.h && \
echo '#import "DYNFakeImpl.h" \n NSString *const SuperImportantSymbol = @"FAKE
important"; \n @implementation DYNFakeImpl \n +(NSString *)fakeMeth { return
SuperImportantSymbol; } \n @end' > DYNFakeImpl.m

```

- Compile them

clang -c Constants.m && clang -c FooUser.m && clang -c DYNFakeImpl.m 


- Pack them into an archive

llvm-ar r libAll.a Constants.o FooUser.o DYNFakeImpl.o


- Link with l64:
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  -o ld64_out libAll.a


This happily produces ld64_out.
Repeat the link step, but with lld, it'd complain about duplicate symbol:

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  -o ld64_out Constants.o
FooUser.o DYNFakeImpl.o 
ld64.lld.darwinnew: error: duplicate symbol: _SuperImportantSymbol
>>> defined in Constants.o
>>> defined in DYNFakeImpl.o


It's worth noting that even with ld64, if you replace the archive with the
three .o files, then it'd also complain about duplicate symbols.

Is this something lld-macho wants to imitate?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to