<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 - Inline assembler might need better errors for section mismatches"
   href="https://bugs.llvm.org/show_bug.cgi?id=38271">38271</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inline assembler might need better errors for section mismatches
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>MC
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>CFSworks@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20587" name="attach_20587" title=""Compile test" file from a project, which cannot be compiled with clang -flto or clang -ffunction-sections">attachment 20587</a> <a href="attachment.cgi?id=20587&action=edit" title=""Compile test" file from a project, which cannot be compiled with clang -flto or clang -ffunction-sections">[details]</a></span>
"Compile test" file from a project, which cannot be compiled with clang -flto
or clang -ffunction-sections

I just spent way too much time digging into something that turned out to be
pretty simple:

I was compiling a small C program with inline assembly. The inline assembly
switches to the data section (with '.data'), defines some data, then switches
back (with '.text'). It was compiling fine with Clang, except when enabling
-flto. This is because the LLVMgold plugin now enables -function-sections by
default, and so the inline assembly is supposed to switch back to '.text.main'
instead of '.text', which was switching to a different section altogether, and
so the size of the 'main' function couldn't be calculated.

The above isn't LLVM's fault; nothing LLVM can really do about user mistakes
like that.

However, LLVM's error message in response to this situation was:
<unknown>:0: error: Cannot represent a difference across sections
LLVM ERROR: Size expression must be absolute.

This really did not help me understand that:
a) LLVMgold was turning on -function-sections in the code generator in secret,
which was why it only broke with LTO and not otherwise.
b) The inline assembly wasn't switching back to the correct section: .text was
the wrong thing to use.
c) The "difference" it was complaining about wasn't even the one that appeared
in the inline assembly, but rather the size computation added by LLVM itself.

For comparison, this is how GCC reacts under the same circumstances:
/tmp/cc9bEh8L.s: Assembler messages:
/tmp/cc9bEh8L.s:21: Error: CFI instruction used without previous .cfi_startproc
/tmp/cc9bEh8L.s:23: Error: .cfi_endproc without corresponding .cfi_startproc
/tmp/cc9bEh8L.s: Error: open CFI at the end of file; missing .cfi_endproc
directive
/tmp/cc9bEh8L.s: Error: .size expression for main does not evaluate to a
constant

This is a _little_ bit better, and is more likely to prompt a user to look at
the assembler output - at the very least, it points the user in the direction
of investigating the input, rather than the compiler. ;)

I felt this should be an issue, because the error messages probably are more
vague than intended, and because this bug does cause a fatal error under Clang
when using -ffunction-sections.</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>