<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 - [AARCH64] "expected assembly-time absolute expression""
   href="https://bugs.llvm.org/show_bug.cgi?id=46679">46679</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[AARCH64] "expected assembly-time absolute expression"
          </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>All
          </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>Backend: AArch64
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>From <a href="https://github.com/ClangBuiltLinux/linux/issues/1078">https://github.com/ClangBuiltLinux/linux/issues/1078</a>, IAS fails to
assemble the following code with Clang's integrated assembler for ARM64. The
reproducer was originally reported at
<a href="https://github.com/ClangBuiltLinux/linux/issues/1078#issuecomment-656245060">https://github.com/ClangBuiltLinux/linux/issues/1078#issuecomment-656245060</a>.
Here is a slightly changed reproducer

$ cat test.c
void a(void)

        asm(
        ".arch_extension lse            \n"
        "1:                             \n"
        "nop                            \n"
        "2:                             \n"
        ".subsection 1                  \n"
        "3:                             \n"
        "nop                            \n"
        "4:                             \n"
        ".previous                      \n"
        ".org . - (4b-3b) + (2b-1b)     \n"
        );
}
/* identical to a() */
void b(void)
{
        asm(
        "5:                             \n"
        "nop                            \n"
        "6:                             \n"
        ".subsection 1                  \n"
        "7:                             \n"
        "nop                            \n"
        "8:                             \n"
        ".previous                      \n"
        ".org . - (4b-3b) + (2b-1b)     \n"
        );
}
$ clang --target=aarch64-linux-gnu -c test.c
test.c:28:10: error: expected assembly-time absolute expression
        ".org . - (8b-7b) + (6b-5b)     \n"
         ^
<inline asm>:9:6: note: instantiated into assembly here
.org . - (8b-7b) + (6b-5b)     
     ^
1 error generated.


I did some digging on this issue. So while parsing
(AArch64AsmParser::parseDirectiveArchExtension) .arch_extension, IAS created a
new MCSubtargetInfo object and replaced the one associated with the assembly
parser. Later, however, when creating machine functions
(MachineModuleInfo::getOrCreateMachineFunction), the old one was used. So when
parsing the nop between label 7 and 8, while deciding if it can place the
instruction into the current fragment, IAS finds out the difference on the
MCSubtargetInfo object of the fragment (from the new object associated with the
parser) and the one from the machine function b, therefore creating
(MCObjectStreamer::getOrCreateDataFragment) a new data fragment and causing 7
and 8 be placed into two different fragments. Since IAS can only resolve
(AttemptToFoldSymbolOffsetDifference) differences of labels belong to the same
fragment, it failed to assemble the above code. 


Also if I separate the compilation and assembling process as in
<a href="https://github.com/ClangBuiltLinux/linux/issues/1078#issuecomment-656385059">https://github.com/ClangBuiltLinux/linux/issues/1078#issuecomment-656385059</a>,
the same example assembled successfully.</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>