Skip to contentSkip to conversation

GAS/GCC Assembler Code Modification

DISCUSSION Martin 3 participants 6 messages May 15, 2004

lore
Share & tools
lore

Martin

author
#0 lore raw

Hi folks,

I have a question regarding GAS and GCC.
Does the GAS modify the Assembler Code? If I try to assemble (for example) the following line:

popl %esi

the gas changes that to

pop %esi

Ok I guess this is ok, because the ESI Register is 'only' 32 Bit. So movw (= mov) would be ok.

Next example:

If I try to assemble

movl $0xb,%eax

the gas changes that to

mov $0xb,%eax

How can I tell gas that I dont want him to optimize the code?

Best regards,
Martin

PS: Sry for my poor english.

#1 lore raw
Quoted 8 lines · Martin

popl %esi the gas changes that to
pop %esi Ok I guess this is ok, because the ESI Register is 'only' 32 Bit. So movw (= mov) would be ok.

Next example:

If I try to assemble
movl $0xb,%eax the gas changes that to
mov $0xb,%eax

There is no optimisation happening here. it's only that gas is using only mov as mnemonic, irrespective of whether you write movw or movl. I suggest you have a look at the generated instruction bytecodes.

while on linux, the default it assumes is 32 bit mode. so, though your movw also it will show as mov, but the generated instruction bytecode will also be prefixed with a mode byte, compared to had same movw been used in 16 bit mode.

Quoted 1 line

How can I tell gas that I dont want him to optimize the code?

Do you mean anything other than above as 'optimize the code' ?

I don't know if I cleared some things for you or increased the mess.

--
sandeep
--------------------------------------------------------------------------
I predict that today will be remembered until tomorrow!
--------------------------------------------------------------------------

#2 lore raw
In reply to Martin

Am Samstag, 15. Mai 2004 10:28 schrieb Martin:

Quoted 11 lines

Hi folks,

I have a question regarding GAS and GCC.
Does the GAS modify the Assembler Code? If I try to assemble (for example) the following line:

popl %esi

the gas changes that to

pop %esi

though gas 'optimizes', which cannot be configured(!), in your example gas doesn't, re listing by gas, itself! (my version ex binutils 2.14.90) - apparently, your disassembler translates differently. compare the code...

the only 'optimization' by gas, which I'm aware of, is branches distance coding and selection of alignment fill code. branches coding can be forced to always 'long' (4 bytes) by declaring the destn label '.global'.

while assembling gas tries to deduce the oprands' formats by mnemonics and register nameing and, tries some correction if the proper size specs were missing, plus emanating a concerning warning (not an error!) message.

best,
hp

Signature · 1 line
mail to 'hp': lx at lxhp : in-berlin : de
author
#3 lore raw
Quoted 11 lines · peter willy krause

Am Samstag, 15. Mai 2004 10:28 schrieb Martin:

Quoted 9 lines

I have a question regarding GAS and GCC.
Does the GAS modify the Assembler Code? If I try to assemble (for example) the following line:

popl %esi

the gas changes that to

pop %esi

Quoted 7 lines

though gas 'optimizes', which cannot be configured(!), in your example gas doesn't, re listing by gas, itself! (my version ex binutils 2.14.90) - apparently, your disassembler translates differently. compare the code...

the only 'optimization' by gas, which I'm aware of, is branches distance coding and selection of alignment fill code. branches coding can be forced to always 'long' (4 bytes) by declaring the destn label '.global'.

Alright.

Quoted 3 lines

while assembling gas tries to deduce the oprands' formats by mnemonics and register nameing and, tries some correction if the proper size specs were missing, plus emanating a concerning warning (not an error!) message.

Ok. I guess here is my error in reasoning. I just wondered because in AlephOnes Paper about Stacksmashing he printed the following code:

[...]

        popl   %esi         
        movl   %esi,0x8(%esi)
        movb   $0x0,0x7(%esi)
        movl   $0x0,0xc(%esi)
        movl   $0xb,%eax
        movl   %esi,%ebx              
        leal   0x8(%esi),%ecx         
        leal   0xc(%esi),%edx         
        int    $0x80                
        movl   $0x1, %eax		
        movl   $0x0, %ebx

[...]

After assembling with gas and disassembling with gdb I got the following code:
[...]

        pop   %esi         
        mov   %esi,0x8(%esi)
        movb   $0x0,0x7(%esi)
        movl   $0x0,0xc(%esi)
        mov   $0xb,%eax      
        mov   %esi,%ebx      
        lea   0x8(%esi),%ecx 
        lea   0xc(%esi),%edx 
        int    $0x80         
        mov   $0x1, %eax	
        mov   $0x0, %ebx	

[...]

But if you are right, the code above should be the same.

But I still have one question. Wouldn't be the code from AlephOne bigger (bytesize) than the code I got?

Best regards,
thanks for your help.
Martin

#4 lore raw

Am Samstag, 15. Mai 2004 21:08 schrieb Martin:

Quoted 2 lines

But I still have one question. Wouldn't be the code from AlephOne

										^^^^^^^^^^ 

I've no idea of what that is. got a link?

best
hp

Signature · 1 line
mail to 'hp': lx at lxhp : in-berlin : de
author
#5 lore raw
Quoted 5 lines · peter willy krause

Am Samstag, 15. Mai 2004 21:08 schrieb Martin:

Quoted 2 lines

But I still have one question. Wouldn't be the code from AlephOne

										^^^^^^^^^^ 

I've no idea of what that is. got a link?

..my fault. sry.
http://www.phrack.org/show.php?p=49&a=14
(etwa in der Mitte des Textes befindet sich der Code)