OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 12:15 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: How to link without errors? [SOLVED, lmao so easy]
PostPosted: Sun Oct 09, 2016 4:45 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
Original question i asked on SO: http://stackoverflow.com/questions/3991 ... -linker-ld
I am currently following the Bare Bones tutorial from OSDev and i have set up everything and compiled the kernel and bootloader into object files, and i have the .ld file. However, when i try to link the files and produce it into a bin using:
Code:
i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc
, i get this error:

"
Code:
.../i686/bin/../lib/gcc/i686-elf/4.8.2/../../../../i686-elf/bin/ld.exe: cannot open linker script file linker.ld

collect2.exe: error: ld returned 1 exit status
"

I know what "ld returned 1 exit status" means (ld has gotten a error, not a error itself, just indicating errors.). The other solutions i have tried either give more errors or do absolutely nothing. Adding -T does nothing. I'm using Windows 10 and have the .exe's and etc. from a source which i don't have the link to, and i'm using GCC. I also put 4 dll's for gcc to work without errors. I have already compiled the assembly and C into object files, but nothing. I removed every part that has to do with GRUB/Multiboot except protected mode (possibly) and 32 bit code, and there are no errors in the code. I've never seen a solution that involves "cannot open linker script file linker.ld", and linking by default either literally ignores every piece of assembly code beacuse it's not "machine code" (it is, normally ignores /001 or /000 or /003 or &) or gives the same error (possibly with a few more errors).

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Last edited by NunoLava1998 on Mon Oct 10, 2016 2:51 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Sun Oct 09, 2016 4:55 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
The error message seems quite clear. Either linker.ld does not exist in the current working directory or its permissions forbid you access.


Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Sun Oct 09, 2016 4:59 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
iansjack wrote:
The error message seems quite clear. Either linker.ld does not exist in the current working directory or its permissions forbid you access.

So where can i get linker.ld then?

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Sun Oct 09, 2016 5:03 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
http://wiki.osdev.org/Bare_Bones#Linking_the_Kernel


Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Sun Oct 09, 2016 5:08 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
iansjack wrote:
http://wiki.osdev.org/Bare_Bones#Linking_the_Kernel


Oh, just realized i didn't name my linker "linker.ld". #-o :lol:

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Sun Oct 09, 2016 5:13 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
And now it's giving a syntax error on linker.ld saying the code between the triple parenthesis is incorrect (the real code doesn't include the paranthesis and i don't want the OS to be started with GRUB) in this code is incorrect:
Code:
ENTRY(_start)

SECTIONS
{

   . = 1M;



   .rodata BLOCK(4K) : ALIGN(4K)
   {
      *(.rodata)
   }


   .data BLOCK(4K) : ALIGN(4K)
   {
      *(.data)
   }


   .bss BLOCK(4K) : ALIGN(4K)
   {
      *(COMMON)
      *(.bss)
   }


((( } )))

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Sun Oct 09, 2016 5:17 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
nvm, got it working. it was the return 0; i had put, lol now it's linked and i can make a quick bat file to make the linked .bin finally

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Sun Oct 09, 2016 5:20 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
How are you going to boot the kernel if you don't use GRUB?


Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Sun Oct 09, 2016 6:22 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
@iansjack a 512 byte bootloader which should load sector 2, which contains the ASM file to load the C file and it's headers and link.ld. i have dd to place the code into sector 2 (it can extend beyond sector 2, it just starts at sector 2).

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS


Top
 Profile  
 
 Post subject: Re: How to link without errors?
PostPosted: Wed Oct 12, 2016 10:41 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
NunoLava1998 wrote:
@iansjack a 512 byte bootloader which should load sector 2, which contains the ASM file to load the C file and it's headers and link.ld. i have dd to place the code into sector 2 (it can extend beyond sector 2, it just starts at sector 2).


Is there a compelling reason why you want to write your own boot loader?

(NB: just saying "I want to learn how to write one" is enough to count, though I would caution against then using that boot loader as your OS loader unless you are willing to spend more time on the boot loader than on the rest of the OS and dealing with an excessive amount of frustration along the way.)

The boot loader is a very small part of the system, takes a disproportionate amount of development time for its significance, and is very difficult to get right to a production scale (even for a hobbyist level of 'production'), which is why we usually recommend going with an existing boot loader for your actual OS.

There are reasons to write your own boot loader, but the are usually not very good ones. While I am intending to write one myself, it is because my own system is meant to use a very anomalous document system that doesn't play well with conventional file structures, and because I think I might be able to improve on GRUB (unlikely, but why not try?). In the end, though, I realize I am driven by egotism rather than rational goals, and have accepted that.

The point is that you need to think of both your motivations and your goals before committing to a substantial project that is, in the final analysis, likely to be a detour rather than a direct route. Will writing your own boot loader teach you anything significant? Possibly; it can serve as a decent warm-up for more complex problems. Does it further your goal of writing an operating system? Probably not, unless you are doing something very exotic with the file system or the boot sequence. I suggest you give that some thought before going further.

And set up a repo on somewhere like GitHub or Cloudforge. Seriously, you will come to regret it if you don't, and it would make showing us your code problems a loooot easier.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 44 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