(t *testing.T)
| 118 | } |
| 119 | |
| 120 | func TestFindProgHeaderForMapping(t *testing.T) { |
| 121 | buildList := func(headers []*elf.ProgHeader) (result string) { |
| 122 | builder := strings.Builder{} |
| 123 | if err := builder.WriteByte('['); err != nil { |
| 124 | t.Error("Failed to append '[' to the builder") |
| 125 | } |
| 126 | defer func() { |
| 127 | if err := builder.WriteByte(']'); err != nil { |
| 128 | t.Error("Failed to append ']' to the builder") |
| 129 | } |
| 130 | result = builder.String() |
| 131 | }() |
| 132 | if len(headers) == 0 { |
| 133 | if _, err := builder.WriteString("nil"); err != nil { |
| 134 | t.Error("Failed to append 'nil' to the builder") |
| 135 | } |
| 136 | return |
| 137 | } |
| 138 | if _, err := builder.WriteString(fmt.Sprintf("%#v", *headers[0])); err != nil { |
| 139 | t.Error("Failed to append first header to the builder") |
| 140 | } |
| 141 | for i, h := range headers[1:] { |
| 142 | if _, err := builder.WriteString(fmt.Sprintf(", %#v", *h)); err != nil { |
| 143 | t.Errorf("Failed to append header %d to the builder", i+1) |
| 144 | } |
| 145 | } |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | // Various ELF program headers for unit tests. |
| 150 | tinyHeaders := []elf.ProgHeader{ |
| 151 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}, |
| 152 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x1f0, Memsz: 0x1f0, Align: 0x200000}, |
| 153 | } |
| 154 | tinyBadBSSHeaders := []elf.ProgHeader{ |
| 155 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0xc80, Memsz: 0xc80, Align: 0x200000}, |
| 156 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xc80, Vaddr: 0x200c80, Paddr: 0x200c80, Filesz: 0x100, Memsz: 0x1f0, Align: 0x200000}, |
| 157 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xd80, Vaddr: 0x400d80, Paddr: 0x400d80, Filesz: 0x90, Memsz: 0x90, Align: 0x200000}, |
| 158 | } |
| 159 | smallHeaders := []elf.ProgHeader{ |
| 160 | {Type: elf.PT_PHDR, Flags: elf.PF_R | elf.PF_X, Off: 0x40, Vaddr: 0x400040, Paddr: 0x400040, Filesz: 0x1f8, Memsz: 0x1f8, Align: 8}, |
| 161 | {Type: elf.PT_INTERP, Flags: elf.PF_R, Off: 0x238, Vaddr: 0x400238, Paddr: 0x400238, Filesz: 0x1c, Memsz: 0x1c, Align: 1}, |
| 162 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0x400000, Paddr: 0x400000, Filesz: 0x6fc, Memsz: 0x6fc, Align: 0x200000}, |
| 163 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xe10, Vaddr: 0x600e10, Paddr: 0x600e10, Filesz: 0x230, Memsz: 0x238, Align: 0x200000}, |
| 164 | {Type: elf.PT_DYNAMIC, Flags: elf.PF_R | elf.PF_W, Off: 0xe28, Vaddr: 0x600e28, Paddr: 0x600e28, Filesz: 0x1d0, Memsz: 0x1d0, Align: 8}, |
| 165 | } |
| 166 | smallBadBSSHeaders := []elf.ProgHeader{ |
| 167 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0x200000, Paddr: 0x200000, Filesz: 0x6fc, Memsz: 0x6fc, Align: 0x200000}, |
| 168 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0x700, Vaddr: 0x400700, Paddr: 0x400700, Filesz: 0x500, Memsz: 0x710, Align: 0x200000}, |
| 169 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0xe10, Vaddr: 0x600e10, Paddr: 0x600e10, Filesz: 0x230, Memsz: 0x238, Align: 0x200000}, |
| 170 | } |
| 171 | mediumHeaders := []elf.ProgHeader{ |
| 172 | {Type: elf.PT_PHDR, Flags: elf.PF_R, Off: 0x40, Vaddr: 0x40, Paddr: 0x40, Filesz: 0x2d8, Memsz: 0x2d8, Align: 8}, |
| 173 | {Type: elf.PT_INTERP, Flags: elf.PF_R, Off: 0x318, Vaddr: 0x318, Paddr: 0x318, Filesz: 0x28, Memsz: 0x28, Align: 1}, |
| 174 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_X, Off: 0, Vaddr: 0, Paddr: 0, Filesz: 0x354ca0, Memsz: 0x354ca0, Align: 0x200000}, |
| 175 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0x400000, Vaddr: 600000, Paddr: 600000, Filesz: 0x0083b8, Memsz: 0x009000, Align: 0x200000}, |
| 176 | {Type: elf.PT_LOAD, Flags: elf.PF_R | elf.PF_W, Off: 0x600000, Vaddr: 0xa00000, Paddr: 0xa00000, Filesz: 0x007030, Memsz: 0x9cf090, Align: 0x200000}, |
| 177 | {Type: elf.PT_LOAD, Flags: elf.PF_R, Off: 0x7cf090, Vaddr: 0x15cf090, Paddr: 0x15cf090, Filesz: 0x028460, Memsz: 0x028460, Align: 0x200000}, |
nothing calls this directly
no test coverage detected
searching dependent graphs…