File format not recognized

CodeVisio
2012-08-24
2013-06-06
  • CodeVisio
    CodeVisio
    2012-08-24

    Hi All,

    sorry if this is not the right forum for my question. If it so please let me point out on the right one.

    The scenario:
    I've installed MingW (mingw.org) environment with gcc and ld support, just to make some test on my Windows 7(64bit).
    All works fine.
    I've installed nasm too, and this works fine.

    The Problem:
    I'm using nasm to assemble a file with 'aout' object file format.
    After that, I used gcc to compile some c files, producing object files. Also this is ok.
    When I come to ld in order to link all object files it says about my nasm object file:
    File format not recognized.

    My guess is that probably I don't have the right MingW (32 bit?) installed and so the right ld version.
    This is why I'm wrinting here.

    Any suggestion?

    Thank you

     
  • Jonathan Yong
    Jonathan Yong
    2012-08-25

    "I'm using nasm to assemble a file with 'aout' object file format."

    There is your problem, Windows nor mingw use the aout format. I don't know what nasm calls Windows PE, but consult the NASM documentation before proceeding further.

     
  • CodeVisio
    CodeVisio
    2012-08-25

    I've forgotten to say before that I've tried different object file formats with nasm, coff, bin, elf, elf32, elf64 etc but ld is still output errors, different ones. For example with coff and win32 object file format ld says, 'cannot perform pe operations on non pe output file'. This is caused probably because the asm file is not structured for windows but for a raw binary format.
    I'm following this tutorial
    http://www.osdever.net/bkerndev/Docs/whatsleft.htm
    I've also successfull compiled and linked the kernel on a linux pc following the instructions from the tutorial, but on a Window pc not.

    Any idea?

    Thank you

     
  • rubenvb
    rubenvb
    2012-08-25

    Ignoring the fact you are trying to use the competing project (MinGW.org vs MinGW-w64, which is where you are at now), this will probably never work.

    What are you trying to do?

    If you are trying to link a program for your toy OS, you need to use binutils compiled to match the ABI of your toy OS.
    If you are trying to link a bootloader or OS loader binary file, you need to provide your own linker scripts, as (IIRC) osdev tells you to do.
    MinGW ld will by default (and perhaps only) generate Windows executable image files.

    That being said, a nasm-assembled (-f win32) file should be linkable by ld. Either you're doing black magic (the osdev reference seems to imply this) or you're using outdated tools. My bet is on the first;

     
  • CodeVisio
    CodeVisio
    2012-08-25

    Hi rubernvb,

    If I right understood your points:

    If you are trying to link a bootloader or OS loader binary file, you need to provide your own linker scripts, as (IIRC) osdev tells >you to do.

    No, the tutorial doesn't talk about boot loader. The only assembler file has some stuff releated to GRUB and others low level ones(gdt, isr etc). I think the asm file is not structured as windows program for sure.
    Yes there is a linker script file to pass to ld (link.ld).

    If you are trying to link a program for your toy OS, you need to use binutils compiled to match the ABI of your toy OS.

    Yes I know that. But what I'm tying to do is simply compile and link the files on that tutorial. This should give me a raw flat kernel file as the tutorial says. I didn't download the DYGPP as the tutorial says because doesn't work on a 64bit Windows.

    MinGW ld will by default (and perhaps only) generate Windows executable image files.

    What I have understood about MinGW is that they are a porting to Windows env. (not a posix one like cygwin) but they should behave like the counter part on linux (more or less), so I can use gcc, ld, as if I were on linux (again more or less).

    That being said, a nasm-assembled (-f win32) file should be linkable by ld

    It doesn't work in my case.

    Either you're doing black magic (the osdev reference seems to imply this) or you're using outdated tools. My bet is on the first;

    MinGW and nasm were downloaded the other day.
    I don't think there are black magic things here. The code is quite simple. Probably the hard part is on the asm file.

    From the web link I have provided there is a list of files you can download and build to get your kernel image. The build.bat file contains the list of tools called in order to build that image. Probably the tutorial is outdated and is assuming tools that now are over updated.
    My first thought was that ld and so MinGW wasn't able to link the assembler file because it is a 32bit version while I have 7(64 bit) version.

    Thank you anyway