[llvm-bugs] [Bug 51475] New: lld-macho unconditionally loads all contents of an archive (unlike ld64)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 13 21:55:38 PDT 2021


            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: unassignedbugs at nondot.org
          Reporter: vyng at google.com
                CC: gkm at fb.com, jezreel at gmail.com,
                    llvm-bugs at lists.llvm.org, smeenai at 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? :)


- 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 at 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
 -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
 -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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210814/3f395d95/attachment.html>

More information about the llvm-bugs mailing list