summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-08-04 22:36:48 +0200
committerMark Wielaard <mark@klomp.org>2018-09-14 00:52:48 +0200
commiteab0cf411128c0130d9284daf3bcd372d5384d3a (patch)
tree638a6c1c1e6057bdc55ff310a02a1f3239935433
parent7859092379225482ffd4b49de2d18ad2d69ce810 (diff)
libdwfl: Document core memory and remote memory ELF shdrs reading.
There are two places, dwfl_segment_report_module and elf_from_remote_memory in libdwfl where we use the Ehdr e_shnum directly. Document why this is fine. Getting the shdrs in those two places is really just a nice bonus and if there are more than 0xff00 then it is unlikely we will get them all anyway. Signed-off-by: Mark Wielaard <mark@klomp.org>
-rw-r--r--libdwfl/ChangeLog6
-rw-r--r--libdwfl/dwfl_segment_report_module.c6
-rw-r--r--libdwfl/elf-from-memory.c6
3 files changed, 18 insertions, 0 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 15d75114..5e9b986d 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2018-09-13 Mark Wielaard <mark@klomp.org>
+
+ * dwfl_segment_report_module.c (dwfl_segment_report_module):
+ Document why we use e_shnum directly.
+ * elf-from-memory.c (elf_from_remote_memory): Likewise.
+
2018-07-17 Ulf Hermann <ulf.hermann@qt.io>
* linux-pid-attach.c: Include sys/uio.h only on linux.
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 207a2573..36e5c823 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -367,6 +367,11 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
phentsize = ehdr.e32.e_phentsize;
if (phentsize != sizeof (Elf32_Phdr))
return finish ();
+ /* NOTE if the number of sections is > 0xff00 then e_shnum
+ is zero and the actual number would come from the section
+ zero sh_size field. We ignore this here because getting shdrs
+ is just a nice bonus (see below in consider_phdr PT_LOAD
+ where we trim the last segment). */
shdrs_end = ehdr.e32.e_shoff + ehdr.e32.e_shnum * ehdr.e32.e_shentsize;
break;
@@ -380,6 +385,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
phentsize = ehdr.e64.e_phentsize;
if (phentsize != sizeof (Elf64_Phdr))
return finish ();
+ /* See the NOTE above for shdrs_end and ehdr.e32.e_shnum. */
shdrs_end = ehdr.e64.e_shoff + ehdr.e64.e_shnum * ehdr.e64.e_shentsize;
break;
diff --git a/libdwfl/elf-from-memory.c b/libdwfl/elf-from-memory.c
index 12a0a1be..c54c1b99 100644
--- a/libdwfl/elf-from-memory.c
+++ b/libdwfl/elf-from-memory.c
@@ -139,6 +139,11 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
phentsize = ehdr.e32.e_phentsize;
if (phentsize != sizeof (Elf32_Phdr) || phnum == 0)
goto bad_elf;
+ /* NOTE if the number of sections is > 0xff00 then e_shnum
+ is zero and the actual number would come from the section
+ zero sh_size field. We ignore this here because getting shdrs
+ is just a nice bonus (see below where we trim the last phdrs
+ PT_LOAD segment). */
shdrs_end = ehdr.e32.e_shoff + ehdr.e32.e_shnum * ehdr.e32.e_shentsize;
break;
@@ -151,6 +156,7 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
phentsize = ehdr.e64.e_phentsize;
if (phentsize != sizeof (Elf64_Phdr) || phnum == 0)
goto bad_elf;
+ /* See the NOTE above for shdrs_end and ehdr.e32.e_shnum. */
shdrs_end = ehdr.e64.e_shoff + ehdr.e64.e_shnum * ehdr.e64.e_shentsize;
break;