ppc64 synthetic symtab
Alan Modra
amodra@bigpond.net.au
Sat Aug 28 08:53:00 GMT 2004
On Sat, Aug 28, 2004 at 12:26:44PM +0930, Alan Modra wrote:
> * elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Don't read symbols.
That wasn't well thought out. We shouldn't be changing the symbol
pointer array passed in.
bfd/
* elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Copy input
symbol pointer arrays before modifying.
This adds an option to nm, mainly for powerpc64-linux kernel use.
It seems people want to see code entry points..
binutils/
* nm.c (show_synthetic): New var.
(long_options): Add "synthetic".
(usage): Here too.
(display_rel_file): Handle show_synthetic.
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.169
diff -u -p -r1.169 elf64-ppc.c
--- bfd/elf64-ppc.c 28 Aug 2004 03:05:17 -0000 1.169
+++ bfd/elf64-ppc.c 28 Aug 2004 08:47:36 -0000
@@ -2645,18 +2645,19 @@ sym_exists_at (asymbol **syms, long lo,
entry syms. */
static long
-ppc64_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms,
- long dynsymcount, asymbol **dynsyms,
+ppc64_elf_get_synthetic_symtab (bfd *abfd,
+ long static_count, asymbol **static_syms,
+ long dyn_count, asymbol **dyn_syms,
asymbol **ret)
{
asymbol *s;
long i;
long count;
char *names;
- long codesecsym, codesecsymend, secsymend, opdsymend;
+ long symcount, codesecsym, codesecsymend, secsymend, opdsymend;
asection *opd;
bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
- asymbol **sy = NULL;
+ asymbol **syms;
*ret = NULL;
@@ -2664,29 +2665,27 @@ ppc64_elf_get_synthetic_symtab (bfd *abf
if (opd == NULL)
return 0;
+ symcount = static_count;
if (!relocatable)
- {
- if (symcount != 0 && dynsymcount != 0)
- {
- /* Use both symbol tables. */
- sy = bfd_malloc ((symcount + dynsymcount + 1) * sizeof (*syms));
- if (sy == NULL)
- return 0;
- memcpy (sy, syms, symcount * sizeof (*syms));
- memcpy (sy + symcount, dynsyms, (dynsymcount + 1) * sizeof (*syms));
- syms = sy;
- symcount = symcount + dynsymcount;
- }
- else if (symcount == 0)
- {
- syms = dynsyms;
- symcount = dynsymcount;
- }
- }
-
+ symcount += dyn_count;
if (symcount == 0)
return 0;
+ syms = bfd_malloc ((symcount + 1) * sizeof (*syms));
+ if (syms == NULL)
+ return 0;
+
+ if (!relocatable && static_count != 0 && dyn_count != 0)
+ {
+ /* Use both symbol tables. */
+ memcpy (syms, static_syms, static_count * sizeof (*syms));
+ memcpy (syms + static_count, dyn_syms, (dyn_count + 1) * sizeof (*syms));
+ }
+ else if (!relocatable && static_count == 0)
+ memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms));
+ else
+ memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms));
+
synthetic_opd = opd;
synthetic_relocatable = relocatable;
qsort (syms, symcount, sizeof (asymbol *), compare_symbols);
@@ -2916,8 +2915,7 @@ ppc64_elf_get_synthetic_symtab (bfd *abf
}
done:
- if (sy != NULL)
- free (sy);
+ free (syms);
return count;
}
Index: binutils/nm.c
===================================================================
RCS file: /cvs/src/src/binutils/nm.c,v
retrieving revision 1.39
diff -u -p -r1.39 nm.c
--- binutils/nm.c 7 Nov 2003 12:19:34 -0000 1.39
+++ binutils/nm.c 28 Aug 2004 08:31:28 -0000
@@ -177,6 +177,7 @@ static int undefined_only = 0; /* Print
static int dynamic = 0; /* Print dynamic symbols. */
static int show_version = 0; /* Show the version number. */
static int show_stats = 0; /* Show statistics. */
+static int show_synthetic = 0; /* Display synthesized symbols too. */
static int line_numbers = 0; /* Print line numbers for symbols. */
/* When to print the names of files. Not mutually exclusive in SYSV format. */
@@ -232,6 +233,7 @@ static struct option long_options[] =
{"reverse-sort", no_argument, &reverse_sort, 1},
{"size-sort", no_argument, &sort_by_size, 1},
{"stats", no_argument, &show_stats, 1},
+ {"synthetic", no_argument, &show_synthetic, 1},
{"target", required_argument, 0, OPTION_TARGET},
{"defined-only", no_argument, &defined_only, 1},
{"undefined-only", no_argument, &undefined_only, 1},
@@ -271,6 +273,7 @@ usage (FILE *stream, int status)
-S, --print-size Print size of defined symbols\n\
-s, --print-armap Include index for symbols from archive members\n\
--size-sort Sort symbols by size\n\
+ --synthetic Display synthetic symbols as well\n\
-t, --radix=RADIX Use RADIX for printing symbol values\n\
--target=BFDNAME Specify the target object format as BFDNAME\n\
-u, --undefined-only Display only undefined symbols\n\
@@ -958,6 +961,45 @@ display_rel_file (bfd *abfd, bfd *archiv
return;
}
+ if (show_synthetic && size == sizeof (asymbol *))
+ {
+ asymbol *synthsyms;
+ long synth_count;
+ asymbol **static_syms = NULL;
+ asymbol **dyn_syms = NULL;
+ long static_count = 0;
+ long dyn_count = 0;
+
+ if (dynamic)
+ {
+ dyn_count = symcount;
+ dyn_syms = minisyms;
+ }
+ else
+ {
+ static_count = symcount;
+ static_syms = minisyms;
+ }
+ synth_count = bfd_get_synthetic_symtab (abfd, static_count, static_syms,
+ dyn_count, dyn_syms, &synthsyms);
+ if (synth_count > 0)
+ {
+ asymbol **symp;
+ void *new_mini;
+ long i;
+
+ new_mini = xmalloc ((symcount + synth_count + 1) * sizeof (*symp));
+ symp = new_mini;
+ memcpy (symp, minisyms, symcount * sizeof (*symp));
+ symp += symcount;
+ for (i = 0; i < synth_count; i++)
+ *symp++ = synthsyms + i;
+ *symp = 0;
+ minisyms = new_mini;
+ symcount += synth_count;
+ }
+ }
+
/* Discard the symbols we don't want to print.
It's OK to do this in place; we'll free the storage anyway
(after printing). */
--
Alan Modra
IBM OzLabs - Linux Technology Centre
More information about the Binutils
mailing list