I am currently learning assembler for x86 with att syntax. Over the past time I have already written exercise programs without dependencies. Now I wanted to try writing a shared shared-library, as this is what I do in C most of the time.
I thought it may be a good idea to write a simple "test" program, which consists of an, in asm written, test-library and a program, that links to this test-library.
I assembled the library with: as -32 prog.s -o prog.o
and the caller with: as -32 startprog.s -o startprog.o
After I assembled both files, I ran the linker on the library with ld -melf_i386 -fPIE -shared prog.o -o libprog.so
and on the caller ld -melf_i386 startprog.o -L./ -lprog -o startprog
Up to this point everything worked fine. But then I tried to run the program ./startprog
, which causes a Segment violation. I re-ran with gdb
and set _start
as a breakpoint. As soon as I entered r
into gdb, to actually start the execution,
I was greeted with the same SIGSEGV. It seems to occur in the libc
write()
function. At least that is, what I can make of this.
The complete output looks like this:
[cediw@cwm10 pC $] gdb ./startprog
Reading symbols from ./startprog...
(No debugging symbols found in ./startprog)
(gdb) b _start
Breakpoint 1 at 0x8049020
(gdb) r
Starting program: /home/cediw/dev/asm/re/pC/startprog
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
Program received signal SIGSEGV, Segmentation fault.
0xf7f06fe1 in write () from /usr/lib/libc.so.1
(gdb) disas
Dump of assembler code for function write:
0xf7f06fd0 < 0>: push %esi
0xf7f06fd1 < 1>: push