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

    <tr>
        <th>Summary</th>
        <td>
            lld-link produce broken binaries if /manifestinput:xxx argument is repeated
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    With this `app.manifest`:

```xml
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
        <ws2:longPathAware>true</ws2:longPathAware>
    </windowsSettings>
</application>
</assembly>
```

With a simple hello world program `manifest_test.cpp`:

```c++
#include <cstdio>
int main() {
    puts("Hello world");
}
```

Build:

```
clang++ -target x86_64-pc-windows-msvc manifest_test.cpp -c -o manifest_test.obj
lld-link -defaultlib:libcmt /OUT:manifest_test.exe /manifest:embed /manifestinput:app.manifest /manifestinput:app.manifest /SUBSYSTEM:CONSOLE /MACHINE:X64 manifest_test.obj
```

If you try to run the output binary, you will get this error: "The application has failed to start because its side-by-side configuration is incorrect"

Extracting the manifest from the binary using resource hacker gives this:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo>
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
      <ws2:longPathAware>true</ws2:longPathAware>
    </windowsSettings>
    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
      <ws2:longPathAware>true</ws2:longPathAware>
    </windowsSettings>
  </application>
</assembly>
```

The `<windowsSettings>` element is duplicated, which I presume is what making Windows unhappy.

Try the same using link.exe instead of lld-link, and the resulting embedded manifest does not have this duplicated element:

```xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"><trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"><security><requestedPrivileges><requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel></requestedPrivileges></security></trustInfo><application xmlns="urn:schemas-microsoft-com:asm.v3"><windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"><ws2:longPathAware>true</ws2:longPathAware></windowsSettings></application></assembly>
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVktv2zgQ_jXyhZBhS_IjBx-cxEYNNE0BJ9vdU0GRI4sNRXr58OPf71CyHdtx0m2R9lDDkKAZ8pvhPL5hrvl29EW4krhSWBL1O3S5bFdUiQKsw88oHUed26izf6Kk_m8quZOkN1E6xU-yAmOFVlF6GyVJt93BJwHFNBdq0Qi9K-IhvnFDlE4O-6m1UOVyS_Z2_7qAhBaU3cEYVI0tK6GiNq4EM9rqwsVMVyintmqvurWVIxPLpRSMOkT9QaT0GIngD9HWQnG9tnNwDs9m94jjtU0a3NK5ZYhcMsX_Dr59gG8H-GQ6v5vhM-l0-_j6cgp5bnRvOBgYS60Wn6krx2tqAJc54yGkIZle1p_4Hlad2TqKE2qPQnWu2eXpWbyvhuMSqauJEiuqpQRSgpSarLWRnCyNXhhahSrbZ_qrw0ebLZdvlBqLkuvwb6RJKhSTnkM4DLOOC33wRyiHNSRUlGCVXZFocP189KV3tpYnH55dCmFOrqJ0Dz64feNg117gjlecbD6ZpFjrtbskdtQswJHNsP-1n8VLFu_iHld2xciLCJCYkVifyXX-rUGWksdSqCcScyiol06KPKRa5K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