ld problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
houbOS1
Posts: 7
Joined: Tue Jan 22, 2008 1:34 pm

ld problem

Post by houbOS1 »

Hi, I was trying to make my first Os, with the tutorial on this webpage : http://osdever.net/bkerndev/Docs/creatingmain.htm, I checked my main with the solution, but gcc said me a lot of errors, so I was trying to just make a main() like that:

Code: Select all

void main() {}
To just see if the linking works...
And the booting_new.asm like that:

Code: Select all

; This is the kernel's entry point. We could either call main here,
; or we can use this to setup the stack or other nice stuff, like
; perhaps setting up the GDT and segments. Please note that interrupts
; are disabled at this point: More on interrupts later!
[BITS 32]
global start
start:
    mov esp, _sys_stack     ; This points the stack to our new stack area
    jmp stublet

; This part MUST be 4byte aligned, so we solve that issue using 'ALIGN 4'
ALIGN 4
mboot:
    ; Multiboot macros to make a few lines later more readable
    MULTIBOOT_PAGE_ALIGN	equ 1<<0
    MULTIBOOT_MEMORY_INFO	equ 1<<1
    MULTIBOOT_AOUT_KLUDGE	equ 1<<16
    MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
    EXTERN code, bss, end

    ; This is the GRUB Multiboot header. A boot signature
    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM
    
    ; AOUT kludge - must be physical addresses. Make a note of these:
    ; The linker script fills in the data for these ones!
    dd mboot
    dd code
    dd bss
    dd end
    dd start

; This is an endless loop here. Make a note of this: Later on, we
; will insert an 'extern _main', followed by 'call _main', right
; before the 'jmp $'.
stublet:
    extern _main
    call _main
    jmp $


; Shortly we will add code for loading the GDT right here!


; In just a few pages in this tutorial, we will add our Interrupt
; Service Routines (ISRs) right here!



; Here is the definition of our BSS section. Right now, we'll use
; it just to store the stack. Remember that a stack actually grows
; downwards, so we declare the size of the data before declaring
; the identifier '_sys_stack'
SECTION .bss
    resb 8192               ; This reserves 8KBytes of memory here
_sys_stack:
I was using this bat file for compiling and linking :

Code: Select all


Q:\osdev>nasm -f aout -o start.o booting_new.asm 

Q:\osdev>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c 

Q:\osdev>ld -T link.ld -o kernel.bin start.o main.o 

Q:\osdev>echo Done! 
Done!

Q:\osdev>pause
Press any key to continue . . . 
but the linker said : start.o : file not recognized : File format not recognized.

Does anyone know what am I doing wrong? If you need more info, feel free to ask... I really don't know what's going on with that...

Thanks for your help!!!

EDIT: I was trying too to change the output format of nasm, for example elf, win32, but all of these did not work.
This time, the error was :"PE operations on non PE file.".
PLEASE help.
User avatar
crazygray1
Member
Member
Posts: 168
Joined: Thu Nov 22, 2007 7:18 pm
Location: USA,Hawaii,Honolulu(Seriously)

Post by crazygray1 »

first Os
First? :shock: I doubt many people make more than one. [/code]
Codname: Cipher
Working On: Design Doc(CFFS file system)
User avatar
Wave
Member
Member
Posts: 50
Joined: Sun Jan 20, 2008 5:51 am

Post by Wave »

You probably want to build a cross compiler like described in the wiki. It will solve your problem.
Conway's Law: If you have four groups working on a compiler, you'll get a 4-pass compiler.
Melvin Conway
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

I've built more than one OS.

And this isn't a cross-compiler problem, iirc.

Try using "-f elf" instead of "-f aout" in your nasm line.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

he's using microsoft produce. And he said that he tried elf/win32 targets already :roll:

So yes, I do think it has something to do with not using a GCC Cross-Compiler
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
houbOS1
Posts: 7
Joined: Tue Jan 22, 2008 1:34 pm

Post by houbOS1 »

Yes, I have tried formats like elf, etc.
I will try the cross-compilers, I know nothing about it so I will learn...
Anyway thx for replies!
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Combuster wrote:he's using microsoft produce. And he said that he tried elf/win32 targets already :roll:

So yes, I do think it has something to do with not using a GCC Cross-Compiler
Don't roll your eyes at me, you can quite clearly see that he added that as an edit. :roll:
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

crazygray1 wrote:
first Os
First? :shock: I doubt many people make more than one. [/code]
I think most people never make an OS. As for those who do, I think many will start, quit, start again, quit again, etc. until they finally have something that works to their taste. Of course, you could also call that 'evolution of a single OS' and call that 'Fenestra 1.0' through '8', it's just what you'd define as an 'OS'.


JAL
houbOS1
Posts: 7
Joined: Tue Jan 22, 2008 1:34 pm

reply

Post by houbOS1 »

That's weird. You know what was the error? My compiler don't put underthings (_) before the name of the function. When I put the underscore in main.c, it works.
gr8
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: reply

Post by jal »

houbOS1 wrote:That's weird. You know what was the error? My compiler don't put underthings (_) before the name of the function. When I put the underscore in main.c, it works.
That's not weird per se. Many compilers have an option to enable or disable trailing underscores. Most C compilers do it by default, most assemblers don't do it by default.


JAL
Post Reply