OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 11:00 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Re-ordering linker sections in ELF file
PostPosted: Sat Aug 08, 2020 11:59 pm 
Offline

Joined: Sun May 10, 2020 9:47 pm
Posts: 8
I'm working on transfering my barebones OS to 64 bit, and was running into issues getting my multiboot header within the first 8k of my ELF file.

I've read countless posts on the forums suggesting that this is the correct way to put your multiboot header at the beginning (assuming your multiboot header is in a section called .multiboot):

Code:
KERNEL_LOW = 0x100000;

SECTIONS
{
    . = KERNEL_LOW;

   .multiboot ALIGN(4K) : AT (ADDR (.multiboot) - KERNEL_LOW)
   {
      KEEP(*(.multiboot))
   }

   .text ALIGN(4K)  : AT (ADDR (.text) - KERNEL_LOW)
   {
      *(.text)
   }
}


This does not work at all. When using " x86_64-elf-readelf -a kernel/myos.kernel" its clear that the .text section is the first section in the ELF file at an offset of 0x1000, and the multiboot section is being placed near the end at 0xa400, which is well above the 8k required for the multiboot header to be found.

What I found does work is defining .multiboot in the same section as .text like this:

Code:
KERNEL_LOW = 0x100000;

SECTIONS
{
    . = KERNEL_LOW;

   .text ALIGN(4K)  : AT (ADDR (.text) - KERNEL_LOW)
   {
      KEEP(*(.multiboot))
      *(.text)
   }
}


Here, .text remains the first section at an offset of 0x1000 and .multiboot is at the beginning of it, allowing the multiboot header to be found.

Is the .text section always the first usable section at the lowest offset in an ELF file? If its not, how can I define the layout of the sections so that I can get a custom .multiboot section (like in my first example) at the beginning of my ELF. I've heard all forms of nonsense on how to get the multiboot section at the beginning of an ELF file on this forum and I want to set it straight here so no one has to go through this again.


Top
 Profile  
 
 Post subject: Re: Re-ordering linker sections in ELF file
PostPosted: Mon Aug 10, 2020 7:40 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
Did you pass -z max-page-size=4096 to the linker?

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Re-ordering linker sections in ELF file
PostPosted: Tue Aug 11, 2020 9:30 pm 
Offline

Joined: Sun May 10, 2020 9:47 pm
Posts: 8
nexos wrote:
Did you pass -z max-page-size=4096 to the linker?


Yeah, I've been passing -z max-page-size=0x1000 to the linker


Top
 Profile  
 
 Post subject: Re: Re-ordering linker sections in ELF file
PostPosted: Wed Aug 12, 2020 10:11 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Just keep the multiboot header in the .text section... That's what I do and it works just fine. Is this causing you a problem?

_________________
https://github.com/kiznit/rainbow-os


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 199 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