2. Da sa v C-cku pre ELF shared so library nastavit _start entry point (resp. aby sa spustil int main()) ? Ak skompilujem v C-ku jednoduchy program "int main() { printf("Hello\n"); }" ako shared library dostavam Segmentation fault...
Moje pozorovanie v asm:
Skusal som experimentovat s tymto jednoduchym programom (vypise "Hello 1\n", potom "Hello 2\n" a skonci):
.text .global _start _start: movl $len, %edx movl $msg, %ecx movl $1, %ebx movl $4, %eax int $0x80 subl $8, %esp movl $0x6C6C6548, 0(%esp) # "Hell" movl $0x0A32206F, 4(%esp) # "o 2\n" movl %esp, %ecx addl $8, %esp movl $8, %edx movl $1, %ebx movl $4, %eax int $0x80 movl $0, %ebx movl $1, %eax int $0x80 .data msg: .ascii "Hello 1\n" len = . - msg
Ak ho skompilujem ako ELF executable, tak ide vsetko ok:
$ as test.s -o test.o && ld test.o -o a.out $ ./a.out Hello 1 Hello 2
Avsak ak ho skompilujem ako ELF shared library, tak je tu daco divne a nechapem tomu uz vobec...
$ as test.s -o test.o && ld -shared test.o -o a.out $ ./a.out Hello 2Kde sa stratil vypis "Hello 1"?? Skusal som aj presunut msg do sekcie .text (namiesto .data) ale spravanie bolo v oboch pripadoch rovnake...