<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/144669>144669</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [LLD] unable to link a uncalled constructor function in static lib
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Eternalni
      </td>
    </tr>
</table>

<pre>
    
#include <iostream>

extern "C" {

__attribute__((constructor(101), used, retain, section(".llvm.keep,.init.250"), noinline, visibility("hidden"))) static void
_init_cpu_features() {
    __builtin_cpu_init();
    std::cout << "?" << std::endl;
};
}

build this function to a static lib _initd.lib, link it by cmake: "set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_CURRENT_LIST_DIR}/libs -l_initd.lib ")"
 howevery,  "?" not printed, and __builtin_cpu_supports always return false in main.cpp
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsU8uO4zYQ_BrqQowgtSTLOujg8SMYrLMH7wbITSCptt0ZmhT48MZ_H1Aex0YQQIAIsoqsrq4W3tPJIPaseWfNJhMxnK3rtwGdEdpQJu1461mxYlCRUTqOyFm1JuuDQ3Fh1TadFSv8OzE4A1gzAM7a9_v-MIgQHMkYcBgYLBkslTU-uKiCdQyWZVEy6BisefQ4pr_DIMiklUcVyJqZBrnW10v-iTgxWOdkKOTQFAzgi24sGU0G0_pKniRpCrc790zjiOaBTR_3QQRS_GppTDLTfYOa4nBEEaJDPxO7r0I453wYZCQdyMywhL9DWPVA-DCyasWqlbIxJJdYtU6OsGo3e3Lf-BeFZtR3Mms3z8VsW3pq5OFMnh-jmV3gwXLxkK1J8lnDmGuSqWRN5pNT4PLG1UV8IqtW6W2PSeb699W37bD9czvsP75_2x6G3X71249ZG9Ssff__c9Zu-Nv-FbH-43DYfv857D9-_Bw2H4ekF3aapOdv-qmHP5yG5MzZ_sIrultS-WKHsYFPjky4d12Y8T8W-zhN1gXPhf4lbj7lIjrDj0J75GT4RZDJ1TRlY1-NXdWJDPuybQqoy2VdZ-e-axEVLroGqkaB7FS3KKRcSFh0dSOXbUY9FNAUizKlsIU6ByzLetmqpqyP1VIgqwu8CNL37Fl3ysj7iH1Z14tFl2khUft5dAC0HlNxzSZzfYK_yXjyrC40-eCfFwQKep62_X7Dmg2PRkiNqblzBwWPRgmtceQvc_IMAZmXCGTR6f4cwuRTomDHYHeicI4yV_aSGqOvj9_b5OxfqAKD3VyCZ7D7quLawz8BAAD__wgXPBQ">