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

    <tr>
        <th>Summary</th>
        <td>
            endbr64 removal
        </td>
    </tr>

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

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

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

<pre>
    When `-fcf-protection=branch` is given, the compiler conservatively emits an `endbr64` landing pad instruction at the beginning of each globally-visible function. This is because, even if the address of a function was not taken within the current compilation unit, it might be taken in another translation unit. That means the compiler has no choice other than to conservatively emit `endbr64` to allow indirect branches.

That conservative assumption resulted in having lots of unnecessary gadgets in the linked code.

mold has recently gained the `-z rewrite-endbr` option to rewrite unnecessary `endbr64` instructions with NOPs. It was doable because the linker can do a simple whole-program analysis to determine whether an address of a function is taken or not; a function's address is considered not taken if and only if the function is referred only by `R_X86_64_PLT32`.

Would you like to implement this same feature in lld? In particular, OpenBSD guys are interested in it to tighten security of their operating system.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VM1u20YQfprVZWCBImk5OvAQ1xAQoGiCNkB6M4a7Q3Lq5a6wMytDffpi10oiF-1FOnC-me-PRBGeA9Fg7h_N_dMGsy4xDSlzt-s3Y3SX4dtCAcy-uZvsdHdKUckqx2C6pzFhsIvZN8ACM58pmPYX0IXAxvXEnhLYGITSGZXP5C9AK6sA1n0U3Jj2fYF7DI7DDCd0wEE05XoCUOu2kWYOoQzECQjtArOPI3p_uTuz8OgJphwqZAtfF5bCZySLWagwojMF4KnuQucSiZRN-AMFrygQooLiCwV4ZV04vAnJKVHQqyCswzmwlrWssPK8KIx0BXIADFEXSqAJg9wACjFUWAmDvLdoqbfBLpEtwRW9YACN_2Xfv6zTCOh9fAUOjhNZhbdUSLameTLNx7ffevx2G6BIXk-VXyLJXql4Dwuei9E-avUoh0CWRDBdYEY3kwpcrfEcXsiBjY7enVqjd1VUIktBfQFyIFdBpUd_Q6LXxEp3VUdREd-IaPz-6N3h94pvCiI1Kvjt8xfZwietMbqIpRDX-H8yTWAxgIuAILyePMHrEj2VRs8JV8CA_iIshYQjpbRyKDNUA8HwP80pgJp9TKVBpnu8eWraB_mBY6kBsKNE7qZtPAEGBzH4y_eS3m5PNFEqiDowVjd-f_7zw_553z9_-fVr15p98y6AbzF7B5eYwfMLFT1V71p6rOXtEFwJJkLNiUqa3jvTHeFTgBMmZZs9plLwzycKj388wZwvAlhnlRLJtSqsZbeWV4ACCNmcWC_FH12IE8QTJdTSJrmI0rrduKFzh-6AGxp2D83uod_tmn6zDM2-tTgdOmxG27R06O7dhwkRx8a1zWg_bHhom7bbtc19s7vf9f32gAfc7Sc72sl1OyLTN7Qi-63353Ub07xhkUzDQ983zcbjSF7qN65ti9q2LR-7NJTpuzHPYvrGs6j8xCurp-HaO0i0xjP6TU5-WFRPYrqPpj2a9jizLnnc2ria9ljQ179SrL_IqmmPlYqY9ljZ_BMAAP__5V_lvg">