Skip to content

elf: apply implicit addends to object relocations - #2095

Open
raghav2005 wants to merge 1 commit into
cilium:mainfrom
raghav2005:fix/elf-object-relocation-addend
Open

elf: apply implicit addends to object relocations#2095
raghav2005 wants to merge 1 commit into
cilium:mainfrom
raghav2005:fix/elf-object-relocation-addend

Conversation

@raghav2005

Copy link
Copy Markdown

Summary

  • Resolve STT_OBJECT data-section relocations as S + A, preserving the SHT_REL implicit addend from the original LDIMM64 instruction.
  • Reject signed arithmetic overflow or underflow, offsets that cannot fit the pseudo-map-value encoding, and offsets outside the target section.
  • Add regression coverage for the minimal issue reproducer, the GCC values[8192] case, and arithmetic edge cases.

Testing

  • go test . -run '^TestRelocateDataSectionObjectAddend$' -count=1
  • CGO_ENABLED=1 go test -race . -run '^TestRelocateDataSectionObjectAddend$' -count=1
  • go build ./...
  • go vet ./...
  • go tool staticcheck ./...
  • golangci-lint run --timeout=5m
  • ./scripts/go-fix.sh
  • Cross-build and test compilation for Darwin, Android/arm64, Linux/armv6, and js/wasm

Fixes #2083

R_BPF_64_64 relocations use S + A, with the addend stored in the original LDIMM64 instruction for SHT_REL. Preserve that addend for STT_OBJECT data-section relocations instead of resolving them to S alone.

Validate signed addition, 32-bit encoding, and target-section bounds. Add regression coverage for issue cilium#2083, the GCC values[8192] case, and arithmetic edge cases.

Signed-off-by: Raghav <raghavawasthi2005@gmail.com>
@raghav2005
raghav2005 requested a review from a team as a code owner August 30, 2026 21:14
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.

STT_OBJECT Implicit Addend Handling Difference

1 participant