This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: Linker relaxation and the size of the output section
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com, gdb at sources dot redhat dot com
- Date: Sat, 11 Oct 2003 22:00:49 +0930
- Subject: Re: Linker relaxation and the size of the output section
- References: <Pine.BSF.4.44.0309281612450.21971-100000@dair.pair.com><20031008025730.GB18493@bubble.sa.bigpond.net.au><m3n0ccs4oy.fsf@gossamer.airs.com>
On Tue, Oct 07, 2003 at 10:01:49PM -0700, Ian Lance Taylor wrote:
> Alan Modra <amodra@bigpond.net.au> writes:
>
> > Hmm, the following uses of _cooked_size outsize of bfd/ and ld/ are a
> > little dubious (or at least unnecessary). I'm fairly certain that
> > nothing beside the linker needs to look at _cooked_size.
> >
> > ./gprof/corefile.c: + core_syms[i]->section->_cooked_size - 1, max_vma);
> > ./gdb/hppa-tdep.c: && sec->vma + sec->_cooked_size < pc)
> > ./sim/mcore/interp.c: (unsigned long) s_bss->vma , (unsigned long) s_bss->_cooked_size);
> > ./sim/mcore/interp.c: heap_ptr = (unsigned long) s_bss->vma + (unsigned long) s_bss->_cooked_size;
>
> These bits of code should almost certainly be using
> bfd_section_size().
>
> As you say, referring directly to cooked_size makes no sense outside
> the linker.
>
> For that matter, these bits of code should use bfd_get_section_vma()
> rather than ...->vma.
Committing the following. I figure the gdb and sim changes are allowed
as obvious fixes.
The bfd_get_section_size_before_reloc change is because we ought to
be able to access the original section size at any stage, even after
relaxation. Also, I noticed hppa-tdep.c had the pc range test wrong, so
fixed that too.
bfd/ChangeLog
* section.c (bfd_get_section_size_before_reloc): Ignore reloc_done.
* bfd-in2.h: Regenerate.
gprof/ChangeLog
* corefile.c (core_create_function_syms): Don't refer directly to
_cooked_size and vma; Use bfd_section_size and bfd_get_section_vma.
gdb/ChangeLog
* hppa-tdep.c (hppa_in_solib_call_trampoline): Don't refer directly to
_cooked_size and vma; Use bfd_section_size and bfd_get_section_vma.
Correct test for pc within section.
sim/mcore/ChangeLog
* interp.c (sim_load): Don't refer directly to _cooked_size and vma;
Use bfd_section_size and bfd_get_section_vma.
Index: bfd/section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.60
diff -u -p -r1.60 section.c
--- bfd/section.c 25 Jul 2003 14:35:56 -0000 1.60
+++ bfd/section.c 11 Oct 2003 11:14:13 -0000
@@ -558,8 +558,7 @@ CODE_FRAGMENT
.extern const struct symbol_cache_entry * const bfd_und_symbol;
.extern const struct symbol_cache_entry * const bfd_ind_symbol;
.#define bfd_get_section_size_before_reloc(section) \
-. ((section)->reloc_done ? (abort (), (bfd_size_type) 1) \
-. : (section)->_raw_size)
+. ((section)->_raw_size)
.#define bfd_get_section_size_after_reloc(section) \
. ((section)->reloc_done ? (section)->_cooked_size \
. : (abort (), (bfd_size_type) 1))
Index: gprof/corefile.c
===================================================================
RCS file: /cvs/src/src/gprof/corefile.c,v
retrieving revision 1.14
diff -u -p -r1.14 corefile.c
--- gprof/corefile.c 21 Feb 2003 12:42:56 -0000 1.14
+++ gprof/corefile.c 11 Oct 2003 11:14:53 -0000
@@ -456,6 +456,8 @@ core_create_function_syms (cbfd)
for (i = 0; i < core_num_syms; ++i)
{
+ asection *sym_sec;
+
class = core_sym_class (core_syms[i]);
if (!class)
@@ -489,7 +491,10 @@ core_create_function_syms (cbfd)
sym_init (symtab.limit);
/* Symbol offsets are always section-relative. */
- symtab.limit->addr = core_syms[i]->value + core_syms[i]->section->vma;
+ sym_sec = core_syms[i]->section;
+ symtab.limit->addr = core_syms[i]->value;
+ if (sym_sec)
+ symtab.limit->addr += bfd_get_section_vma (sym_sec->owner, sym_sec);
if (symbol_map_count
&& !strcmp (core_syms[i]->name, symbol_map[found].function_name))
@@ -546,9 +551,10 @@ core_create_function_syms (cbfd)
symbols. When computing the max_vma, use the ending address of the
section containing the symbol, if available. */
min_vma = MIN (symtab.limit->addr, min_vma);
- if (core_syms[i]->section)
- max_vma = MAX (core_syms[i]->section->vma
- + core_syms[i]->section->_cooked_size - 1, max_vma);
+ if (sym_sec)
+ max_vma = MAX (bfd_get_section_vma (sym_sec->owner, sym_sec)
+ + bfd_section_size (sym_sec->owner, sym_sec) - 1,
+ max_vma);
else
max_vma = MAX (symtab.limit->addr, max_vma);
Index: gdb/hppa-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
retrieving revision 1.103
diff -u -p -r1.103 hppa-tdep.c
--- gdb/hppa-tdep.c 2 Oct 2003 20:28:29 -0000 1.103
+++ gdb/hppa-tdep.c 11 Oct 2003 11:55:51 -0000
@@ -3095,8 +3095,9 @@ hppa_in_solib_call_trampoline (CORE_ADDR
sec = SYMBOL_BFD_SECTION (minsym);
- if (sec->vma <= pc
- && sec->vma + sec->_cooked_size < pc)
+ if (bfd_get_section_vma (sec->owner, sec) <= pc
+ && pc < (bfd_get_section_vma (sec->owner, sec)
+ + bfd_section_size (sec->owner, sec)))
return 0;
/* We might be in a stub. Peek at the instructions. Stubs are 3
Index: sim/mcore/interp.c
===================================================================
RCS file: /cvs/src/src/sim/mcore/interp.c,v
retrieving revision 1.6
diff -u -p -r1.6 interp.c
--- sim/mcore/interp.c 27 Feb 2003 23:26:34 -0000 1.6
+++ sim/mcore/interp.c 11 Oct 2003 11:15:11 -0000
@@ -1,5 +1,5 @@
/* Simulator for Motorola's MCore processor
- Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
Contributed by Cygnus Solutions.
This file is part of GDB, the GNU debugger.
@@ -1981,9 +1981,11 @@ sim_load (sd, prog, abfd, from_tty)
/* figure the end of the bss section */
#if 0
printf ("bss section at 0x%08x for 0x%08x bytes\n",
- (unsigned long) s_bss->vma , (unsigned long) s_bss->_cooked_size);
+ (unsigned long) bfd_get_section_vma (handle, s_bss),
+ (unsigned long) bfd_section_size (handle, s_bss));
#endif
- heap_ptr = (unsigned long) s_bss->vma + (unsigned long) s_bss->_cooked_size;
+ heap_ptr = ((unsigned long) bfd_get_section_vma (handle, s_bss)
+ + (unsigned long) bfd_section_size (handle, s_bss));
/* Clean up after ourselves. */
bfd_close (handle);
--
Alan Modra
IBM OzLabs - Linux Technology Centre