LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can't compile OS example (https://www.linuxquestions.org/questions/programming-9/cant-compile-os-example-803561/)

MTK358 04-22-2010 12:21 PM

Can't compile OS example
 
I am following this tutorial:

http://wiki.osdev.org/Bare_bones#Booting_the_kernel

But I just can't get it to compile. What do you think is wrong?

Code:

$ nasm -f elf -o loader.o loader.s
[michael:test]$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
[michael:test]$ ld -T linker.ld -o kernel.bin loader.o kernel.o -A i386
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output

I'm often really starting to wish my desktop had 32-bit Linux on it!

Sergei Steshenko 04-22-2010 12:23 PM

Quote:

Originally Posted by MTK358 (Post 3944213)
I am following this tutorial:

http://wiki.osdev.org/Bare_bones#Booting_the_kernel

But I just can't get it to compile. What do you think is wrong?

Code:

$ nasm -f elf -o loader.o loader.s
[michael:test]$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
[michael:test]$ ld -T linker.ld -o kernel.bin loader.o kernel.o -A i386
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output

I'm often really starting to wish my desktop had 32-bit Linux on it!

Have you read NASM documentation, the part describing output format ?

MTK358 04-22-2010 12:32 PM

Code:

$ nasm -hf

...

valid output formats for -f are (`*' denotes default):
  * bin      flat-form binary files (e.g. DOS .COM, .SYS)
    ith      Intel hex
    srec      Motorola S-records
    aout      Linux a.out object files
    aoutb    NetBSD/FreeBSD a.out object files
    coff      COFF (i386) object files (e.g. DJGPP for DOS)
    elf32    ELF32 (i386) object files (e.g. Linux)
    elf      ELF (short name for ELF32)
    elf64    ELF64 (x86_64) object files (e.g. Linux)
    as86      Linux as86 (bin86 version 0.3) object files
    obj      MS-DOS 16-bit/32-bit OMF object files
    win32    Microsoft Win32 (i386) object files
    win64    Microsoft Win64 (x86-64) object files
    rdf      Relocatable Dynamic Object File Format v2.0
    ieee      IEEE-695 (LADsoft variant) object file format
    macho32  NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files
    macho    MACHO (short name for MACHO32)
    macho64  NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
    dbg      Trace of all info passed to output stage

Isn't "-f elf" correct, then?

Sergei Steshenko 04-22-2010 12:38 PM

Quote:

Originally Posted by MTK358 (Post 3944225)
Code:

$ nasm -hf

...

valid output formats for -f are (`*' denotes default):
  * bin      flat-form binary files (e.g. DOS .COM, .SYS)
    ith      Intel hex
    srec      Motorola S-records
    aout      Linux a.out object files
    aoutb    NetBSD/FreeBSD a.out object files
    coff      COFF (i386) object files (e.g. DJGPP for DOS)
    elf32    ELF32 (i386) object files (e.g. Linux)
    elf      ELF (short name for ELF32)
    elf64    ELF64 (x86_64) object files (e.g. Linux)
    as86      Linux as86 (bin86 version 0.3) object files
    obj      MS-DOS 16-bit/32-bit OMF object files
    win32    Microsoft Win32 (i386) object files
    win64    Microsoft Win64 (x86-64) object files
    rdf      Relocatable Dynamic Object File Format v2.0
    ieee      IEEE-695 (LADsoft variant) object file format
    macho32  NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files
    macho    MACHO (short name for MACHO32)
    macho64  NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
    dbg      Trace of all info passed to output stage

Isn't "-f elf" correct, then?

So, you absolutely stubbornly refuse to notice presence of 32 and 64 numbers in the output ?

MTK358 04-22-2010 12:39 PM

But it says that "elf" is the same as "elf32"!

Sergei Steshenko 04-22-2010 12:57 PM

Quote:

Originally Posted by MTK358 (Post 3944230)
But it says that "elf" is the same as "elf32"!


I'm asking it again - you stubbornly refuse to see the 64 number ?

MTK358 04-22-2010 01:12 PM

But I don't want to compile it as 64-bit! I want it to be 32-bit!

Sergei Steshenko 04-22-2010 01:44 PM

Quote:

Originally Posted by MTK358 (Post 3944273)
But I don't want to compile it as 64-bit! I want it to be 32-bit!

You may want whatever you want, but the rest of files are 64 bits, and the linker refuses to link 64 and 32 bit formats:

Code:

ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
.

Do you see the item in red ? Would you argue with linker ?

Why do you care about the output file format ? I.e. why not doing what the linker wants from you ?

MTK358 04-22-2010 01:53 PM

Code:

$ nasm -f elf32 -o loader.o loader.s
$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
$ ld -T linker.ld -o kernel.bin loader.o kernel.o -A i386
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output


Sergei Steshenko 04-22-2010 02:09 PM

Quote:

Originally Posted by MTK358 (Post 3944331)
Code:

$ nasm -f elf32 -o loader.o loader.s
$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
$ ld -T linker.ld -o kernel.bin loader.o kernel.o -A i386
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output


You stubbornly refuse to read 'ld' manpage - see the item in red. Despite of many times you've been suggested to read.

Mara 04-22-2010 02:52 PM

Moderator note: Dear Sergei, it is not really necessary to be aggressive. A simple mention of the options that cause problems would be enough.

MTK358 04-22-2010 03:00 PM

Because ld's output showed "i386", I assumed that that would be valid input.

I looked at the man page and I don't understand this:

Code:

      -A architecture
      --architecture=architecture
          In the current release of ld, this option is useful only for the
          Intel 960 family of architectures.  In that ld configuration, the
          architecture argument identifies the particular architecture in the
          960 family, enabling some safeguards and modifying the archive-
          library search path.

          Future releases of ld may support similar functionality for other
          architecture families.

What's the option for ld to output i386 executables?

Sergei Steshenko 04-22-2010 04:22 PM

Quote:

Originally Posted by MTK358 (Post 3944397)
Because ld's output showed "i386", I assumed that that would be valid input.

I looked at the man page and I don't understand this:

Code:

      -A architecture
      --architecture=architecture
          In the current release of ld, this option is useful only for the
          Intel 960 family of architectures
.  In that ld configuration, the
          architecture argument identifies the particular architecture in the
          960 family, enabling some safeguards and modifying the archive-
          library search path.

          Future releases of ld may support similar functionality for other
          architecture families.

What's the option for ld to output i386 executables?


Which part of the item in red you do not understand ?

As I have already asked you, did you read to the very end output produced by

Code:

ld --help | less
?

Did you comprehend and analyze the text ? Did you do analysis WRT relevant and irrelevant to your task items ?

MTK358 04-22-2010 04:28 PM

I read throught it, I believe that the answer might be there, but I just don't understand it.

I read it, but I don't understand it.

I try to read documentation, but you always assume I don't. I say that I tried but I don't understand, but you keep falsely blaming me for not even trying. I'm just sick of that!

Sergei Steshenko 04-22-2010 04:30 PM

Quote:

Originally Posted by MTK358 (Post 3944458)
I read throught it, I believe that the answer might be there, but I just don't understand it.

I read it, but I don't understand it.

I try to read documentation, but you always assume I don't. I say that I tried but I don't understand, but you keep falsely blaming me for not even trying. I'm just sick of that!

I am asking you again, which part of

Quote:

In the current release of ld, this option is useful only for the
Intel 960 family of architectures

you do not understand ? It's a very simple question.


All times are GMT -5. The time now is 07:17 PM.