.ld

Programming, for all ages and all languages.
Post Reply
chezzestix
Member
Member
Posts: 118
Joined: Mon May 05, 2008 5:51 pm

.ld

Post 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.
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Re: .ld

Post by Zenith »

Here's the manual on making linker scripts for GNU ld: http://sourceware.org/binutils/docs/ld/ ... ml#Scripts
"Sufficiently advanced stupidity is indistinguishable from malice."
souradipm
Posts: 22
Joined: Fri Aug 15, 2008 10:08 am

Re: .ld

Post 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.
chezzestix
Member
Member
Posts: 118
Joined: Mon May 05, 2008 5:51 pm

Re: .ld

Post 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?
souradipm
Posts: 22
Joined: Fri Aug 15, 2008 10:08 am

Re: .ld

Post 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.
chezzestix
Member
Member
Posts: 118
Joined: Mon May 05, 2008 5:51 pm

Re: .ld

Post 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 = .;
}
souradipm
Posts: 22
Joined: Fri Aug 15, 2008 10:08 am

Re: .ld

Post 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?)
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: .ld

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
chezzestix
Member
Member
Posts: 118
Joined: Mon May 05, 2008 5:51 pm

Re: .ld

Post 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'.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: .ld

Post by Combuster »

"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply