Skip to content

sea: keep ELF segments on separate pages in --build-sea output - #65564

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:fix/sea-elf-phdr-placement
Open

sea: keep ELF segments on separate pages in --build-sea output#65564
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:fix/sea-elf-phdr-placement

Conversation

@codebytere

Copy link
Copy Markdown
Member

The sea/* failures on the rhel8-x64 CI hosts (SIGSEGV, empty stderr, https://github.com/nodejs/reliability/blob/main/reports/2026-08-26.md) come with a kernel line, elf segment at ... requested but the memory is mapped already (nodejs/build#4433 (comment)), which is execve refusing the injected executable. When node is not PIE (RHEL toolchains, and the official Linux binaries), LIEF makes room for the new program header by moving the header table into the largest gap between two PT_LOAD segments and extending the earlier segment across it; when that gap is the one between the read-only data and the read-write segment, whose boundary is not page aligned, the extended segment ends inside the next segment's first page. Linux 4.17 to 5.3 and RHEL 8's 4.18 map an executable's segments with MAP_FIXED_NOREPLACE, so the second mapping fails past the point of no return and the process is killed; newer kernels don't check. Which gap is largest depends on section sizes, so it comes and goes from build to build.

This asks LIEF for its after-.bss placement when the executable is ET_EXEC, which leaves every existing segment where the linker put it and gives the header table pages of its own; the output grows by the size of .bss (about 340 KB for node). PIE builds are unchanged. postject makes the same choice in its own copy of LIEF, so test-single-executable-application.js and test_sea_addon, which still inject with it, aren't covered by this.

Tests:

  • new test/sea/test-build-sea-elf-segments.js asserts no two PT_LOAD segments of a --build-sea executable share a page; test/sea passes
  • reproduced off CI with a non-PIE node built with RHEL 8's clang whose read-only/read-write gap is the largest: on AlmaLinux 8.10 (4.18.0-553.150.1.el8_10) the SEA built before this change segfaults with the same kernel line and the one built after it runs; both run on a 6.12 kernel

Refs: nodejs/build#4433


Disclosure: the code, test, investigation and this description were written by Claude Code, directed and reviewed by @codebytere.

When node itself is not position independent (the official Linux
binaries, and any build with a toolchain that does not default to PIE),
LIEF made room for the extra program header by moving the header table
into the largest gap between two PT_LOAD segments and extending the
earlier segment across that gap. Whenever the gap it picked was the one
between the read-only data and the read-write segment, whose boundary
is not page aligned, the extended segment ended inside the first page
of the next one. Linux 4.17 to 5.3, and RHEL 8's 4.18 kernel, map an
executable's segments with MAP_FIXED_NOREPLACE and refuse the second
mapping, so the single executable was killed with SIGSEGV before it ran
a single instruction ('elf segment at ... requested but the memory is
mapped already' in the kernel log). Which gap is largest depends on
section sizes, so roughly one build in three produced such binaries.

Ask LIEF to place the table after .bss for non-PIE executables instead,
which leaves every existing segment as the linker laid it out; the
output grows by the size of .bss. A test checks that no two PT_LOAD
segments of a --build-sea executable share a page.

Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/single-executable

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. single-executable Issues and PRs related to single-executable applications labels Aug 26, 2026

@panva panva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

RSLGTM

@panva panva added fast-track PRs that do not need to wait for 48 hours to land. author ready PRs that have at least one approval, no outstanding review comments, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. review wanted PRs that need reviews. labels Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Fast-track has been requested by @panva. Please 👍 to approve.

@nodejs-github-bot

This comment has been minimized.

@sxa

sxa commented Aug 26, 2026

Copy link
Copy Markdown
Member

That's not ideal - merge conflict on the rhel8-x64 machine
https://ci.nodejs.org/job/node-test-commit-linux/72453/nodes=rhel8-x64/console

Attempting a test in the stress job with 100 iterations: rhel8-x64 and rhel9-x64 as we really need the results on rhel8-x64 ASAP.

@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.06%. Comparing base (7b6b21a) to head (84be637).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sea_bin.cc 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #65564   +/-   ##
=======================================
  Coverage   90.05%   90.06%           
=======================================
  Files         751      751           
  Lines      254420   254423    +3     
  Branches    47975    47986   +11     
=======================================
+ Hits       229121   229148   +27     
+ Misses      16483    16444   -39     
- Partials     8816     8831   +15     
Files with missing lines Coverage Δ
src/node_sea_bin.cc 41.07% <0.00%> (-0.45%) ⬇️

... and 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@panva panva added the flaky-test Issues and PRs related to the tests with unstable failures on the CI. label Aug 26, 2026

@sxa sxa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Annoying (as usual...) but https://ci.nodejs.org/job/node-stress-single-test/nodes=rhel8-x64/848/console which was without this patch seemed to be passing too. But on the basis this has been tested in an environment where it was reproducible I'm approving.

Out of interest, did you manage to come to any conclusion abot what change could have caused this to start going wrong recently given that it doesn't seem to have been package updates?

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. fast-track PRs that do not need to wait for 48 hours to land. flaky-test Issues and PRs related to the tests with unstable failures on the CI. needs-ci PRs that need a full CI run. review wanted PRs that need reviews. single-executable Issues and PRs related to single-executable applications

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants