[GR-68594] Native Image object file alignment issue for glibc. #12139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Shared native images linked with specific versions of the GNU binutils ld linker can cause the Linux dynamic loader to fail:
The toolchain this was tested with uses ld 2.38-17 from the Red Hat gcc-toolset-12 in combination with glibc 2.28.
Root Cause
On glibc <= 2.34: fails due to stricter check of the alignment for
PT_LOAD
sections.It checks whether the difference of address and offset is page-aligned, which is correct based on the ELF specification.
On glibc >= 2.35: relaxes the check to require that
PT_LOAD
sections are only aligned against the system's page size.Example
A shared native image linked with ld 2.38-17 may contain
PT_LOAD
segments that violate the ELF specification and makes glibc <= 2.34 fail:On glibc >= 2.35, if the system's page size is 4KiB (0x1000) this shared native image works.
Fixes
objcopy
re-aligns sections and makes shared native images usable for glibc <= 2.34. This is the currently implemented temporary fix that this PR aims to fix properly.-z common-page-size=
allows setting the default page size for the linker to use the native image page size. The downside of this approach is that it seems to slightly increase the native image size.