Fixing asm: Internal error: unbalanced parenthesis in operand 1

I got this error the other day when I was trying to compile the exploit code for the mremap exploit on Linux. While I have programmed a lot I have not spent an inordinate amount of time with gcc and this was something of a pain to solve so I thought I would share a general solution.

1.) Begin by getting a dump of the assembly code. You can do this with gcc -S -o <name_of_output> <name_of_input>

2.) Go to the line the compiler told you there was an issue with. Now you can see what the problem is. In my case it was that the assembler came up with: movl $((17 which obviously has missing parenthesis.

3.) You can either directly modify the assembly, or trace it back to the root file. In my case, it was inline assembly and doing a search on the corresponding function name led me to the offending line: ” movl $(“xstr(CLONEFL)”), %%ebx \n”. It was a macro, which looked fine. However you can view preprocessor output with the -E option. Examining the preprocessor output led me to the line: ”               movl $(“”(17|0x00004000|0x00000100)””), %%ebx           \n”. I’m not sure why that doesn’t work, but I simply changed it to ”               movl $0x4111, %%ebx                     \n” and it worked.

Hope this saves someone some time. Feel free to comment if you have more specific questions.

2 thoughts on “Fixing asm: Internal error: unbalanced parenthesis in operand 1

  1. Reply

    Anonymous

    This helped me enormously! Thank you!

  2. Reply

    Anonymous

    Thanks for the post. Where did you get the “$0x4111” value from?

Leave a Reply