Page 1 of 1
.ld
Posted: Mon Aug 18, 2008 12:37 pm
by chezzestix
Is there a tutorial around for making these files? The barebones for Grub doesnt explain what everthing is in the ld file and I'm avoiding writing my kernel in C++ so I need to know ever detail about the ld.
Re: .ld
Posted: Mon Aug 18, 2008 1:52 pm
by Zenith
Here's the manual on making linker scripts for GNU ld:
http://sourceware.org/binutils/docs/ld/ ... ml#Scripts
Re: .ld
Posted: Wed Aug 20, 2008 1:10 pm
by souradipm
Bran's Kernel Development Tutorial has a sample link.ld file you could work on, and my ld file is basically that with some INPUT() commands at the top.
Re: .ld
Posted: Thu Aug 21, 2008 2:12 pm
by chezzestix
Thank you both of you. I have been studying Bran's Kernel but I cant get the darn thing to link correctly.
The batch:
Code: Select all
echo Now assembling, compiling, and linking your kernel:
nasm -f aout -o start.o start.asm
tcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c
tcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o scrn.o scrn.c
tcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o gdt.o gdt.c
tcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o idt.o idt.c
tcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o isrs.o isrs.c
tcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o irq.o irq.c
tcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o timer.o timer.c
tcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o kb.o kb.c
ld -T link.ld -o kernel.bin start.o main.o scrn.o gdt.o idt.o isrs.o irq.o timer.o kb.o
echo Cleaning up object files...
del *.o
echo Done!
pause
Produces the output:
start.o: file not recognized: File format not recognized
When the ld command is run. I just moved the ld.exe and the stuff it calls for to my build folder. Can I do that? If so what is wrong here?
Re: .ld
Posted: Thu Aug 21, 2008 2:20 pm
by souradipm
It seems to be a problem with your link.ld file, not your bat. Post that here. Are you using Windows or Linux? If you're using linux, compile start.asm as an elf.
Re: .ld
Posted: Thu Aug 21, 2008 2:41 pm
by chezzestix
Im using windows
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
Re: .ld
Posted: Fri Aug 22, 2008 5:39 am
by souradipm
Ahh, I think your problem is actually in the batch file. The linker script looks correct, however, you're using a 16-bit compiler with your .c files, and if you're using '[BITS 32]' in start.asm you are mixing 16-bit and 32 bit which isn't good. Use gcc as a compiler. I use Windows too, and a great port is DJGPP.
Oh and I think the c compiler flags are for gcc, not tcc. (Is it turbo c?)
Re: .ld
Posted: Fri Aug 22, 2008 9:20 pm
by thepowersgang
It's most probably an incompatibility between versions of LD. The cross compiler that comes with bran's tutorial can understand a.out as an input but the standard linker on Linux/mingw cannot.
Try changing -f aout to -f elf when calling nasm and testing it.
Re: .ld
Posted: Sat Aug 23, 2008 10:42 am
by chezzestix
@souradipm
I've looked at DJGPP but I thought I would try Tiny C Compiler because of its size.
When I've tried DJGPP all I've gotten is:
gcc.exe: enviroment variable DJGPP not defined
@thepowersgang
When I do that it gives me:
ld: cannot perform PE operations on non PE output file 'kernel.bin'.
Re: .ld
Posted: Sat Aug 23, 2008 4:17 pm
by Combuster