I write a simple C program in Solaris and want to check the assembly code of dup
:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int pdes[2];
if(-1 != (pipe(pdes)))
{
//printf("%d\n", dup(pdes[0]));
dup(pdes[0]);
}
return 0;
}
(1) I use gdb
, and gdb
outputs the assembly code:
(gdb) disassemble dup
Dump of assembler code for function dup:
0xff2cda44 <+0>: mov 0x29, %g1 ! 0x29
0xff2cda48 <+4>: ta 8
0xff2cda4c <+8>: bcs 0xff223be0 <_cerror>
0xff2cda50 <+12>: nop
0xff2cda54 <+16>: retl
0xff2cda58 <+20>: nop
End of assembler dump.
(2) I use mdb
, and mdb
outputs the assembly code:
> dup::dis
PLT:dup: sethi %hi(0x21000), %g1
PLT:dup: ba,a -0x88 <0x20a14>
PLT:dup: nop
0x20aa4: nop
0x20aa8: unimp 0x1
0x20aac: unimp 0xe0
0x20ab0: unimp 0xc
0x20ab4: unimp 0x109b8
0x20ab8: unimp 0xd
0x20abc: unimp 0x109d4
0x20ac0: unimp 0x1d
(3) I use the command: echo "dup::dis" | mdb -k
, and the assembly code:
dup: sra %o0, 0x0, %o0
dup+4: mov %o7, %g1
dup+8: clr %o2
dup+0xc: clr %o1
dup+0x10: call -0xeec <fcntl>
dup+0x14: mov %g1, %o7
Why do the three methods output different assembly code for the same function?