OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: A problem about cross-compiler ld
PostPosted: Tue Jul 12, 2022 9:29 am 
Offline
Member
Member

Joined: Wed Jun 29, 2022 2:17 am
Posts: 27
When I use the cross-compiler ld, the size of executable is much larger
And there are too much zero between the elf header and the code section
The grub couldn't recognize the kernel because of it.
What's wrong with it?

_________________
I'm a new man to develop operating system.


Top
 Profile  
 
 Post subject: Re: A problem about cross-compiler ld
PostPosted: Tue Jul 12, 2022 10:08 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
It's probably aligning your code and data on 64 KB boundaries. You might want to change that to 4 KB and see if it fixes your problem.

You can do this by writing/updating your own link script or specify "-z max-page-size=0x1000" as a parameter to the linker.

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


Top
 Profile  
 
 Post subject: Re: A problem about cross-compiler ld
PostPosted: Tue Jul 12, 2022 2:17 pm 
Offline
Member
Member

Joined: Wed Jun 29, 2022 2:17 am
Posts: 27
kzinti wrote:
It's probably aligning your code and data on 64 KB boundaries. You might want to change that to 4 KB and see if it fixes your problem.

You can do this by writing/updating your own link script or specify "-z max-page-size=0x1000" as a parameter to the linker.

I followed your advice, and add the option to the linker.
Then it miraculously became normal!It's magic!
Thank you very much!

_________________
I'm a new man to develop operating system.


Top
 Profile  
 
 Post subject: Re: A problem about cross-compiler ld
PostPosted: Tue Jul 12, 2022 10:22 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
While you found the right solution, it has me curious if this was a 64-bit x86-64 cross compiler and tool chain? In that case the default page size is 4MiB when linking 64-bit ELF objects.


Top
 Profile  
 
 Post subject: Re: A problem about cross-compiler ld
PostPosted: Wed Jul 13, 2022 3:01 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Shouldn't that be 2MiB rather than 4?


Top
 Profile  
 
 Post subject: Re: A problem about cross-compiler ld
PostPosted: Wed Jul 13, 2022 12:41 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
MichaelPetch wrote:
it has me curious if this was a 64-bit x86-64 cross compiler and tool chain?

My aarch64 clang-12 linker does the same thing. Presumably linkers for other architectures can also use something else than 4KB alignment/padding.

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


Top
 Profile  
 
 Post subject: Re: A problem about cross-compiler ld
PostPosted: Thu Jul 14, 2022 10:57 am 
Offline
Member
Member

Joined: Wed Jun 29, 2022 2:17 am
Posts: 27
MichaelPetch wrote:
While you found the right solution, it has me curious if this was a 64-bit x86-64 cross compiler and tool chain? In that case the default page size is 4MiB when linking 64-bit ELF objects.

Yes, you are right

_________________
I'm a new man to develop operating system.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 7 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