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
Variables that start with '$' break generated assembly #46
Comments
The fix for this in GAS would be to surround the variable name w/ |
To clarify, e.g. this lea $(%rip), %rax needs to be this instead lea ($)(%rip), %rax |
Additional note: before the introduction of string literals this would not happen with |
Yeah, there's been a lot of sweeping changes since optimisations were touched last; I'd assume they are slowly falling out of proper behaviour. IIRC it's on the near horizon where that stuff will be worked on some more.
Can there be parentheses around every name? If so, this would be a very quick fix (just inserting parentheses in the format string) EDIT: relevant patch diff --git a/src/codegen/x86_64/arch_x86_64.c b/src/codegen/x86_64/arch_x86_64.c
index 5caaf6c..6ee6c4c 100644
--- a/src/codegen/x86_64/arch_x86_64.c
+++ b/src/codegen/x86_64/arch_x86_64.c
@@ -358,16 +358,16 @@ static void femit_mem_to_reg(CodegenContext *context, enum Instruction inst, Reg
static void femit_name_to_reg(CodegenContext *context, enum Instruction inst, RegisterDescriptor address_register, const char *name, RegisterDescriptor destination_register, enum RegSize size) {
const char *mnemonic = instruction_mnemonic(context, inst);
const char *address = register_name(address_register);
const char *destination = regname(destination_register, size);
switch (context->dialect) {
case CG_ASM_DIALECT_ATT:
- fprint(context->code, " %s %s(%%%s), %%%s\n",
+ fprint(context->code, " %s (%s)(%%%s), %%%s\n",
mnemonic, name, address, destination);
break;
case CG_ASM_DIALECT_INTEL:
fprint(context->code, " %s %s, [%s + %s]\n",
mnemonic, destination, address, name);
break;
default: ICE("ERROR: femit_name_to_reg(): Unsupported dialect %d", context->dialect);
}
} They are probably also needed in the intel syntax |
Probably |
I would double check that first since the intel syntax is substantially different to the point where parens might not be necessary. The problem is mostly w/ the AT&T syntax here because if it sees |
So ... I've checked and it's not good news. Intel uses |
Yeah, it does; I was only thinking about variables that start w/ |
True; there will definitely need to be some sort of lowering by each backend, I'd think. Or we just use the same mentality as functions and mangle them, requiring |
Addresses #46 in the AT&T syntax I'm not sure the solution in Intel syntax, but in GNU syntax this works rather well.
As of 95a8f2b the example given in the original bug has been fixed. However, there are still difficulties when using the |
The code example above produces no compiler errors/warnings and after codegen looks like this:
After running
gcc code.S
the following error is shown:The text was updated successfully, but these errors were encountered: