Skip to content

PHDR segment not covered by a LOAD segment after repeated rewrites #675

Closed

Description

@asp345

Describe the bug

Patching an ET_EXEC twice with master (3e996db) leaves the program header table outside its LOAD segment, and on aarch64 the next rewrite aborts.

  • x86_64: after --add-needed, readelf -l says the PHDR segment is not covered by a LOAD segment. The next --add-rpath doesn't fix it.
  • aarch64: same readelf error after --add-needed, then --add-rpath dies with Assertion 'curOff == neededSpace' failed.

Both findLoadSegmentByOffset() calls in rewriteSectionsExecutable() pass the offset right after the program header table (headerEnd, later curOff). A header LOAD that ends at or before that offset isn't found, so it's neither reused nor extended.

Steps To Reproduce

Grpc.Tools 2.83.0 from https://www.nuget.org/api/v2/package/Grpc.Tools/2.83.0, tools/linux_x64/protoc and tools/linux_arm64/protoc.

protoc=tools/linux_x64/protoc   # and again with tools/linux_arm64/protoc
patchelf --set-interpreter /tmp/some/longer/ld-linux-x86-64.so.2 "$protoc"
patchelf --add-needed libicui18n.so --add-needed libicuuc.so \
         --add-needed libz.so --add-needed libssl.so "$protoc"
readelf -lW "$protoc" >/dev/null
patchelf --add-rpath /tmp/lib "$protoc"

Result with 3e996db:

x86_64:  readelf -lW: Error: the PHDR segment is not covered by a LOAD segment
aarch64: readelf -lW: Error: the PHDR segment is not covered by a LOAD segment
         patchelf: patchelf.cc:1243: ...: Assertion `curOff == neededSpace' failed.

Expected behavior

readelf -l should be clean after every step and repeated rewrites shouldn't abort.

patchelf --version output

patchelf 0.19.2, built from 3e996db.

Additional context

Reported at the end of #672 (comment).

Not #663 (big-endian MIPS/ARM with large p_align).

Activity

  1. added a commit that references this issue on Oct 29, 2026
    964670e
  2. added a commit that references this issue on Oct 31, 2026
    ed1f192
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions