| ... | ... | @@ -4340,7 +4340,7 @@ pub fn dl_iterate_phdr( |
| 4340 | 4340 | |
| 4341 | 4341 | const elf_base = std.process.getBaseAddress(); |
| 4342 | 4342 | const ehdr = @intToPtr(*elf.Ehdr, elf_base); |
| 4343 | | // Make sure the base address points to an ELF image |
| 4343 | // Make sure the base address points to an ELF image. |
| 4344 | 4344 | assert(mem.eql(u8, ehdr.e_ident[0..4], "\x7fELF")); |
| 4345 | 4345 | const n_phdr = ehdr.e_phnum; |
| 4346 | 4346 | const phdrs = (@intToPtr([*]elf.Phdr, elf_base + ehdr.e_phoff))[0..n_phdr]; |
| ... | ... | @@ -4348,10 +4348,21 @@ pub fn dl_iterate_phdr( |
| 4348 | 4348 | var it = dl.linkmap_iterator(phdrs) catch unreachable; |
| 4349 | 4349 | |
| 4350 | 4350 | // The executable has no dynamic link segment, create a single entry for |
| 4351 | | // the whole ELF image |
| 4351 | // the whole ELF image. |
| 4352 | 4352 | if (it.end()) { |
| 4353 | // Find the base address for the ELF image, if this is a PIE the value |
| 4354 | // is non-zero. |
| 4355 | const base_address = for (phdrs) |*phdr| { |
| 4356 | if (phdr.p_type == elf.PT_PHDR) { |
| 4357 | break @ptrToInt(phdrs.ptr) - phdr.p_vaddr; |
| 4358 | // We could try computing the difference between _DYNAMIC and |
| 4359 | // the p_vaddr of the PT_DYNAMIC section, but using the phdr is |
| 4360 | // good enough (Is it?). |
| 4361 | } |
| 4362 | } else unreachable; |
| 4363 | |
| 4353 | 4364 | var info = dl_phdr_info{ |
| 4354 | | .dlpi_addr = 0, |
| 4365 | .dlpi_addr = base_address, |
| 4355 | 4366 | .dlpi_name = "/proc/self/exe", |
| 4356 | 4367 | .dlpi_phdr = phdrs.ptr, |
| 4357 | 4368 | .dlpi_phnum = ehdr.e_phnum, |
| ... | ... | @@ -4360,7 +4371,7 @@ pub fn dl_iterate_phdr( |
| 4360 | 4371 | return callback(&info, @sizeOf(dl_phdr_info), context); |
| 4361 | 4372 | } |
| 4362 | 4373 | |
| 4363 | | // Last return value from the callback function |
| 4374 | // Last return value from the callback function. |
| 4364 | 4375 | while (it.next()) |entry| { |
| 4365 | 4376 | var dlpi_phdr: [*]elf.Phdr = undefined; |
| 4366 | 4377 | var dlpi_phnum: u16 = undefined; |