Linker error: PE operations on non PE file

From: Tom Junior (tbjnospam_at_automateddesign.com)
Date: 05/21/04


Date: Fri, 21 May 2004 15:50:33 GMT

Hi,

I don't know if this group covers linker errors. Anyway...

I'm running Windows 2000 Pro and using the latest version of DJGPP.

All I'm trying to do is compile and link a simple kernel example so I can
burn it to a floppy.

It involves 3 files:
kernel.c
kernel_start.asm
link.ld

Everything compiles fine using the following:
nasmw -f coff kernel_start.asm - o ks.o
gcc -c kernel.c -o kernel.o

Then I try to do the linking:
ld -T link.ld -o kernel.bin ks.o kernel.o

Result:
ld: PE operations on non PE file

Here's the linker file:
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 = .;
}

Can someone please explain the error and why I can't get these two files
to link?

Note: Compiling the assembly file to a.out format instead of coff does not
work, and gives me the error Invalid file format.

Thanks in advance,
Tom

The rest of the code:

kernel.c:
//////////////////////////////////////////////
// This code was made for the tutorial:
// "Making a Simple C kernel with Basic printf and clearscreen Functions"
//
// This code comes with absolutly
// NO WARRANTY
// you can not hold me(KJ), nor
// anyone else responsible for what
// this code does.
//
// This code is in the public domain,
// you may use it however you want
//////////////////////////////////////////////

#define WHITE_TXT 0x07 // white on black text

void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);

k_main() // like main in a normal C program
{
        k_clear_screen();
        k_printf("Hi!\nHow's this for a starter OS?", 0);
};

void k_clear_screen() // clear the entire text screen
{
        char *vidmem = (char *) 0xb8000;
        unsigned int i=0;
        while(i < (80*25*2))
        {
                vidmem[i]=' ';
                i++;
                vidmem[i]=WHITE_TXT;
                i++;
        };
};

unsigned int k_printf(char *message, unsigned int line) // the message and
then the line #
{
        char *vidmem = (char *) 0xb8000;
        unsigned int i=0;

        i=(line*80*2);

        while(*message!=0)
        {
                if(*message=='\n') // check for a new line
                {
                        line++;
                        i=(line*80*2);
                        *message++;
                } else {
                        vidmem[i]=*message;
                        *message++;
                        i++;
                        vidmem[i]=WHITE_TXT;
                        i++;
                };
        };

        return(1);
};

kernel_start.asm:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This code was made for the tutorial:
;; "Making a Simple C kernel with Basic printf and clearscreen Functions"
;;
;; This code comes with absolutly
;; NO WARRANTY
;; you can not hold me(KJ), nor
;; anyone else responsible for what
;; this code does.
;;
;; This code is in the public domain,
;; you may use it however you want
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[BITS 32]

[global start]
[extern _k_main] ; this is in the c file

start:
   call _k_main

   cli ; stop interrupts
   hlt ; halt the CPU

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Relevant Pages

  • Re: Distributions
    ... | general there are a lot of packages for people to use. ... kernel, have to run on a multitude of different systems, they tend to be ... and slower than if you compile those packages, ... can have that stability with virtually any distro. ...
    (Debian-User)
  • Re: Distributions
    ... Ubuntu is based on Debian, ... | general there are a lot of packages for people to use. ... kernel, have to run on a multitude of different systems, they tend to be larger ... and slower than if you compile those packages, ...
    (Debian-User)
  • Problems with custom kernel fbsd 6.2
    ... My kernel for freebsd 6.2 is not compiling but only with my custom config. ... I was able to compile it with the GENERIC kernel included, but my modified one will not compile. ... # Power management support ...
    (freebsd-questions)
  • Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
    ... >optimisations independently of each other', is fairly simple, (in ... >concept), and elegant, (as it lets you compile the most finely tuned ... >Up to now, selecting a CPU to compile for basically means, "Use ... it's silly to include them all in a kernel for a 386. ...
    (Linux-Kernel)
  • [duke@spacebox.net: oops related crash]
    ... 00000000-0009ffff: System RAM ... 00100000-0020c991: Kernel code ... I just got this while trying to compile pciutils - ... oops through ksymoops and I've attached the output. ...
    (Linux-Kernel)