Page 1 of 1

loader.o:file format not recognised

Posted: Mon Oct 17, 2011 6:32 am
by Sampiedev007
hi everyone ,
i m making an os, it's the first time i use C++ to create an os(i choose it because it's the language that i m more experienced than the others).
i search on the net to find a tutorial from where i began.
i did the part code : my project is composed of (temporarily) : VideoMemory.h and CPP , Kernel.cpp loader.asm commun.h .
i compile loader.asm with nasm, and the others file with gcc: i used this command to make the .o: nasm -o aout loader.asm loader.o
i got .o files and i make my linker :

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
    .text 0x100000 :
    {
        code = .; _code = .; __code = .;
        *(.text)
        . = ALIGN(4096);
    }

    .data :
    {
        data = .; _data = .; __data = .;
        *(.data)
        . = ALIGN(4096);
    }

    .bss :
    {
        bss = .; _bss = .; __bss = .;
        *(.bss)
        . = ALIGN(4096);
    }

    end = .; _end = .; __end = .;
}
i link them using ld -T Linker.ld -o Kernel.bin loader.o Kernel.o VideoMemory.o
but i get this error :
loader.o: file not recognized: File format not recognized

thx for your help

Re: loader.o:file format not recognised

Posted: Mon Oct 17, 2011 6:42 am
by Solar
Using Windows?

Not using a cross-compiler?

Try "file loader.o" and check the output. If you see something like "COFF" or "PE", you should refer to the Wiki, more specifically GCC Cross-Compiler.

Re: loader.o:file format not recognised

Posted: Mon Oct 17, 2011 6:43 am
by Solar
Belay that order.
Sampiedev007 wrote:i used this command to make the .o: nasm -o aout loader.asm loader.o
Take this in isolation:

Code: Select all

nasm -o aout loader.asm loader.o
Hint: There is something severely wrong about that line. Check NASM documentation.

Re: loader.o:file format not recognised

Posted: Mon Oct 17, 2011 7:10 am
by Chandra
Solar wrote:

Code: Select all

nasm -o aout loader.asm loader.o
Hint: There is something severely wrong about that line. Check NASM documentation.
For the sake of simplicity,

Code: Select all

nasm -f aout loader.asm -o loader.o
And no, that's not spoon-feeding. His assembler didn't complain on that so, I'd assume that must be a typing error.

Besides, use a Cross-Compiler.

Re: loader.o:file format not recognised

Posted: Mon Oct 17, 2011 9:03 am
by Solar
-f aout?

Really?

Re: loader.o:file format not recognised

Posted: Mon Oct 17, 2011 9:08 am
by Chandra
Solar wrote:-f aout?

Really?
Yes, of course. You seem to find a problem on that, don't you?

Re: loader.o:file format not recognised

Posted: Mon Oct 17, 2011 9:09 am
by Solar
Not authoritatively, no. I just would've expected either ELF or binary, not an executable format...?!?

Re: loader.o:file format not recognised

Posted: Mon Oct 17, 2011 9:15 am
by Chandra
Solar wrote:Not authoritatively, no. I just would've expected either ELF or binary, not an executable format...?!?
Oh! That's a valid logic :)

Since things are later linked with the kernel, it won't matter anyway(other than linker bumping out with the error: Can't recognize file format :wink:)

Re: loader.o:file format not recognised

Posted: Tue Oct 18, 2011 1:16 am
by Solar
...which is exactly what Sampiedev007 is seeing. So I would start by assembling loader.asm to object file, not executable. (I haven't worked with NASM, but I would guess it's creating a fully-linked executable here, startup code and everything. As a linker, I would balk at linking an executable into another executable, too. ;-) )

Re: loader.o:file format not recognised

Posted: Tue Oct 18, 2011 1:40 am
by Chandra
Solar wrote:...which is exactly what Sampiedev007 is seeing.
I've set-up the cross compiler that spits out the elf binaries but still is able to link the aout file-format. It doesn't complain on that so I'd say the actual problem is with the compiler tool-chain.
Solar wrote:So I would start by assembling loader.asm to object file, not executable.
That's a better approach, though.

Re: loader.o:file format not recognised

Posted: Tue Oct 18, 2011 2:02 am
by Solar
Chandra wrote:...so I'd say the actual problem is with the compiler tool-chain.
Just because you found an error doesn't mean you've found the error. :wink: