llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AARCH64] "expected assembly-time absolute expression"

Open jcai19 opened this issue 6 years ago • 1 comments

Bugzilla Link 46679
Resolution FIXED
Resolved on Dec 17, 2020 17:02
Version trunk
OS All
Blocks llvm/llvm-project#4440
CC @Arnaud-de-Grandmaison-ARM,@kbeyls,@lalozano,@m-gupta,@nickdesaulniers,@samitolvanen,@smithp35

Extended Description

From https://github.com/ClangBuiltLinux/linux/issues/1078, IAS fails to assemble the following code with Clang's integrated assembler for ARM64. The reproducer was originally reported at https://github.com/ClangBuiltLinux/linux/issues/1078#issuecomment-656245060. 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" ^ :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 https://github.com/ClangBuiltLinux/linux/issues/1078#issuecomment-656385059, the same example assembled successfully.

jcai19 avatar Jul 11 '20 01:07 jcai19

Fixed in https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/commit/?id=966a0acce2fc and https://reviews.llvm.org/rG415a4fbea7c1a39c780caa3cb7287fe09c5267d2.

jcai19 avatar Dec 18 '20 01:12 jcai19