3 @@ -5754,7 +5754,12 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
5 struct attribute *attr;
7 - CORE_ADDR base = (CORE_ADDR) 0;
8 + struct objfile *objfile = cu->objfile;
9 + CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
10 + SECT_OFF_TEXT (objfile));
11 + /* This is used only for DW_AT_data_member_location entries. */
15 attr = dwarf2_attr (die, DW_AT_location, cu);
17 @@ -5763,6 +5768,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
18 if (attr_form_is_block (attr))
20 base = decode_locdesc (DW_BLOCK (attr), cu);
23 else if (attr_form_is_section_offset (attr))
25 @@ -5824,12 +5830,15 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
27 dwarf2_complex_location_expr_complaint ();
29 - SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
31 + dwarf2_invalid_attrib_class_complaint
32 + ("DW_AT_data_member_location", "common block member");
33 + SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset + baseaddr;
34 add_symbol_to_list (sym, &global_symbols);
37 if (SYMBOL_CLASS (sym) == LOC_STATIC)
38 - SET_FIELD_PHYSADDR (*field, SYMBOL_VALUE_ADDRESS (sym));
39 + SET_FIELD_PHYSADDR (*field, SYMBOL_VALUE_ADDRESS (sym) - baseaddr);
41 SET_FIELD_PHYSNAME (*field, SYMBOL_LINKAGE_NAME (sym));
42 FIELD_TYPE (*field) = SYMBOL_TYPE (sym);
43 @@ -5843,7 +5852,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
45 sym = new_symbol (die, type, cu);
46 /* SYMBOL_VALUE_ADDRESS never gets used as all its fields are static. */
47 - SYMBOL_VALUE_ADDRESS (sym) = base;
48 + SYMBOL_VALUE_ADDRESS (sym) = base + baseaddr;
50 set_die_type (die, type, cu);
57 #include "arch-utils.h"
61 #include "readline/readline.h"
62 @@ -220,6 +221,10 @@ exec_file_attach (char *filename, int from_tty)
63 char *scratch_pathname;
65 struct target_section *sections = NULL, *sections_end = NULL;
66 + struct target_section *p;
68 + CORE_ADDR mask = CORE_ADDR_MAX;
69 + CORE_ADDR displacement;
71 scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename,
72 write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY,
73 @@ -288,12 +293,23 @@ exec_file_attach (char *filename, int from_tty)
74 scratch_pathname, bfd_errmsg (bfd_get_error ()));
77 + set_gdbarch_from_file (exec_bfd);
79 + addr_bit = gdbarch_addr_bit (target_gdbarch);
80 + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
81 + mask = ((CORE_ADDR) 1 << addr_bit) - 1;
83 + displacement = solib_exec_displacement ();
84 + for (p = sections; p < sections_end; p++)
86 + p->addr = (p->addr + displacement) & mask;
87 + p->endaddr = (p->endaddr + displacement) & mask;
90 exec_bfd_mtime = bfd_get_mtime (exec_bfd);
94 - set_gdbarch_from_file (exec_bfd);
96 /* Add the executable's sections to the current address spaces'
98 add_target_sections (sections, sections_end);
101 @@ -966,6 +966,7 @@ extern void allocate_cplus_struct_type (struct type *);
102 #define FIELD_LOC_KIND(thisfld) ((thisfld).loc_kind)
103 #define FIELD_BITPOS(thisfld) ((thisfld).loc.bitpos)
104 #define FIELD_STATIC_PHYSNAME(thisfld) ((thisfld).loc.physname)
105 +/* This address is unrelocated by the objfile's ANOFFSET. */
106 #define FIELD_STATIC_PHYSADDR(thisfld) ((thisfld).loc.physaddr)
107 #define FIELD_DWARF_BLOCK(thisfld) ((thisfld).loc.dwarf_block)
108 #define SET_FIELD_BITPOS(thisfld, bitpos) \
109 @@ -974,6 +975,7 @@ extern void allocate_cplus_struct_type (struct type *);
110 #define SET_FIELD_PHYSNAME(thisfld, name) \
111 (FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_PHYSNAME, \
112 FIELD_STATIC_PHYSNAME (thisfld) = (name))
113 +/* This address is unrelocated by the objfile's ANOFFSET. */
114 #define SET_FIELD_PHYSADDR(thisfld, addr) \
115 (FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_PHYSADDR, \
116 FIELD_STATIC_PHYSADDR (thisfld) = (addr))
117 @@ -989,6 +991,7 @@ extern void allocate_cplus_struct_type (struct type *);
118 #define TYPE_FIELD_LOC_KIND(thistype, n) FIELD_LOC_KIND (TYPE_FIELD (thistype, n))
119 #define TYPE_FIELD_BITPOS(thistype, n) FIELD_BITPOS (TYPE_FIELD (thistype, n))
120 #define TYPE_FIELD_STATIC_PHYSNAME(thistype, n) FIELD_STATIC_PHYSNAME (TYPE_FIELD (thistype, n))
121 +/* This address is unrelocated by the objfile's ANOFFSET. */
122 #define TYPE_FIELD_STATIC_PHYSADDR(thistype, n) FIELD_STATIC_PHYSADDR (TYPE_FIELD (thistype, n))
123 #define TYPE_FIELD_DWARF_BLOCK(thistype, n) FIELD_DWARF_BLOCK (TYPE_FIELD (thistype, n))
124 #define TYPE_FIELD_ARTIFICIAL(thistype, n) FIELD_ARTIFICIAL(TYPE_FIELD(thistype,n))
127 @@ -416,7 +416,8 @@ java_link_class_type (struct gdbarch *gdbarch,
130 nfields--; /* First set up dummy "class" field. */
131 - SET_FIELD_PHYSADDR (TYPE_FIELD (type, nfields), value_address (clas));
132 + SET_FIELD_PHYSADDR (TYPE_FIELD (type, nfields), value_address (clas)
133 + - (TYPE_OBJFILE (type) == NULL ? 0 : ANOFFSET (TYPE_OBJFILE (type)->section_offsets, SECT_OFF_TEXT (TYPE_OBJFILE (type)))));
134 TYPE_FIELD_NAME (type, nfields) = "class";
135 TYPE_FIELD_TYPE (type, nfields) = value_type (clas);
136 SET_TYPE_FIELD_PRIVATE (type, nfields);
137 @@ -462,7 +463,8 @@ java_link_class_type (struct gdbarch *gdbarch,
138 SET_TYPE_FIELD_PROTECTED (type, i);
140 if (accflags & 0x0008) /* ACC_STATIC */
141 - SET_FIELD_PHYSADDR (TYPE_FIELD (type, i), boffset);
142 + SET_FIELD_PHYSADDR (TYPE_FIELD (type, i), boffset
143 + - (TYPE_OBJFILE (type) == NULL ? 0 : ANOFFSET (TYPE_OBJFILE (type)->section_offsets, SECT_OFF_TEXT (TYPE_OBJFILE (type)))));
145 TYPE_FIELD_BITPOS (type, i) = 8 * boffset;
146 if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */
147 --- a/gdb/solib-svr4.c
148 +++ b/gdb/solib-svr4.c
149 @@ -1621,7 +1621,10 @@ svr4_exec_displacement (void)
150 if (target_auxv_search (¤t_target, AT_ENTRY, &entry_point) == 1)
151 return entry_point - exec_entry_point (exec_bfd, ¤t_target);
153 - return svr4_static_exec_displacement ();
154 + if (!ptid_equal (inferior_ptid, null_ptid))
155 + return svr4_static_exec_displacement ();
160 /* Relocate the main executable. This function should be called upon
161 @@ -1632,7 +1635,7 @@ svr4_exec_displacement (void)
163 svr4_relocate_main_executable (void)
165 - CORE_ADDR displacement = svr4_exec_displacement ();
166 + CORE_ADDR displacement = solib_exec_displacement ();
168 /* Even if DISPLACEMENT is 0 still try to relocate it as this is a new
169 difference of in-memory vs. in-file addresses and we could already
170 @@ -1975,6 +1978,7 @@ _initialize_svr4_solib (void)
171 svr4_so_ops.free_so = svr4_free_so;
172 svr4_so_ops.clear_solib = svr4_clear_solib;
173 svr4_so_ops.solib_create_inferior_hook = svr4_solib_create_inferior_hook;
174 + svr4_so_ops.exec_displacement = svr4_exec_displacement;
175 svr4_so_ops.special_symbol_handling = svr4_special_symbol_handling;
176 svr4_so_ops.current_sos = svr4_current_sos;
177 svr4_so_ops.open_symbol_file_object = open_symbol_file_object;
180 @@ -1014,6 +1014,19 @@ solib_create_inferior_hook (int from_tty)
181 ops->solib_create_inferior_hook (from_tty);
184 +/* Query the difference of in-memory VMA addresses vs. exec_bfd VMAs. */
187 +solib_exec_displacement (void)
189 + struct target_so_ops *ops = solib_ops (target_gdbarch);
191 + if (ops->exec_displacement != NULL)
192 + return (*ops->exec_displacement) ();
199 in_solib_dynsym_resolve_code -- check to see if an address is in
202 @@ -43,6 +43,8 @@ extern int solib_read_symbols (struct so_list *, int);
204 extern void solib_create_inferior_hook (int from_tty);
206 +extern CORE_ADDR solib_exec_displacement (void);
208 /* If ADDR lies in a shared library, return its name. */
210 extern char *solib_name_from_address (CORE_ADDR);
213 @@ -89,6 +89,9 @@ struct target_so_ops
214 /* Target dependent code to run after child process fork. */
215 void (*solib_create_inferior_hook) (int from_tty);
217 + /* Query the difference of in-memory VMA addresses vs. exec_bfd VMAs. */
218 + CORE_ADDR (*exec_displacement) (void);
220 /* Do additional symbol handling, lookup, etc. after symbols
221 for a shared object have been loaded. */
222 void (*special_symbol_handling) (void);
225 @@ -873,15 +873,36 @@ syms_from_objfile (struct objfile *objfile,
226 if an error occurs during symbol reading. */
227 old_chain = make_cleanup_free_objfile (objfile);
229 - /* If ADDRS and OFFSETS are both NULL, put together a dummy address
230 - list. We now establish the convention that an addr of zero means
231 - no load address was specified. */
232 + /* If ADDRS and OFFSETS are both NULL, put together a dummy offset list. */
234 if (! addrs && ! offsets)
237 - = alloc_section_addr_info (bfd_count_sections (objfile->obfd));
238 - make_cleanup (xfree, local_addr);
239 - addrs = local_addr;
240 + /* Relocateble files have an exception in default_symfile_offsets which
241 + applies only for ADDRS. But calling solib_exec_displacement is more
242 + suitable for OFFSETS. Fortunately we never need the both
243 + functionalities simultaneously and in other cases zeroed ADDRS and
244 + zeroed OFFSETS are equivalent. */
246 + if ((bfd_get_file_flags (objfile->obfd) & (EXEC_P | DYNAMIC)) == 0)
249 + = alloc_section_addr_info (bfd_count_sections (objfile->obfd));
250 + make_cleanup (xfree, local_addr);
251 + addrs = local_addr;
255 + CORE_ADDR displacement = 0;
259 + displacement = solib_exec_displacement ();
261 + num_offsets = bfd_count_sections (objfile->obfd);
262 + offsets = alloca (SIZEOF_N_SECTION_OFFSETS (num_offsets));
263 + for (i = 0; i < num_offsets; i++)
264 + offsets->offsets[i] = displacement;
268 /* Now either addrs or offsets is non-zero. */
271 @@ -1890,7 +1890,8 @@ value_static_field (struct type *type, int fieldno)
272 if (TYPE_FIELD_LOC_KIND (type, fieldno) == FIELD_LOC_KIND_PHYSADDR)
274 retval = value_at (TYPE_FIELD_TYPE (type, fieldno),
275 - TYPE_FIELD_STATIC_PHYSADDR (type, fieldno));
276 + TYPE_FIELD_STATIC_PHYSADDR (type, fieldno)
277 + + (TYPE_OBJFILE (type) == NULL ? 0 : ANOFFSET (TYPE_OBJFILE (type)->section_offsets, SECT_OFF_TEXT (TYPE_OBJFILE (type)))));
281 @@ -1920,7 +1921,8 @@ value_static_field (struct type *type, int fieldno)
283 if (retval && VALUE_LVAL (retval) == lval_memory)
284 SET_FIELD_PHYSADDR (TYPE_FIELD (type, fieldno),
285 - value_address (retval));
286 + value_address (retval)
287 + - (TYPE_OBJFILE (type) == NULL ? 0 : ANOFFSET (TYPE_OBJFILE (type)->section_offsets, SECT_OFF_TEXT (TYPE_OBJFILE (type)))));