(t *testing.T)
| 411 | } |
| 412 | |
| 413 | func TestHeaderForFileOffset(t *testing.T) { |
| 414 | for _, tc := range []struct { |
| 415 | desc string |
| 416 | headers []*elf.ProgHeader |
| 417 | fileOffset uint64 |
| 418 | wantError bool |
| 419 | want *elf.ProgHeader |
| 420 | }{ |
| 421 | { |
| 422 | desc: "no headers, want error", |
| 423 | headers: nil, |
| 424 | wantError: true, |
| 425 | }, |
| 426 | { |
| 427 | desc: "three headers, BSS in last segment, file offset selects first header", |
| 428 | headers: []*elf.ProgHeader{ |
| 429 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}, |
| 430 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x1f0, Memsz: 0x1f0, Align: 0x200000}, |
| 431 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xe70, Vaddr: 0x400e70, Paddr: 0x400e70, Filesz: 0x90, Memsz: 0x100, Align: 0x200000}, |
| 432 | }, |
| 433 | fileOffset: 0xc79, |
| 434 | want: &elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}, |
| 435 | }, |
| 436 | { |
| 437 | desc: "three headers, BSS in last segment, file offset selects second header", |
| 438 | headers: []*elf.ProgHeader{ |
| 439 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}, |
| 440 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x1f0, Memsz: 0x1f0, Align: 0x200000}, |
| 441 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xe70, Vaddr: 0x400e70, Paddr: 0x400e70, Filesz: 0x90, Memsz: 0x100, Align: 0x200000}, |
| 442 | }, |
| 443 | fileOffset: 0xc80, |
| 444 | want: &elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x1f0, Memsz: 0x1f0, Align: 0x200000}, |
| 445 | }, |
| 446 | { |
| 447 | desc: "three headers, BSS in last segment, file offset selects third header", |
| 448 | headers: []*elf.ProgHeader{ |
| 449 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}, |
| 450 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x1f0, Memsz: 0x1f0, Align: 0x200000}, |
| 451 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xe70, Vaddr: 0x400e70, Paddr: 0x400e70, Filesz: 0x90, Memsz: 0x100, Align: 0x200000}, |
| 452 | }, |
| 453 | fileOffset: 0xef0, |
| 454 | want: &elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xe70, Vaddr: 0x400e70, Paddr: 0x400e70, Filesz: 0x90, Memsz: 0x100, Align: 0x200000}, |
| 455 | }, |
| 456 | { |
| 457 | desc: "three headers, BSS in last segment, file offset in uninitialized section selects third header", |
| 458 | headers: []*elf.ProgHeader{ |
| 459 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}, |
| 460 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x1f0, Memsz: 0x1f0, Align: 0x200000}, |
| 461 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xe70, Vaddr: 0x400e70, Paddr: 0x400e70, Filesz: 0x90, Memsz: 0x100, Align: 0x200000}, |
| 462 | }, |
| 463 | fileOffset: 0xf40, |
| 464 | want: &elf.ProgHeader{Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xe70, Vaddr: 0x400e70, Paddr: 0x400e70, Filesz: 0x90, Memsz: 0x100, Align: 0x200000}, |
| 465 | }, |
| 466 | { |
| 467 | desc: "three headers, BSS in last segment, file offset past any segment gives error", |
| 468 | headers: []*elf.ProgHeader{ |
| 469 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}, |
| 470 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x1f0, Memsz: 0x1f0, Align: 0x200000}, |
nothing calls this directly
no test coverage detected
searching dependent graphs…