LD Not Linking

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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

LD Not Linking

Post by pcmattman »

Ok, I now (finally!) have a working setup of GRUB. New problem: when I try to build the BareBones example (DJGPP), LD says about the NASM-assembled loader:

Code: Select all

loader.o: file not recognized: File format not recognized
I'm assembling the NASM version of loader.s (with the '-f elf' option).

Even just using NASM and assembling into a pure binary ('-f bin') to load with GRUB does not work. Nor does a pure elf file ('-f elf'). I switched to GRUB so I could make a C kernel (and also because it seemed so much easier). Why won't this work?
Last edited by pcmattman on Thu Feb 08, 2007 3:48 pm, edited 1 time in total.
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

Post by Otter »

Which ld do you use ? The one of djgpp ? You have to make sure that your ld knows the elf format. You could try

Code: Select all

$ ld --help
to get a list of supported targets. Otherwise, nasm is able to produce its object files in lots of different formats, dunno what your ld uses, but I would suggest to use elf.

Do you use 32 bit code for your kernel ? You should ... Maybe you could give some code, but I think the following should work (for example)

Code: Select all

void _main( void* mbd, unsigned int magic ) {
  *(unsigned int*)0x000B8000 = 0x04420441;
}
Try to use gcc instead
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Ok, found out a possible reason: my version of LD does not have ELF as a supported target:
ld --help wrote: supported targets: coff-go32 coff-go32-exe a.out-i386 srec symbolsrec tekhex binary ihex
Can anyone tell me how to make an A.OUT file work in GRUB?
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

Post by Otter »

Dunno whether it's possible to use a.out, but it should be possible to use the binary format, even if it is more complicated than using elf. GRUB needs to know where to load the file so you need to adjust the multiboot header. I don't remember exactly what to do but you could look for it in the multiboot specification, it should be easy to understand.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

It doesn't matter anymore, I did a search on Google for 'GRUB binary kernel" and the first result that came up was exactly what I needed. Thankyou for your help.
Post Reply