Mark Wielaard 36e4b6
commit abe8793d216293af960a0334401795bf74945705
Mark Wielaard 36e4b6
Author: sewardj <sewardj@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Mark Wielaard 36e4b6
Date:   Thu Nov 8 15:45:16 2012 +0000
Mark Wielaard 36e4b6
Mark Wielaard 36e4b6
    Ignore ELF sections that have zero size.  Fixes #309600.
Mark Wielaard 36e4b6
    (Dragos Tatulea, dragos.tatulea@gmail.com)
Mark Wielaard 36e4b6
    
Mark Wielaard 36e4b6
    
Mark Wielaard 36e4b6
    
Mark Wielaard 36e4b6
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13109 a5019735-40e9-0310-863c-91ae7b9d1cf9
Mark Wielaard 36e4b6
Mark Wielaard 36e4b6
diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
Mark Wielaard 36e4b6
index d78dc7a..2d08b67 100644
Mark Wielaard 36e4b6
--- a/coregrind/m_debuginfo/readelf.c
Mark Wielaard 36e4b6
+++ b/coregrind/m_debuginfo/readelf.c
Mark Wielaard 36e4b6
@@ -1713,7 +1713,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
       UChar* name = shdr_strtab_img + shdr->sh_name;
Mark Wielaard 36e4b6
       Addr   svma = shdr->sh_addr;
Mark Wielaard 36e4b6
       OffT   foff = shdr->sh_offset;
Mark Wielaard 36e4b6
-      UWord  size = shdr->sh_size;
Mark Wielaard 36e4b6
+      UWord  size = shdr->sh_size; /* Do not change this to be signed. */
Mark Wielaard 36e4b6
       UInt   alyn = shdr->sh_addralign;
Mark Wielaard 36e4b6
       Bool   bits = !(shdr->sh_type == SHT_NOBITS);
Mark Wielaard 36e4b6
       /* Look through our collection of info obtained from the PT_LOAD
Mark Wielaard 36e4b6
@@ -1754,6 +1754,12 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
          goto out;
Mark Wielaard 36e4b6
       }
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
+      /* Ignore zero sized sections. */
Mark Wielaard 36e4b6
+      if (size == 0) {
Mark Wielaard 36e4b6
+         TRACE_SYMTAB("zero sized section \"%s\", ignoring\n", name);
Mark Wielaard 36e4b6
+         continue;
Mark Wielaard 36e4b6
+      }
Mark Wielaard 36e4b6
+
Mark Wielaard 36e4b6
 #     define BAD(_secname)                                 \
