Page 1 of 1
A problem about cross-compiler ld
Posted: Tue Jul 12, 2022 9:29 am
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?
Re: A problem about cross-compiler ld
Posted: Tue Jul 12, 2022 10:08 am
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.
Re: A problem about cross-compiler ld
Posted: Tue Jul 12, 2022 2:17 pm
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!
Re: A problem about cross-compiler ld
Posted: Tue Jul 12, 2022 10:22 pm
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.
Re: A problem about cross-compiler ld
Posted: Wed Jul 13, 2022 3:01 am
by iansjack
Shouldn't that be 2MiB rather than 4?
Re: A problem about cross-compiler ld
Posted: Wed Jul 13, 2022 12:41 pm
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.
Re: A problem about cross-compiler ld
Posted: Thu Jul 14, 2022 10:57 am
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