]> git.pld-linux.org Git - packages/binutils.git/blob - binutils-pr3191.patch
770bf1fc923a315658920898d574ffc18698cc10
[packages/binutils.git] / binutils-pr3191.patch
1 2006-09-29  H.J. Lu  <hongjiu.lu@intel.com>
2
3         PR ld/3191
4         * dwarf2.c (find_abstract_instance_name): Pass a pointer to
5         attribute instead of offset.  For DW_FORM_ref_addr, get the
6         entry at the offset from the .debug_info section.
7         (scan_unit_for_symbols): Updated.
8         (_bfd_dwarf2_find_nearest_line): Adjust debug_info
9         section vma when needed.
10
11 --- bfd/dwarf2.c.ref_addr       2006-09-21 13:55:25.000000000 -0700
12 +++ bfd/dwarf2.c        2006-09-29 10:07:14.000000000 -0700
13 @@ -1556,16 +1556,30 @@ lookup_symbol_in_variable_table (struct 
14  }
15  
16  static char *
17 -find_abstract_instance_name (struct comp_unit *unit, bfd_uint64_t die_ref)
18 +find_abstract_instance_name (struct comp_unit *unit,
19 +                            struct attribute *attr_ptr)
20  {
21    bfd *abfd = unit->abfd;
22    bfd_byte *info_ptr;
23    unsigned int abbrev_number, bytes_read, i;
24    struct abbrev_info *abbrev;
25 +  bfd_uint64_t die_ref = attr_ptr->u.val;
26    struct attribute attr;
27    char *name = 0;
28  
29 -  info_ptr = unit->info_ptr_unit + die_ref;
30 +  /* DW_FORM_ref_addr can reference an entry in a different CU. It
31 +     is an offset from the .debug_info section, not the current CU.  */
32 +  if (attr_ptr->form == DW_FORM_ref_addr)
33 +    {
34 +      /* FIXME: How to handle DW_FORM_ref_addr references an entry in
35 +        a different file?  */ 
36 +      if (!die_ref)
37 +       abort ();
38 +
39 +      info_ptr = unit->stash->sec_info_ptr + die_ref;
40 +    }
41 +  else 
42 +    info_ptr = unit->info_ptr_unit + die_ref;
43    abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
44    info_ptr += bytes_read;
45  
46 @@ -1591,7 +1605,7 @@ find_abstract_instance_name (struct comp
47                     name = attr.u.str;
48                   break;
49                 case DW_AT_specification:
50 -                 name = find_abstract_instance_name (unit, attr.u.val);
51 +                 name = find_abstract_instance_name (unit, &attr);
52                   break;
53                 case DW_AT_MIPS_linkage_name:
54                   name = attr.u.str;
55 @@ -1751,7 +1765,7 @@ scan_unit_for_symbols (struct comp_unit 
56                   break;
57  
58                 case DW_AT_abstract_origin:
59 -                 func->name = find_abstract_instance_name (unit, attr.u.val);
60 +                 func->name = find_abstract_instance_name (unit, &attr);
61                   break;
62  
63                 case DW_AT_name:
64 @@ -2375,6 +2389,11 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
65      {
66        bfd_size_type total_size;
67        asection *msec;
68 +      bfd_vma last_vma;
69 +      bfd_size_type size;
70 +      asection *first_msec;
71 +      asection **msecs = NULL;
72 +      unsigned int i, count;
73  
74        *pinfo = stash;
75  
76 @@ -2389,9 +2408,28 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
77          Read them all in and produce one large stash.  We do this in two
78          passes - in the first pass we just accumulate the section sizes.
79          In the second pass we read in the section's contents.  The allows
80 -        us to avoid reallocing the data as we add sections to the stash.  */
81 +        us to avoid reallocing the data as we add sections to the stash.
82 +       
83 +        We may need to adjust debug_info section vmas since we will
84 +        concatenate them together.  Otherwise relocations may be
85 +        incorrect.  */
86 +      first_msec = msec;
87 +      last_vma = 0;
88 +      count = 0;
89        for (total_size = 0; msec; msec = find_debug_info (abfd, msec))
90 -       total_size += msec->size;
91 +       {
92 +         size = msec->size;
93 +         if (size == 0)
94 +           continue;
95 +
96 +         total_size += size;
97 +
98 +         BFD_ASSERT (msec->vma == 0 && msec->alignment_power == 0);
99 +
100 +         msec->vma = last_vma;
101 +         last_vma += size;
102 +         count++;
103 +       }
104  
105        stash->info_ptr = bfd_alloc (abfd, total_size);
106        if (stash->info_ptr == NULL)
107 @@ -2399,17 +2437,27 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
108  
109        stash->info_ptr_end = stash->info_ptr;
110  
111 -      for (msec = find_debug_info (abfd, NULL);
112 +      if (count > 1)
113 +       {
114 +         count--;
115 +         msecs = (asection **) bfd_malloc2 (count, sizeof (*msecs));
116 +       }
117 +
118 +      for (i = 0, msec = first_msec;
119            msec;
120            msec = find_debug_info (abfd, msec))
121         {
122 -         bfd_size_type size;
123           bfd_size_type start;
124  
125           size = msec->size;
126           if (size == 0)
127             continue;
128  
129 +         if (i && msecs)
130 +           msecs [i - 1] = msec;
131 +
132 +         i++;
133 +
134           start = stash->info_ptr_end - stash->info_ptr;
135  
136           if ((bfd_simple_get_relocated_section_contents
137 @@ -2419,9 +2467,27 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
138           stash->info_ptr_end = stash->info_ptr + start + size;
139         }
140  
141 +      /* Restore section vma. */
142 +      if (count)
143 +       {
144 +         if (msecs)
145 +           {
146 +             for (i = 0; i < count; i++)
147 +               msecs [i]->vma = 0;
148 +             free (msecs);
149 +           }
150 +         else
151 +           {
152 +             for (msec = find_debug_info (abfd, first_msec);
153 +                  msec;
154 +                  msec = find_debug_info (abfd, msec))
155 +               msec->vma = 0;
156 +           }
157 +       }
158 +
159        BFD_ASSERT (stash->info_ptr_end == stash->info_ptr + total_size);
160  
161 -      stash->sec = find_debug_info (abfd, NULL);
162 +      stash->sec = first_msec;
163        stash->sec_info_ptr = stash->info_ptr;
164        stash->syms = symbols;
165      }
This page took 0.215474 seconds and 2 git commands to generate.