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

    <tr>
        <th>Summary</th>
        <td>
            [LLD] Evaluation of DEFINED linker script directive produces wrong output
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld,
            lld:ELF
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          edward-jones
      </td>
    </tr>
</table>

<pre>
    The following linker script causes unexpected behaviour when `APPLE` is not defined by any input objects. The unexpected output is that `APPLE` will resolve to '1' instead of '2'.

```
APPLE = DEFINED (APPLE) ? 1 : 2;
```

It appears that when the symbol is first processed it is added to the symbol table with the expected value, however LLD reevaluates symbol assignments, and during these subsequent evaluations of the expression the `DEFINED` now returns 1 as `APPLE` has been inserted in the symbol table.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU91uozwQfRpzM2oEJnHCBRdpCVKl6FMvvhcweAjuOjbrscPm7VcmtNtqV0IGxvN3zpmRRPpiEWu2e2a7JpMxjM7XqGbp1dO7s0hZ59S9_n9EGJwxbtb2AkbbH-iBeq-nAL2MhATR4q8J-4AKOhzlTbvoYR7RAhP58e3tfGIiB01gXQCFg7bJ8w7S3kHbKQZw3Tv2gTaQqn1J52JI15ogjDJ8SzdrY8AjOXNDCA4Y3xeM70FbCigVuCGZOOP7Dcsblh_XU-Trs_wu6YCVDTSn9vW_UwOMHx41eAWsbKEAVh6Bs_L5nwke52sAOU0o_droAj6MCHS_ds4kAIP2FGDyrkciVKAXWFIpVKn9L85BdgZh1mFcrJ9k3KSJyPgLjG7GG3o4nxvwiMkuA9JH_EPaK9pAyVtaBSr6pF4YkRAodoQ_I9oAa6x2lhJhazmPRNo9ADCRr8wk0q2bwWOI3hIUIOmbIqMk6BBtkgB96ljbv3BtMlWXqiormWFdiKoQh4IfRDbW21LtUVRDVfJelELIAQtVFvtDrmSlxJDpmue8zA9FXuz4IRebLXZKKL4fimG7k5Vk2xyvUpuNMbfrxvlLpoki1mIr8jwzskNDy7xzboxinDP-sn6Xx9O5TZZdk_k6xT918UJsmxtNgf5kDDqYZWnO54btGjh9MpgI_Bii72uitMc-6Bsm-VXskWD2zl7W8c6iN_UYwkSsPDLeMt5edBhjt-ndlfE21V5fT5N3aVMYbxdoxHi7oPsdAAD__0nwPEQ">