Skip to content

Conversation

graalvmbot
Copy link
Collaborator

Problem

Shared native images linked with specific versions of the GNU binutils ld linker can cause the Linux dynamic loader to fail:

$ ldd helloworld.so
	not a dynamic executable

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:

LOAD           0x387db8 0x0000000000388db8 0x0000000000388db8 0x000370 0x000370 RW  0x10000
contents of the segment: .init_array .fini_array .data.rel.ro .dynamic .got .got.plt

On glibc >= 2.35, if the system's page size is 4KiB (0x1000) this shared native image works.

Fixes

  • Running 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.
  • Make sure that the linker uses the correct page size for aligning segments in object files. The option -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.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 10, 2025
@graalvmbot graalvmbot merged commit 8fa980f into master Sep 10, 2025
13 checks passed
@graalvmbot graalvmbot deleted the doma/GR-68594 branch September 10, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants