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

    <tr>
        <th>Summary</th>
        <td>
            llvm-mt/lld creates binaries that doesn't work given a certain input manifest
        </td>
    </tr>

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

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

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

<pre>
    Create this manifest:
```XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <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>
  </application>
</assembly>
```

Run: `lld-link.exe /out:test.exe test.obj /manifest:embed /manifestinput:test.manifest`

Binary doesn't start with: `The application has failed to start because its side-by-side configuration is incorrect` if we look in the event viewer it complains that the attribute `level` on `requestedExecutionLevel` is missing.

Disable libxml2 in lld and it will work. This points to the internal WindowsManifestMerger code.

I then extracted the manifests from the binaries with mt and here is the one created with our internal code:

```XML
<ms_asmv1:requestedExecutionLevel ms_asmv1:level="asInvoker" ms_asmv1:uiAccess="false"></ms_asmv1:requestedExecutionLevel>
```

here is the one embedded with mt.exe:

```XML
<ms_asmv1:requestedExecutionLevel xmlns:ms_asmv1="urn:schemas-microsoft-com:asm.v1" level="asInvoker" uiAccess="false"></ms_asmv1:requestedExecutionLevel>
```

I then tried to manually edit the manifest and remove the `ms_asmv1:` prefix to `level` and `uiAccess` and then embed that with mt.exe and it worked.

Next I digged up this code in llvm:

https://github.com/llvm/llvm-project/blob/main/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp#L557

This code finds the nearest namespace and copies it to all the attributes and claims that mt.exe does the same. Disabling this code makes the binary work again, but I am likely missing some nuance here.

This code was written by Eric Beckman but he doesn't seem active anymore. Happy to fix it if someone that knows what the right xml should be without my just ripping out code.

As an aside - llvm-mt/WindowsManifestMerger also seems totally untested. Maybe this code shouldn't be active if it's untested?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVsFu4zYQ_Rr7QliQpThODj44mwQNsCkW3WzbW0FJI5mxRKokZcV_30dStuVk00WAAIHkDIczb4bzHpWpYr_6oolbYnYjDGu4FCUZO0nXk_h2Eq8nl3H4-_vx62BJv0zS-5emZjvSRig5SW8nSTKPYjwZyVwVQlbB-OPpfnblzMZyWfBaSQoLezJ4Is4kvTuG5cZQk9V7huDSBMdOI_7a5BtquJk1ItfKqNLOctXAzk0T7eYuwQH4n28xHVMwhiRWd8Y-yFJ9MEt6HsnHMpR3Wtj9md2vaPq3AxoqvmmxEzVVqPfc6dzt7gWhLIB_pR3VrHbPAI2bB7lTW9Kuyk6s85zMgLrktSEHK7l_iwDGX4EIXj8pIiwcO3W-wtu2Fjl3YD-hhb2QherNd7IWU2MOEde9SULcjbWtm0bUCKwhfHQMH7nwyf33xwc8k3h-iddf5yFfJz0kdgnWmMjqG7ebdc81RvMONVOo_ufrr5v3Cv6bHo6aNZ50tzIM-8l8YNrwr3_-0bmuMljrupjVQm4jeiGG_apzJLU4X2_xP1T27JZGJEYKKsY2IdvTxqPjedIbIbnes0KRkZNkaR17tWW9sJsBzNOG2HgONtywkmPECmbV4J5RzjtDTFjDjCholu1n7s1yJUtRdTpshegIaIbWlDscTJSsJ1YrtYUdokQMXJCW7QT1pBEN-5u25kIarHLrXbi1WmQdVMx1ypMHoRAdr3c45nNB8IQxOLloXP-tMDyrAUJkGMfE4UD3GRTMpe9FXbNe6W3EnpxktkpIlIi6HRL8Ji15zYYpf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