<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - lld-macho unconditionally loads all contents of an archive (unlike ld64)"
   href="https://bugs.llvm.org/show_bug.cgi?id=51475">51475</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lld-macho unconditionally loads all contents of an archive (unlike ld64)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>MachO
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vyng@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>gkm@fb.com, jezreel@gmail.com, llvm-bugs@lists.llvm.org, smeenai@fb.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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
<span class="quote">>>> defined in Constants.o
>>> defined in DYNFakeImpl.o</span >


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?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>