Skip to content

fix(build): align Go ELF segments to 64KB for aarch64 64K-page kernels#915

Open
Pangjiping wants to merge 1 commit into
alibaba:mainfrom
Pangjiping:fix/aarch64-64k-page-alignment
Open

fix(build): align Go ELF segments to 64KB for aarch64 64K-page kernels#915
Pangjiping wants to merge 1 commit into
alibaba:mainfrom
Pangjiping:fix/aarch64-64k-page-alignment

Conversation

@Pangjiping
Copy link
Copy Markdown
Collaborator

Summary

Pass -R 0x10000 to Go's linker so PT_LOAD segments are aligned to 64KB in every Go binary build (execd, ingress, egress, controller, task-executor, image-committer). Without this, ELF binaries built for amd64 use 4KB segment alignment by default and fail to load on aarch64 kernels configured with CONFIG_ARM64_64K_PAGES=y (NVIDIA Grace Hopper, ARM Neoverse-V2 HPC, RHEL/CentOS aarch64+64k variants). The flag is also applied to arm64 builds to lock the alignment in case Go's default ever regresses.

Closes #853.

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

Pass `-R 0x10000` to Go's linker so PT_LOAD segments are aligned to 64KB
in every Go binary build (execd, ingress, egress, controller,
task-executor, image-committer). Without this, ELF binaries built for
amd64 use 4KB segment alignment by default and fail to load on aarch64
kernels configured with CONFIG_ARM64_64K_PAGES=y (NVIDIA Grace Hopper,
ARM Neoverse-V2 HPC, RHEL/CentOS aarch64+64k variants). The flag is also
applied to arm64 builds to lock the alignment in case Go's default ever
regresses.

Refs alibaba#853.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02a8e07ef4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 60 to 62
RUN CGO_ENABLED=0 GOOS=windows go build ${GOFLAGS} -trimpath -buildvcs=false \
-ldflags "${LDFLAGS} -buildid= -B none \
-ldflags "${LDFLAGS} -buildid= -B none -R 0x10000 \
-X 'github.com/alibaba/opensandbox/internal/version.Version=${VERSION}' \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove -R from the Windows execd build

When this Dockerfile reaches the GOOS=windows step, the Go linker rejects -R 0x10000 for PE output (I checked go tool link -h, where -R is the address rounding quantum, and a Go 1.25.1 GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-buildid= -B none -R 0x10000' fails with .data.VirtualAddress = 0xff000, want 0x100000). That makes every execd image build fail before the runtime stage, even though the 64K-page fix is only needed for Linux ELF binaries.

Useful? React with 👍 / 👎.

Comment thread components/execd/Makefile
# aarch64 kernels built with CONFIG_ARM64_64K_PAGES=y (e.g. NVIDIA Grace,
# RHEL aarch64+64k). Go's internal linker honours this for ELF/PE; on Mach-O
# the value just affects layout. See issue #853.
PROJECT_LDFLAGS := -buildid= -B none -R 0x10000 -X 'github.com/alibaba/opensandbox/internal/version.Version=$(VERSION)' \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep -R out of multi-build's Windows targets

PROJECT_LDFLAGS is reused by make multi-build, whose loop includes windows/amd64 and windows/arm64; with this added -R 0x10000, the first Windows cross-compile fails in the linker (.data.VirtualAddress = 0xff000, want 0x100000 with Go 1.25.1). This breaks the documented multi-platform execd release build even though only the Linux ELF artifacts need the 64K PT_LOAD alignment.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown
Contributor

⚠️ This PR has no labels. Please add one based on the changes.

Changed directories: components、kubernetes.

📋 Recommended labels (based on changed files):

  • component/egress ⬅️
  • component/execd ⬅️
  • component/ingress ⬅️
  • component/k8s ⬅️

Other available labels:

  • bug - Something isn't working
  • dependencies - Pull requests that update a dependency file
  • documentation - Improvements or additions to documentation
  • feature - New feature or request
  • packages - Changes for package, image and configuration

💡 Tip: Use feature for new functionality or improvements, bug for fixes.

cc @Pangjiping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Go binaries may crash on aarch64 with 64KB page size kernel

1 participant