A problem about cross-compiler ld

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
theflysong
Member
Member
Posts: 27
Joined: Wed Jun 29, 2022 2:17 am
Libera.chat IRC: theflysong

A problem about cross-compiler ld

Post by theflysong »

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.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: A problem about cross-compiler ld

Post by kzinti »

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.
theflysong
Member
Member
Posts: 27
Joined: Wed Jun 29, 2022 2:17 am
Libera.chat IRC: theflysong

Re: A problem about cross-compiler ld

Post by theflysong »

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.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: A problem about cross-compiler ld

Post by MichaelPetch »

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.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: A problem about cross-compiler ld

Post by iansjack »

Shouldn't that be 2MiB rather than 4?
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: A problem about cross-compiler ld

Post by kzinti »

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.
theflysong
Member
Member
Posts: 27
Joined: Wed Jun 29, 2022 2:17 am
Libera.chat IRC: theflysong

Re: A problem about cross-compiler ld

Post by theflysong »

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.
Post Reply