Mark Wielaard 36e4b6
          do { ML_(symerr)(di, True,                        \
Mark Wielaard 36e4b6
                           "Can't make sense of " _secname  \
Mark Wielaard 36e4b6
@@ -1770,7 +1776,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .text where mapped as rx (code), even if zero-sized */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".text")) {
Mark Wielaard 36e4b6
-         if (inrx && size >= 0 && !di->text_present) {
Mark Wielaard 36e4b6
+         if (inrx && !di->text_present) {
Mark Wielaard 36e4b6
             di->text_present = True;
Mark Wielaard 36e4b6
             di->text_svma = svma;
Mark Wielaard 36e4b6
             di->text_avma = svma + inrx->bias;
Mark Wielaard 36e4b6
@@ -1792,7 +1798,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .data where mapped as rw (data), even if zero-sized */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".data")) {
Mark Wielaard 36e4b6
-         if (inrw && size >= 0 && !di->data_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->data_present) {
Mark Wielaard 36e4b6
             di->data_present = True;
Mark Wielaard 36e4b6
             di->data_svma = svma;
Mark Wielaard 36e4b6
             di->data_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
@@ -1814,7 +1820,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .sdata where mapped as rw (data) */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".sdata")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && !di->sdata_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->sdata_present) {
Mark Wielaard 36e4b6
             di->sdata_present = True;
Mark Wielaard 36e4b6
             di->sdata_svma = svma;
Mark Wielaard 36e4b6
             di->sdata_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
@@ -1836,7 +1842,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .rodata where mapped as rx (data), even if zero-sized */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".rodata")) {
Mark Wielaard 36e4b6
-         if (inrx && size >= 0 && !di->rodata_present) {
Mark Wielaard 36e4b6
+         if (inrx && !di->rodata_present) {
Mark Wielaard 36e4b6
             di->rodata_present = True;
Mark Wielaard 36e4b6
             di->rodata_svma = svma;
Mark Wielaard 36e4b6
             di->rodata_avma = svma + inrx->bias;
Mark Wielaard 36e4b6
@@ -1858,7 +1864,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
       }
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".dynbss")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && !di->bss_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->bss_present) {
Mark Wielaard 36e4b6
             dynbss_present = True;
Mark Wielaard 36e4b6
             di->bss_present = True;
Mark Wielaard 36e4b6
             di->bss_svma = svma;
Mark Wielaard 36e4b6
@@ -1879,7 +1885,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .bss where mapped as rw (data), even if zero-sized */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".bss")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && dynbss_present) {
Mark Wielaard 36e4b6
+         if (inrw && dynbss_present) {
Mark Wielaard 36e4b6
             vg_assert(di->bss_present);
Mark Wielaard 36e4b6
             dynbss_present = False;
Mark Wielaard 36e4b6
             vg_assert(di->bss_svma + di->bss_size == svma);
Mark Wielaard 36e4b6
@@ -1891,7 +1897,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
             TRACE_SYMTAB("acquiring .bss bias = %#lx\n", di->bss_bias);
Mark Wielaard 36e4b6
          } else
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
-         if (inrw && size >= 0 && !di->bss_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->bss_present) {
Mark Wielaard 36e4b6
             di->bss_present = True;
Mark Wielaard 36e4b6
             di->bss_svma = svma;
Mark Wielaard 36e4b6
             di->bss_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
@@ -1909,7 +1915,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
          } else
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
          /* Now one from the wtf?! department ... */
Mark Wielaard 36e4b6
-         if (inrx && (!inrw) && size >= 0 && !di->bss_present) {
Mark Wielaard 36e4b6
+         if (inrx && (!inrw) && !di->bss_present) {
Mark Wielaard 36e4b6
             /* File contains a .bss, but it got mapped as rx only.
Mark Wielaard 36e4b6
                This is very strange.  For now, just pretend we didn't
Mark Wielaard 36e4b6
                see it :-) */
Mark Wielaard 36e4b6
@@ -1930,7 +1936,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
             }
Mark Wielaard 36e4b6
          } else
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
-         if ((!inrw) && (!inrx) && size >= 0 && !di->bss_present) {
Mark Wielaard 36e4b6
+         if ((!inrw) && (!inrx) && !di->bss_present) {
Mark Wielaard 36e4b6
             /* File contains a .bss, but it didn't get mapped.  Ignore. */
Mark Wielaard 36e4b6
             di->bss_present = False;
Mark Wielaard 36e4b6
             di->bss_svma = 0;
Mark Wielaard 36e4b6
@@ -1943,7 +1949,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
       }
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".sdynbss")) {
Mark Wielaard 36e4b6
-         if (inrw && size >= 0 && !di->sbss_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->sbss_present) {
Mark Wielaard 36e4b6
             sdynbss_present = True;
Mark Wielaard 36e4b6
             di->sbss_present = True;
Mark Wielaard 36e4b6
             di->sbss_svma = svma;
Mark Wielaard 36e4b6
@@ -1964,7 +1970,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .sbss where mapped as rw (data) */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".sbss")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && sdynbss_present) {
Mark Wielaard 36e4b6
+         if (inrw && sdynbss_present) {
Mark Wielaard 36e4b6
             vg_assert(di->sbss_present);
Mark Wielaard 36e4b6
             sdynbss_present = False;
Mark Wielaard 36e4b6
             vg_assert(di->sbss_svma + di->sbss_size == svma);
Mark Wielaard 36e4b6
@@ -1976,7 +1982,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
             TRACE_SYMTAB("acquiring .sbss bias = %#lx\n", di->sbss_bias);
Mark Wielaard 36e4b6
          } else
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && !di->sbss_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->sbss_present) {
Mark Wielaard 36e4b6
             di->sbss_present = True;
Mark Wielaard 36e4b6
             di->sbss_svma = svma;
Mark Wielaard 36e4b6
             di->sbss_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
@@ -1998,7 +2004,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .got where mapped as rw (data) */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".got")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && !di->got_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->got_present) {
Mark Wielaard 36e4b6
             di->got_present = True;
Mark Wielaard 36e4b6
             di->got_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
             di->got_size = size;
Mark Wielaard 36e4b6
@@ -2010,7 +2016,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .got.plt where mapped as rw (data) */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".got.plt")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && !di->gotplt_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->gotplt_present) {
Mark Wielaard 36e4b6
             di->gotplt_present = True;
Mark Wielaard 36e4b6
             di->gotplt_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
             di->gotplt_size = size;
Mark Wielaard 36e4b6
@@ -2026,7 +2032,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
          || defined(VGP_mips32_linux)
Mark Wielaard 36e4b6
       /* Accept .plt where mapped as rx (code) */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".plt")) {
Mark Wielaard 36e4b6
-         if (inrx && size > 0 && !di->plt_present) {
Mark Wielaard 36e4b6
+         if (inrx && !di->plt_present) {
Mark Wielaard 36e4b6
             di->plt_present = True;
Mark Wielaard 36e4b6
             di->plt_avma = svma + inrx->bias;
Mark Wielaard 36e4b6
             di->plt_size = size;
Mark Wielaard 36e4b6
@@ -2038,7 +2044,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 #     elif defined(VGP_ppc32_linux)
Mark Wielaard 36e4b6
       /* Accept .plt where mapped as rw (data) */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".plt")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && !di->plt_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->plt_present) {
Mark Wielaard 36e4b6
             di->plt_present = True;
Mark Wielaard 36e4b6
             di->plt_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
             di->plt_size = size;
Mark Wielaard 36e4b6
@@ -2050,7 +2056,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 #     elif defined(VGP_ppc64_linux)
Mark Wielaard 36e4b6
       /* Accept .plt where mapped as rw (data), or unmapped */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".plt")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && !di->plt_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->plt_present) {
Mark Wielaard 36e4b6
             di->plt_present = True;
Mark Wielaard 36e4b6
             di->plt_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
             di->plt_size = size;
Mark Wielaard 36e4b6
@@ -2073,7 +2079,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
 
Mark Wielaard 36e4b6
       /* Accept .opd where mapped as rw (data) */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".opd")) {
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && !di->opd_present) {
Mark Wielaard 36e4b6
+         if (inrw && !di->opd_present) {
Mark Wielaard 36e4b6
             di->opd_present = True;
Mark Wielaard 36e4b6
             di->opd_avma = svma + inrw->bias;
Mark Wielaard 36e4b6
             di->opd_size = size;
Mark Wielaard 36e4b6
@@ -2088,14 +2094,14 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Mark Wielaard 36e4b6
          rw (data) instead.  We can handle up to N_EHFRAME_SECTS per
Mark Wielaard 36e4b6
          ELF object. */
Mark Wielaard 36e4b6
       if (0 == VG_(strcmp)(name, ".eh_frame")) {
Mark Wielaard 36e4b6
-         if (inrx && size > 0 && di->n_ehframe < N_EHFRAME_SECTS) {
Mark Wielaard 36e4b6
+         if (inrx && di->n_ehframe < N_EHFRAME_SECTS) {
Mark Wielaard 36e4b6
             di->ehframe_avma[di->n_ehframe] = svma + inrx->bias;
Mark Wielaard 36e4b6
             di->ehframe_size[di->n_ehframe] = size;
Mark Wielaard 36e4b6
             TRACE_SYMTAB("acquiring .eh_frame avma = %#lx\n",
Mark Wielaard 36e4b6
                          di->ehframe_avma[di->n_ehframe]);
Mark Wielaard 36e4b6
             di->n_ehframe++;
Mark Wielaard 36e4b6
          } else
Mark Wielaard 36e4b6
-         if (inrw && size > 0 && di->n_ehframe < N_EHFRAME_SECTS) {
Mark Wielaard 36e4b6
+         if (inrw && di->n_ehframe < N_EHFRAME_SECTS) {
Mark Wielaard 36e4b6
             di->ehframe_avma[di->n_ehframe] = svma + inrw->bias;
Mark Wielaard 36e4b6
             di->ehframe_size[di->n_ehframe] = size;
Mark Wielaard 36e4b6
             TRACE_SYMTAB("acquiring .eh_frame avma = %#lx\n",