Blame SOURCES/ruby-dwarf5-avoid_crash-r1.patch

7958ac
--- a/addr2line.c
7958ac
+++ b/addr2line.c
7958ac
@@ -159,11 +159,12 @@
7958ac
     struct dwarf_section debug_info;
7958ac
     struct dwarf_section debug_line;
7958ac
     struct dwarf_section debug_ranges;
7958ac
+    struct dwarf_section debug_rnglists;
7958ac
     struct dwarf_section debug_str;
7958ac
     struct obj_info *next;
7958ac
 } obj_info_t;
7958ac
 
7958ac
-#define DWARF_SECTION_COUNT 5
7958ac
+#define DWARF_SECTION_COUNT 6
7958ac
 
7958ac
 static struct dwarf_section *
7958ac
 obj_dwarf_section_at(obj_info_t *obj, int n)
7958ac
@@ -173,6 +174,7 @@
7958ac
         &obj->debug_info,
7958ac
         &obj->debug_line,
7958ac
         &obj->debug_ranges,
7958ac
+        &obj->debug_rnglists,
7958ac
         &obj->debug_str
7958ac
     };
7958ac
     if (n < 0 || DWARF_SECTION_COUNT <= n) {
7958ac
@@ -411,7 +413,7 @@
7958ac
 	    FILL_LINE();
7958ac
 	    break;
7958ac
 	case DW_LNS_advance_pc:
7958ac
-	    a = uleb128((char **)&p);
7958ac
+	    a = uleb128((char **)&p) * header.minimum_instruction_length;
7958ac
 	    addr += a;
7958ac
 	    break;
7958ac
 	case DW_LNS_advance_line: {
7958ac
@@ -450,7 +452,7 @@
7958ac
 	    /* isa = (unsigned int)*/(void)uleb128((char **)&p);
7958ac
 	    break;
7958ac
 	case 0:
7958ac
-	    a = *(unsigned char *)p++;
7958ac
+	    a = uleb128((char **)&p);
7958ac
 	    op = *p++;
7958ac
 	    switch (op) {
7958ac
 	    case DW_LNE_end_sequence:
7958ac
@@ -807,6 +809,18 @@
7958ac
     DW_FORM_addrx4 = 0x2c
7958ac
 };
7958ac
 
7958ac
+/* Range list entry encodings */
7958ac
+enum {
7958ac
+    DW_RLE_end_of_list = 0x00,
7958ac
+    DW_RLE_base_addressx = 0x01,
7958ac
+    DW_RLE_startx_endx = 0x02,
7958ac
+    DW_RLE_startx_length = 0x03,
7958ac
+    DW_RLE_offset_pair = 0x04,
7958ac
+    DW_RLE_base_address = 0x05,
7958ac
+    DW_RLE_start_end = 0x06,
7958ac
+    DW_RLE_start_length = 0x07
7958ac
+};
7958ac
+
7958ac
 enum {
7958ac
     VAL_none = 0,
7958ac
     VAL_cstr = 1,
7958ac
@@ -961,6 +975,23 @@
7958ac
 }
7958ac
 
7958ac
 static void
7958ac
+di_skip_die_attributes(char **p)
7958ac
+{
7958ac
+    for (;;) {
7958ac
+        uint64_t at = uleb128(p);
7958ac
+        uint64_t form = uleb128(p);
7958ac
+        if (!at && !form) break;
7958ac
+        switch (form) {
7958ac
+          default:
7958ac
+            break;
7958ac
+          case DW_FORM_implicit_const:
7958ac
+            sleb128(p);
7958ac
+            break;
7958ac
+        }
7958ac
+    }
7958ac
+}
7958ac
+
7958ac
+static void
7958ac
 di_read_debug_abbrev_cu(DebugInfoReader *reader)
7958ac
 {
7958ac
     uint64_t prev = 0;
7958ac
@@ -974,12 +1005,7 @@
7958ac
         prev = abbrev_number;
7958ac
         uleb128(&p); /* tag */
7958ac
         p++; /* has_children */
7958ac
-        /* skip content */
7958ac
-        for (;;) {
7958ac
-            uint64_t at = uleb128(&p);
7958ac
-            uint64_t form = uleb128(&p);
7958ac
-            if (!at && !form) break;
7958ac
-        }
7958ac
+        di_skip_die_attributes(&p);
7958ac
     }
7958ac
 }
7958ac
 
7958ac
@@ -1243,12 +1269,7 @@
7958ac
     /* skip 255th record */
7958ac
     uleb128(&p); /* tag */
7958ac
     p++; /* has_children */
7958ac
-    /* skip content */
7958ac
-    for (;;) {
7958ac
-        uint64_t at = uleb128(&p);
7958ac
-        uint64_t form = uleb128(&p);
7958ac
-        if (!at && !form) break;
7958ac
-    }
7958ac
+    di_skip_die_attributes(&p);
7958ac
     for (uint64_t n = uleb128(&p); abbrev_number != n; n = uleb128(&p)) {
7958ac
         if (n == 0) {
7958ac
             fprintf(stderr,"%d: Abbrev Number %"PRId64" not found\n",__LINE__, abbrev_number);
7958ac
@@ -1256,12 +1277,7 @@
7958ac
         }
7958ac
         uleb128(&p); /* tag */
7958ac
         p++; /* has_children */
7958ac
-        /* skip content */
7958ac
-        for (;;) {
7958ac
-            uint64_t at = uleb128(&p);
7958ac
-            uint64_t form = uleb128(&p);
7958ac
-            if (!at && !form) break;
7958ac
-        }
7958ac
+        di_skip_die_attributes(&p);
7958ac
     }
7958ac
     return p;
7958ac
 }
