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?
A problem about cross-compiler ld
-
- Member
- Posts: 27
- Joined: Wed Jun 29, 2022 2:17 am
- Libera.chat IRC: theflysong
A problem about cross-compiler ld
I'm a new man to develop operating system.
Re: A problem about cross-compiler ld
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.
You can do this by writing/updating your own link script or specify "-z max-page-size=0x1000" as a parameter to the linker.
-
- Member
- Posts: 27
- Joined: Wed Jun 29, 2022 2:17 am
- Libera.chat IRC: theflysong
Re: A problem about cross-compiler ld
I followed your advice, and add the option to the linker.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.
Then it miraculously became normal!It's magic!
Thank you very much!
I'm a new man to develop operating system.
-
- Member
- Posts: 797
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
Re: A problem about cross-compiler ld
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
Shouldn't that be 2MiB rather than 4?
Re: A problem about cross-compiler ld
My aarch64 clang-12 linker does the same thing. Presumably linkers for other architectures can also use something else than 4KB alignment/padding.MichaelPetch wrote:it has me curious if this was a 64-bit x86-64 cross compiler and tool chain?
-
- Member
- Posts: 27
- Joined: Wed Jun 29, 2022 2:17 am
- Libera.chat IRC: theflysong
Re: A problem about cross-compiler ld
Yes, you are rightMichaelPetch 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.
I'm a new man to develop operating system.