<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 - [RISC-V] ELF flags discarded when using "ld -b binary""
   href="https://bugs.llvm.org/show_bug.cgi?id=52148">52148</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[RISC-V] ELF flags discarded when using "ld -b binary"
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>dc@m-labs.hk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Overview/TLDR: The RISC-V version of
<a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - [LLD][MIPS][FreeBSD] ld -b binary outputs objects with no ABI flags"
   href="show_bug.cgi?id=43368">https://bugs.llvm.org/show_bug.cgi?id=43368</a>. Background/Usage: Same as the one
described in <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - [LLD][MIPS][FreeBSD] ld -b binary outputs objects with no ABI flags"
   href="show_bug.cgi?id=43368">https://bugs.llvm.org/show_bug.cgi?id=43368</a>. A kernel binary file
is needed to be glued onto a runtime binary, so we can use the generated
_binary_* symbols to move the kernel binary into a pre-specified memory
location.

Reproduce steps:
Practically the same as <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - [LLD][MIPS][FreeBSD] ld -b binary outputs objects with no ABI flags"
   href="show_bug.cgi?id=43368">https://bugs.llvm.org/show_bug.cgi?id=43368</a>, but
several RISC-V specific options are needed to compile the binaries.
e.g. -mabi=ilp32d to specify the usage of RISC-V double precision ABI

1. Compile a binary using RISCV32 target and ILP32D ABI.
e.g. clang -target riscv32-unknown-none-elf -march=rv32g -mabi=ilp32d main.c
-nostdlib -o main.o

When examined using llvm-readelf, the value of "Flags" would be 0x4
(double-float-ABI). 

2. Start off with a binary. Link the binary using -b binary.
e.g. ld.lld -r -m elf32lriscv -b binary main.o -o main

When examined using llvm-readelf, the value of "Flags" would become 0x0.

When linking it with another archive built using ILP32D ABI. LLD will then
complain about linking object with different floating-point ABI.
e.g. ld.lld: error:
cargo/riscv32g-unknown-none-elf/debug/libruntime.a(vectors.o): cannot link
object files with different floating-point ABI

The cause of this issue is probably the following patch.
<a href="https://reviews.llvm.org/D71101">https://reviews.llvm.org/D71101</a>

While it prevented an assertion error, the flag is always set to 0, which cause
the bug described above.
Unlike the same issue in MIPS, it seems that the ABI cannot be inferred from
emulation directly.
Discussion on adding ABI specific emulations for RISC-V targets:
<a href="https://reviews.llvm.org/D95755">https://reviews.llvm.org/D95755</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>