OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:34 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: error: invalid arch-dependent ELF magic when using grub
PostPosted: Sat Jun 18, 2022 10:55 am 
Offline

Joined: Sat Jun 18, 2022 10:42 am
Posts: 9
i was trying to follow the bare bones tutorial with c++
i think the problem might be with my makefile so im gonna put it here

Code:
C_SOURCES = $(wildcard kernel/*.cpp libk/*.cpp libc/*.cpp)
HEADERS = $(wildcard kernel/*.hpp libk/*.hpp libc/*.hpp)
OBJ = ${C_SOURCES:.cpp=.o}

CC = i686-elf-g++
GDB = i686-elf-gdb
CFLAGS = -g -m32 -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs \
       -Wall -Wextra -fcommon

run: iota.iso
   qemu-system-i386 -cdrom iota.iso
   
iota.iso: kernel.bin
   cp kernel.bin isodir/boot/kernel.bin
   grub-mkrescue -o iota.iso isodir

kernel.bin: boot.o ${OBJ}
   i686-elf-ld -o $@ -T linker.ld $^ --oformat binary

boot.o: boot.s
   i686-elf-as boot.s -o boot.o

%.o: %.cpp ${HEADERS}
   ${CC} ${CFLAGS} -ffreestanding -c $< -o $@

clean:
   rm ${OBJ} iota.iso kernel.bin


i tried copying the boot.s code from the wiki page but it still keeps giving me the error
it might also be the c++ code so im gonna put that there too

Code:
//
//  kernel.cpp
//  iota
//
//  Created by Anthony Valdes on 2022-06-17.
//

#include "kernel.hpp"

extern "C" void kmain(void) {
   
}


the kernel.hpp file is empty apart from an include guard and the comment at the start


Top
 Profile  
 
 Post subject: Re: error: invalid arch-dependent ELF magic when using grub
PostPosted: Sun Jun 19, 2022 5:45 pm 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
Code:
kernel.bin: boot.o ${OBJ}
   i686-elf-ld -o $@ -T linker.ld $^ --oformat binary

If you're using the boot.s from the Bare Bones template on the wiki, it does not set up the Multiboot header with necessary information for making a flat binary readable by Grub - its Makefile builds an ELF binary, but your use of --oformat binary produces a raw binary. If this is what you want to do, you'll need to adjust the header you build to set the appropriate flag to tell Grub the address section of the Multiboot header is valid, and to set the appropriate values in it. You can read more about those entries in the header here: https://www.gnu.org/software/grub/manua ... ess-fields

Additionally, you should not set CC to a C++ compiler in a Makefile, and not all C sources will compile as C++, so be careful with that.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: error: invalid arch-dependent ELF magic when using grub
PostPosted: Mon Jun 20, 2022 10:16 am 
Offline

Joined: Sat Jun 18, 2022 10:42 am
Posts: 9
thanks i noticed that mistake before so i removed it and changed my makefile to use c instead of c++


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], MichaelPetch and 51 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