Reading command line args from assmebly
Anand Android
android.anand at gmail.com
Thu Feb 18 22:15:31 EST 2010
Hi All,
I have written one sample assmebly and c code which reads command line args
and displays .
find the source files as attachments.
expected output is ,
$ ./a.out
Inside __linker_init argc = 1
Inside __linker_init argv[0] = ./a.out
Segmentation fault [Seg fault Never mind]
if i statically link startx86.S & linker.c on x86 AND statrt_ppc.S &
linker.c on PS3,i'll get SEGV fault on both system. But on PS3, inside
'_start' function if i verify the contents of 'r1[stack pointer]' and '(Char
*) *(r1 + 4)' in GDB i get '1' and '~/a.out' respectively .But once 'r1'
moved to r3[holds the 1st arg of the function] & passed as argument to
__linker_init ,inside the function '*elfdata' points '1' but (char *)
*(elfdata + 1) points to some junk string. some thing like this
"|c\033x|i\003�N\200\004 \224!��|\b\002�\220\001".
find the GDB log file of PS3.
if i link them without statically,i'll get the correct output on x86 .i.e
$ ./a.out
Inside __linker_init argc = 1
Inside __linker_init argv[0] = ./a.out
Segmentation fault [Seg fault Never mind]
but on ps3 i get this,
$ ./a.out
Inside __linker_init argc = 0
Inside __linker_init argv[0] = |c|i�N� �!����
Segmentation fault
Why am i getting strange characters instead of './a.out' and y 'argc' having
'zero' ?
Why is this two different outputs for static linking and dynamic linking ?
-Anand
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20100218/3a13ee69/attachment-0001.htm>
-------------- next part --------------
This GDB was configured as "powerpc-linux-gnu"...
(gdb) b _start
Breakpoint 1 at 0x100000e4: file start.S, line 35.
(gdb) r
Starting program: /home/dayananda/junks/power/a.out
Breakpoint 1, _start () at start.S:37
37 bl __linker_init
Current language: auto; currently asm
(gdb) s
__linker_init (elfdata=0x0) at linker.c:5
5 {
Current language: auto; currently c
(gdb) i r
r0 0x0 0
r1 0xff9a1820 4288288800
r2 0x0 0
r3 0xff9a1820 4288288800
r4 0x0 0
r5 0x0 0
r6 0x0 0
r7 0x0 0
r8 0x0 0
r9 0x0 0
r10 0x0 0
r11 0x0 0
r12 0x0 0
r13 0x0 0
r14 0x0 0
r15 0x0 0
r16 0x0 0
r17 0x0 0
r18 0x0 0
r19 0x0 0
r20 0x0 0
r21 0x0 0
r22 0x0 0
r23 0x0 0
r24 0x0 0
r25 0x0 0
r26 0x0 0
r27 0x0 0
r28 0x0 0
r29 0x0 0
r30 0x0 0
r31 0x0 0
pc 0x100000f4 268435700
msr 0x4010c032 1074839602
cr 0x0 0
lr 0x100000e8 268435688
ctr 0x0 0
xer 0x0 0
(gdb) p *(0xff9a1820)
$1 = 1
(gdb) p *(0xff9a1820+4)
$2 = -6678169
(gdb) p (char *)*(0xff9a1820+4)
$3 = 0xff9a1967 "/home/dayananda/junks/power/a.out"
(gdb) s
7 int argc = (int) *elfdata;
(gdb) s
8 char **argv = (char**) (elfdata + 1);
(gdb) p elfdata
$4 = (unsigned int **) 0xff9a1820
(gdb) p *elfdata
$5 = (unsigned int *) 0x1
(gdb) p *(elfdata + 1)
$6 = (unsigned int *) 0x100000e8
(gdb) p (char *)*(elfdata + 1)
$7 = 0x100000e8 "|c\033x|i\003�N\200\004 \224!��|\b\002�\220\001"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linker.c
Type: application/octet-stream
Size: 277 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20100218/3a13ee69/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: start_ppc.S
Type: application/octet-stream
Size: 1744 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20100218/3a13ee69/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: start_x86.S
Type: application/octet-stream
Size: 555 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20100218/3a13ee69/attachment-0005.obj>
More information about the Linuxppc-dev
mailing list