This is the mail archive of the mailing list for the elfutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] libdwfl: elf_from_remote_memory only trust shdrs of last file-only segment.

On Mon, 10 Mar 2014 21:27:54 +0100, Mark Wielaard wrote:
> Normally we either get all of the shdrs or can easily detect that the
> end of the ELF file (where the shdrs are normally located) doesn't fall
> completely in the last segment mapped in. The exception is needed only
> in some corner cases that are not that common (basically when the
> sections have been reordered in such a way that a NOBITS one falls at
> the end of the last PT_LOAD segement).
> The reproducer I have here is on RHEL6 (the one from
> firefox-24.3.0-2.el6_5.x86_64 specifically. It has been processed by
> Which places the .bss at the end.

  Start of section headers:          96264 (bytes into file) = 0x17808
Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [26] .data             PROGBITS        0000000000617680 017680 000068 00  WA  0   0 16
  [27] .bss              NOBITS          00000000006176f0 0176e8 0003d8 00  WA  0   0 16
  [28] .gnu_debuglink    PROGBITS        0000000000000000 0176e8 000014 00      0   0  4
  [29] .shstrtab         STRTAB          0000000000000000 0176fc 000107 00      0   0  1
Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x016b94 0x016b94 R E 0x200000
  LOAD           0x017000 0x0000000000617000 0x0000000000617000 0x0006e8 0x000ac8 RW  0x200000

OK, got it now.

Just I do not agree with the 'segments_end == segments_end_mem'
and 'segments_end != segments_end_mem' conditions.  It does not try to test
where the sections headers are located, just the conditions themselves are
unrelated to the problem.  The conditions just accidentally match the Elfhack
specific layout but they may both miss similar problem with other layouts and
they also may have false positives.

I would rather adjust elf_from_remote_memory() so that it considers
'contents_size' to span
 * either just the first PT_LOAD segment
 * or just all non-writable PT_LOAD segments
or similar heuristics.  This is enough for all backtracing elfutils needs.
The former use has been only for vDSO which matches all heuristics one can

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x000000 0xffffffffff700000 0xffffffffff700000 0x000db0 0x000db0 R E 0x1000


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]