<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 mis-links lld, crashes in _tlv_bootstrap"
   href="https://bugs.llvm.org/show_bug.cgi?id=50282">50282</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lld mis-links lld, crashes in _tlv_bootstrap
          </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>nicolasweber@gmx.de
          </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>While debugging <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Regression(d5a70db1938c063): LLVM's ProfileDataTests crashes when linked with lld/mac"
   href="show_bug.cgi?id=50274">bug 50274</a> I ran into an issue where lld crashes on startup when
linked with lld.

% git diff
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index d33c3d50fbbc..05e87b81f7ef 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -580,6 +580,7 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section>
sectionHeaders,
       return nList[lhs].n_value < nList[rhs].n_value;
     });
     uint64_t sectionAddr = sectionHeaders[i].addr;
+    uint64_t sectionAlign = sectionHeaders[i].align;

     // We populate subsecMap by repeatedly splitting the last (highest
address)
     // subsection.
@@ -604,6 +605,11 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section>
sectionHeaders,
       //   3. Alternative entry points do not induce new subsections.
       if (!subsectionsViaSymbols || symbolOffset == 0 ||
           sym.n_desc & N_ALT_ENTRY) {
+
+if (name ==
"l___const._ZN12_GLOBAL__N_116addValueProfDataERN4llvm15InstrProfRecordE.VD0")
{
+fprintf(stderr, "reuse\n");
+}
+
         symbols[symIndex] =
             createDefined(sym, name, isec, symbolOffset, symbolSize);
         continue;
@@ -622,7 +628,10 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section>
sectionHeaders,
       // TODO: ld64 appears to preserve the original alignment as well as each
       // subsection's offset from the last aligned address. We should consider
       // emulating that behavior.
-      nextIsec->align = MinAlign(isec->align, sym.n_value);
+      nextIsec->align = MinAlign(sectionAlign, sym.n_value);
+if (name ==
"l___const._ZN12_GLOBAL__N_116addValueProfDataERN4llvm15InstrProfRecordE.VD0")
{
+fprintf(stderr, "new, %u\n", nextIsec->align);
+}
       subsecMap.push_back({sym.n_value - sectionAddr, nextIsec});
       subsecEntry = subsecMap.back();
     }


Repro file:

<a href="https://drive.google.com/file/d/1xbr2NY2SJbKrT9n1XwMyoLy-M_X2GA-p/view?usp=sharing">https://drive.google.com/file/d/1xbr2NY2SJbKrT9n1XwMyoLy-M_X2GA-p/view?usp=sharing</a>


thakis@MBP repro_lld %
~/src/chrome/src/third_party/llvm-build/Release+Asserts/bin/ld64.lld
@response.txt
thakis@MBP repro_lld % ./lld
zsh: abort      ./lld
thakis@MBP repro_lld % lldb ./lld
(lldb) target create "./lld"
Current executable set to '/Users/thakis/src/llvm-project/out/gn/repro_lld/lld'
(x86_64).
(lldb) r
Process 39549 launched: '/Users/thakis/src/llvm-project/out/gn/repro_lld/lld'
(x86_64)
Process 39549 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff715c933a libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff715c933a <+10>: jae    0x7fff715c9344            ; <+20>
    0x7fff715c933c <+12>: movq   %rax, %rdi
    0x7fff715c933f <+15>: jmp    0x7fff715c3629            ; cerror_nocancel
    0x7fff715c9344 <+20>: retq
Target 0: (lld) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff715c933a libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff71685e60 libsystem_pthread.dylib`pthread_kill + 430
    frame #2: 0x00007fff71550808 libsystem_c.dylib`abort + 120
    frame #3: 0x00007fff71483c33 libdyld.dylib`_tlv_bootstrap + 9
    frame #4: 0x00000001003b3904 lld`::PrettyStackTraceEntry() [inlined]
printForSigInfoIfNeeded at PrettyStackTrace.cpp:195:7 [opt]
    frame #5: 0x00000001003b38f4 lld`::PrettyStackTraceEntry() at
PrettyStackTrace.cpp:217 [opt]
    frame #6: 0x00000001003abc48 lld`::InitLLVM() [inlined]
PrettyStackTraceProgram at PrettyStackTrace.h:95:5 [opt]
    frame #7: 0x00000001003abc40 lld`::InitLLVM() [inlined]
PrettyStackTraceProgram at PrettyStackTrace.h:96 [opt]
    frame #8: 0x00000001003abc40 lld`::InitLLVM() [inlined] emplace<int &,
const char **&> at Optional.h:113 [opt]
    frame #9: 0x00000001003abc22 lld`::InitLLVM() [inlined] emplace<int &,
const char **&> at Optional.h:263 [opt]
    frame #10: 0x00000001003abc22 lld`::InitLLVM() at InitLLVM.cpp:35 [opt]
    frame #11: 0x0000000100000c8e lld`main at lld.cpp:201:12 [opt]
    frame #12: 0x00007fff71481cc9 libdyld.dylib`start + 1
    frame #13: 0x00007fff71481cc9 libdyld.dylib`start + 1



Works fine without that local diff. Not sure if this is a regression or not.
(Maybe it's a dupe of <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Regression(d5a70db1938c063): LLVM's ProfileDataTests crashes when linked with lld/mac"
   href="show_bug.cgi?id=50274">bug 50274</a> in the end.)</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>