a link problem(ld -r)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jinglexy
Posts: 15
Joined: Sat Mar 10, 2007 1:05 am

a link problem(ld -r)

Post by jinglexy »

i try to write a simply os, at first all source file compiled in a simpley makefile as follow:

all:
g++ -I/root/source/os/jinix-1.2.1/include/ -I/root/source/os/jinix-1.2.1/ -nostdlib -nostdinc -nostartfiles -nodefaultlibs -fno-rtti -fno-exceptions -fomit-frame-pointer -MD -MP -Wall -Wextra -O2 -D__KERNEL__ -c ./init/init_kernel.cpp ./arch/i386/irq.cpp ./fs/ext2/ext2.cpp ./fs/vfat/vfat.cpp ./fs/fs2.cpp ./fs/proc/proc.cpp ./fs/fs1.cpp ./lib/ctype.cpp ./lib/string.cpp ./kernel/trap.cpp ./mm/memory.cpp ./net/core.cpp ./drivers/ide/ide.cpp ./drivers/video/console/textio.cpp ./drivers/video/console/ostream.cpp ./ipc/pipe.cpp
g++ -I/root/source/os/jinix-1.2.1/include/ -I/root/source/os/jinix-1.2.1/ -nostdlib -nostdinc -nostartfiles -nodefaultlibs -fno-rtti -fno-exceptions -fomit-frame-pointer -MD -MP -Wall -Wextra -O2 -D__KERNEL__ -D__ASM__ -c -o arch/i386/boot/boot.o arch/i386/boot/boot.S
ld -v *.o -T arch/i386/vmjinix.lds.S -o vmjinix

all work well, the vmjinix.lds.S is from linux-2.6.10, after link, the elf kernel entry point is 0x100000.

buf after i adjust the makefile, the entry point is 0x100010, in the kernel init period(an assemble file), will init page table(the address is fixed by .org instruction:
.org 0x2000)
so after link, the page table is 0x102010, (before my makefile adjust, it is 0x102000), the address is not aligned 4K. so kernel init crushed.

i do the new makefile as follow:
int the lib directory, compile the two file: ctype.cpp, string.cpp, etc.
then ld -r ctype.o string.o -o k_lib.o
at top makefile, ld command is:
ld -T vmjinix.lds.S lib/k_lib.o mm/k_mm.o ...... -o vmjinix
after link, the entry point is 0x100010, not 0x100000.
i think there may be some error on" ld -r ctype.o string.o -o k_lib.o", so i modify it as:
as -r ctype.o string.o -o k_lib.a, then link all k_xx.a file,
after link, the entry point is 0x100000, it is right, all runs ok.
it is strange, why it is?
how can i use some way to avoid it in "ld -r"?
Post Reply