Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrecognized opcodes in module level assembly #355

Open
mlund opened this issue Sep 20, 2023 · 5 comments
Open

Unrecognized opcodes in module level assembly #355

mlund opened this issue Sep 20, 2023 · 5 comments
Labels
bug Something isn't working p2

Comments

@mlund
Copy link
Contributor

mlund commented Sep 20, 2023

Using non-6502 in module level assembler code I get the following compilation error. Inline and stand-alone assembly is OK.

error: instruction requires a CPU feature not currently enabled
  ldz #0

when using e.g. mos-mega65-clang++ -mcpu=mos45gs02 asm.cc and the snippet shown below.

// asm.cc
asm (
 ".text\n"
 ".global func\n"
 "func:\n"
 "ldz #0\n" // not ok
 "rts"
);
void func();

int main() {
  asm volatile ("ldz #0"); // ok
}
@mlund mlund changed the title Unrecognized opcodes in module level assemble Unrecognized opcodes in module level assembly Sep 20, 2023
@mlund
Copy link
Contributor Author

mlund commented Sep 20, 2023

This does seem to compile in Compiler Explorer. Not sure if this is related to my setup (git checkout on 15/9).

@mysterymath mysterymath added the p1 label Sep 20, 2023
@asiekierka asiekierka mentioned this issue Sep 23, 2023
2 tasks
@mysterymath mysterymath added the bug Something isn't working label Sep 24, 2023
@mysterymath
Copy link
Member

mysterymath commented Sep 28, 2023

Did a little digging on this, it looks like this may actually be a LTO bug upstream. They're not instantiating the target CPU when scanning the inline assembly for symbols before LTO occurs (it's the first "").

https://github.com/llvm/llvm-project/blob/eb38edc82850c34bbbda7f7ce2235ec882b7d398/llvm/lib/Object/ModuleSymbolTable.cpp#L91

I'll start looking for an existing issue; if I can't find one, I'll try to make a X86 reproducer and file it upstream.

@mysterymath
Copy link
Member

Filed llvm/llvm-project#67698 for this upstream.

@mysterymath
Copy link
Member

So, I did some digging into this upstream, and it looks like this error is partially spurious; the error is emitted, but the compile and link actually does eventually succeed. The only actual effects of this bug, other than the error message, is that module-level inline assembly is no longer scanned for symbol references to feed into the LTO symbol resolution table. This is already the situation for regular inline assembly, so it isn't a tremendous loss.

It's in a bit of a sticky situation upstream; a lot of code tends to assume that you can scan module-level inline assembly for symbols without knowing the CPU and feature set, and there are tools that operate on bitcode that couldn't possibly have that information, too.

@mysterymath
Copy link
Member

Taking this down to p2; it doesn't look like it's likely to be hard blocker on anything, just surprising and annoying, and it's architecturally quite difficult to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2
Projects
None yet
Development

No branches or pull requests

2 participants