7958ac
@@ -1389,6 +1405,21 @@
7958ac
     }
7958ac
 }
7958ac
 
7958ac
+static uint64_t
7958ac
+read_dw_form_addr(DebugInfoReader *reader, char **ptr)
7958ac
+{
7958ac
+    char *p = *ptr;
7958ac
+    *ptr = p + reader->format;
7958ac
+    if (reader->format == 4) {
7958ac
+        return read_uint32(&p);
7958ac
+    } else if (reader->format == 8) {
7958ac
+        return read_uint64(&p);
7958ac
+    } else {
7958ac
+        fprintf(stderr,"unknown address_size:%d", reader->address_size);
7958ac
+        abort();
7958ac
+    }
7958ac
+}
7958ac
+
7958ac
 static uintptr_t
7958ac
 ranges_include(DebugInfoReader *reader, ranges_t *ptr, uint64_t addr)
7958ac
 {
7958ac
@@ -1402,8 +1433,50 @@
7958ac
     }
7958ac
     else if (ptr->ranges_set) {
7958ac
         /* TODO: support base address selection entry */
7958ac
-        char *p = reader->obj->debug_ranges.ptr + ptr->ranges;
7958ac
+        char *p;
7958ac
         uint64_t base = ptr->low_pc_set ? ptr->low_pc : reader->current_low_pc;
7958ac
+        if (reader->obj->debug_rnglists.ptr) {
7958ac
+            p = reader->obj->debug_rnglists.ptr + ptr->ranges;
7958ac
+            for (;;) {
7958ac
+                uint8_t rle = read_uint8(&p);
7958ac
+                uintptr_t base_address = 0;
7958ac
+                uintptr_t from, to;
7958ac
+                if (rle == DW_RLE_end_of_list) break;
7958ac
+                switch (rle) {
7958ac
+                  case DW_RLE_base_addressx:
7958ac
+                    uleb128(&p);
7958ac
+                    break;
7958ac
+                  case DW_RLE_startx_endx:
7958ac
+                    uleb128(&p);
7958ac
+                    uleb128(&p);
7958ac
+                    break;
7958ac
+                  case DW_RLE_startx_length:
7958ac
+                    uleb128(&p);
7958ac
+                    uleb128(&p);
7958ac
+                    break;
7958ac
+                  case DW_RLE_offset_pair:
7958ac
+                    from = base_address + uleb128(&p);
7958ac
+                    to = base_address + uleb128(&p);
7958ac
+                    if (base + from <= addr && addr < base + to) {
7958ac
+                        return from;
7958ac
+                    }
7958ac
+                    break;
7958ac
+                  case DW_RLE_base_address:
7958ac
+                    base_address = read_dw_form_addr(reader, &p);
7958ac
+                    break;
7958ac
+                  case DW_RLE_start_end:
7958ac
+                    read_dw_form_addr(reader, &p);
7958ac
+                    read_dw_form_addr(reader, &p);
7958ac
+                    break;
7958ac
+                  case DW_RLE_start_length:
7958ac
+                    read_dw_form_addr(reader, &p);
7958ac
+                    uleb128(&p);
7958ac
+                    break;
7958ac
+                }
7958ac
+            }
7958ac
+            return false;
7958ac
+        }
7958ac
+        p = reader->obj->debug_ranges.ptr + ptr->ranges;
7958ac
         for (;;) {
7958ac
             uintptr_t from = read_uintptr(&p);
7958ac
             uintptr_t to = read_uintptr(&p);
7958ac
@@ -1747,6 +1820,7 @@
7958ac
                     ".debug_info",
7958ac
                     ".debug_line",
7958ac
                     ".debug_ranges",
7958ac
+                    ".debug_rnglists",
7958ac
                     ".debug_str"
7958ac
                 };
7958ac
 
7958ac
@@ -2003,6 +2077,7 @@
7958ac
                     "__debug_info",
7958ac
                     "__debug_line",
7958ac
                     "__debug_ranges",
7958ac
+                    "__debug_rnglists",
7958ac
                     "__debug_str"
7958ac
                 };
7958ac
                 struct LP(segment_command) *scmd = (struct LP(segment_command) *)lcmd;