linux - Using -dynamic-linker with a linker script? -
linux - Using -dynamic-linker with a linker script? -
i using linux 2.6.31-14 on intel 32-bit processor.
c file:
#include <stdio.h> main() { printf("hello world!\n"); }
linker script:
sections{ .text 0x00000100 :{ *(.text) } }
output:
$ gcc -s test.c $ -o test.o test.s $ ld -t linker.ld -dynamic-linker /lib/ld-linux.so.2 -o test test.o test.o: in function `main': test.c:(.text+0x11): undefined reference `puts'
what wrong? how can create linker script utilize dynamic c library?
i think should link programme c standard library (libc.so) adding -lc alternative ld arguments.
ld -t linker.ld -lc -dynamic-linker /lib/ld-linux.so.2 -o test test.o
also may have problems running programme (segmentation faults) because test.o have no programme entry point (_start symbol). need additional object file entry point calling main() function within test.o , termitates code execution calling exit() scheme call.
here start.s code
# linux scheme calls constants .equ syscall_exit, 1 .equ interrupt_linux_syscall, 0x80 # code section .section .text .globl _start _start: # programme entry point phone call main # calling main function # calling exit() scheme phone call movl %eax, %ebx # saving homecoming value exit() argument movl $syscall_exit, %eax # scheme phone call number int $interrupt_linux_syscall # raising programm interrupt
then should build program
gcc test.c -s test.s -o test.o start.s -o start.o ld start.o test.o -o test -lc --dynamic-linker=/lib/ld-linux.so.2
you may want check out article https://blogs.oracle.com/ksplice/entry/hello_from_a_libc_free larn more how c compiler , standard library works.
linux linker ld linker-scripts
Comments
Post a Comment