ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.98k stars 2.48k forks source link

zig objcopy failed to extract binary when phdr have 0 as p_paddr #20019

Open cclin0816 opened 4 months ago

cclin0816 commented 4 months ago

https://github.com/ziglang/zig/blob/28476a5ee94d311319941b54e9da66210690ce70/lib/compiler/objcopy.zig#L400

I understand that p_paddr might be set to zero when not used. However, shouldn't zero also be a valid physical address?

When elf is linked with something like this:

SECTIONS
{
  . = load_offset;
  .text : AT(0) { *(.text) }
  .data : { *(.data) }
}

Trying to create binary with zig objcopy will either failed to seek, or produce binary with wrong layout. gnu objcopy and llvm-objcopy produces correct binary file.

Will it break things if newSegment.physicalAddress = phdr.p_paddr is used instead?

andrewrk commented 1 month ago

Will it break things if newSegment.physicalAddress = phdr.p_paddr is used instead?

seems fine to me