OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:05 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: build script fails on linux host / no from 64 bit build.
PostPosted: Mon Feb 04, 2019 2:58 am 
Offline

Joined: Fri Jan 04, 2019 6:05 am
Posts: 9
You folks have been helpful in the past so I thought I'd come back with a new problem. I've been busy with University so theOS development has been on the backlogs.
I've switched back to linux from a macbook pro and am having some trouble getting the build to work correctly.
If I clone the repo with

git clone https://github.com/sowens26/theos
https://github.com/sowens26/theos


and simulate it with

Code:
qemu-system-x86_64 os-image


then everything works properly but if i attempt to build it with the build script it will throw this errror

ld: i386 architecture of input file `kernel-boots.o' is incompatible with i386:x86-64 output, followed by some other errors that indicate a failure upstream in the build.

I have tried changing the following line in ./build_script.sh

Code:
nasm kernel-boots.asm -f elf -o kernel-boots.o

to
Code:
nasm kernel-boots.asm -f elf64 -o kernel-boots.o


which caused the error to no longer be thrown and the build succeeds but the purple "currently in c kernel" message does not show.

is graphics memory located somewhere else in 64 bit runtime? Am I now in 64bit runtime?
any help would be appreciated.


Top
 Profile  
 
 Post subject: Re: build script fails on linux host / no from 64 bit build.
PostPosted: Mon Feb 04, 2019 4:05 am 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 306
Location: Germany
Hi,

a few things that I came across in about 30 seconds of browsing your repo:

1. You are using your system compiler against all advice on osdev. Please build a cross-compiler and see what output you get when using it. See GCC_Cross-Compiler

2. Why are you lying to your assembler, telling it that your code is should be output as elf64 when it isn't 64-bit?

3. Why are you creating a flat binary?

Your error means that it you are mixing 32-bit and 64-bit code in one binary, which probably has something to do with your usage of your system compiler. I assume it doesn't output elf32 for you.

Cheers, Leo

_________________
managarm


Top
 Profile  
 
 Post subject: Re: build script fails on linux host / no from 64 bit build.
PostPosted: Mon Feb 04, 2019 2:36 pm 
Offline

Joined: Fri Jan 04, 2019 6:05 am
Posts: 9
no92 wrote:
Hi,

a few things that I came across in about 30 seconds of browsing your repo:

1. You are using your system compiler against all advice on osdev. Please build a cross-compiler and see what output you get when using it. See GCC_Cross-Compiler

2. Why are you lying to your assembler, telling it that your code is should be output as elf64 when it isn't 64-bit?

3. Why are you creating a flat binary?

Your error means that it you are mixing 32-bit and 64-bit code in one binary, which probably has something to do with your usage of your system compiler. I assume it doesn't output elf32 for you.

Cheers, Leo



Initially this all worked on my macbook pro where I was using the cross compiler, I was under the impression that I needed that cross compiler because I was on mac and clang is missing some things. Are you saying that I need to use the cross-compiler regardless of my host OS? That would make sense is suppose but I want to be sure I understand you correctly.

as to the elf64 line, I made that change on the recommendation of a stack overflow post, I knew it was incorrect obviously as it was causing one of the problems mentioned in the post. This advice not solving my problem is the reason I came to this forum for this problem.

Please explain what you mean by "flat binary", does this refer to the fact that everything is being written into one file os-image at the end of the process? what is wrong with this? what are the alternatives?

thank you,
theOSdev

============

I have installed the i386 cross compiler and that works, I also have the x86_64 ccgcc and I will try that to see if it works as well.

I would appreciate you elaborating on the other question if you have the time. ie, what is flat binary? why is it bad?
much thanks.


Top
 Profile  
 
 Post subject: Re: build script fails on linux host / no from 64 bit build.
PostPosted: Mon Feb 04, 2019 4:34 pm 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 306
Location: Germany
Hi,

You should use a cross-compiler regardless of what OS you use, because it's the only way to know what you are targeting. You don't know what is targeted by the system's gcc (think of running the build on a RPi), and neither do you know what patches are applied to it or what options are enabled by default (In a recent thread, this became an issue when it started outputting position-independent code). Your linux gcc is targeted for x86_64, which is a wrong target for your use. Your point about macOS necessitating a cross-compiler is entirely correct, but only adds to the existing problem.

The solution for reproducable builds is a cross-compiler for your correct target, which probably (but I'm guessing) should be i686-elf-gcc.

Flat binaries are binaries stripped of everything but executable code, which in the long run will work against you. Loading a statically-linked ELF is no big deal and can be done in a second-stage bootloader, should you decide (for IMHO misguided reasons) to write one. Your kernel should be a proper executable (think ELF or PE) and be loaded from a file system.

Cheers, Leo

_________________
managarm


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 64 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group