# Reading command line args from assmebly

- From: Anand Android \<hidden\>
- Date: 2010-02-18 11:15:33 
- List: linuxppc-dev
- Page: https://ratatoskr.run/linuxppc-dev/2010/02/9458795
- Thread: https://ratatoskr.run/linuxppc-dev/2010/02/9458795/t.md

```text
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
```

## Attachments

- [gdb.txt](https://ratatoskr.run/linuxppc-dev/2010/02/9458795/attachment/0) (text/plain, 2129 bytes)
- [linker.c](https://ratatoskr.run/linuxppc-dev/2010/02/9458795/attachment/1) (application/octet-stream, 278 bytes)
- [start\_ppc.S](https://ratatoskr.run/linuxppc-dev/2010/02/9458795/attachment/2) (application/octet-stream, 1745 bytes)
- [start\_x86.S](https://ratatoskr.run/linuxppc-dev/2010/02/9458795/attachment/3) (application/octet-stream, 556 bytes)
