<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - `-mattr` should be encoded in the IR for LTO's sake"
   href="https://bugs.llvm.org/show_bug.cgi?id=51161">51161</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>`-mattr` should be encoded in the IR for LTO's sake
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>twd2.me@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25046" name="attach_25046" title="The diagnostic information.">attachment 25046</a> <a href="attachment.cgi?id=25046&action=edit" title="The diagnostic information.">[details]</a></span>
The diagnostic information.

When compiling the following code with LTO:

```
$ cat test.c
void _start()
{
    asm volatile (
        ".balign 4\n\t"
        "c.nop\n\t"
        ".balign 4\n\t"
        "c.nop"
    );
}

$ clang -march=rv64imac -O2 -flto -mno-relax -c test.c
$ ld.lld test.o
```

lld fails with `unable to write nop sequence of 2 bytes`.
The diagnostic information is attached.

It looks like to be due to the `HasStdExtC` check failure in
`RISCVAsmBackend::writeNopData`.
And, if I use `ld.lld -mllvm -mattr=+c test.o`, lld can generate proper machine
code.
According to Nick Desaulniers [1], `-mattr` should be encoded in the IR for
LTO's sake.

My LLVM version: commit 1b61d837b9d0 ("[Inline] Add test for PR50589 (NFC)")
[1]
<a href="https://lore.kernel.org/linux-riscv/CAKwvOdmNji0AbYUiOSfb5cLD+g7YCpXk4oDupa8gTfgzYmxvBg@mail.gmail.com/">https://lore.kernel.org/linux-riscv/CAKwvOdmNji0AbYUiOSfb5cLD+g7YCpXk4oDupa8gTfgzYmxvBg@mail.gmail.com/</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>