Changes to make ld demangle C++ symbol names before printing

error messages containing them.

Reviewed by:	Peter Wemm
This commit is contained in:
Joshua Peck Macdonald 1997-01-11 05:51:03 +00:00
parent 63c9b0f9ee
commit c83a75eb30
7 changed files with 94 additions and 1048 deletions

View File

@ -1,16 +1,18 @@
# $Id: Makefile,v 1.17 1995/09/22 14:14:32 phk Exp $
# $Id: Makefile,v 1.18 1996/10/01 01:22:12 peter Exp $
#
PROG= ld
SRCS= ld.c symbol.c lib.c shlib.c warnings.c support.c rrs.c xbits.c md.c
CFLAGS += -I$(.CURDIR) -I$(.CURDIR)/$(MACHINE)
SRCS= ld.c symbol.c lib.c shlib.c warnings.c support.c rrs.c xbits.c md.c cplus-dem.c
CFLAGS += -I$(.CURDIR) -I$(.CURDIR)/$(MACHINE) -I$(GCCDIR) -DIN_GCC -DDEMANGLE_CPLUSPLUS
LDFLAGS+= -Xlinker -Bstatic
GCCDIR= ${.CURDIR}/../../../contrib/gcc
SUBDIR= ldconfig ldd
.if !defined(NOPIC)
SUBDIR+= rtld
.endif
.PATH: $(.CURDIR)/$(MACHINE)
.PATH: $(.CURDIR)/$(MACHINE) $(GCCDIR)
.include <bsd.prog.mk>

View File

@ -1,975 +0,0 @@
/*-
* This code is derived from software copyrighted by the Free Software
* Foundation.
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)cplus-dem.c 5.4 (Berkeley) 4/30/91";*/
static char rcsid[] = "$Id: cplus-dem.c,v 1.3 1993/11/09 04:18:51 paul Exp $";
#endif /* not lint */
/* Demangler for GNU C++
Copyright (C) 1989 Free Software Foundation, Inc.
written by James Clark (jjc@jclark.uucp)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* This is for g++ 1.36.1 (November 6 version). It will probably
require changes for any other version.
Modified for g++ 1.36.2 (November 18 version). */
/* This file exports one function
char *cplus_demangle (const char *name)
If `name' is a mangled function name produced by g++, then
a pointer to a malloced string giving a C++ representation
of the name will be returned; otherwise NULL will be returned.
It is the caller's responsibility to free the string which
is returned.
For example,
cplus_demangle ("_foo__1Ai")
returns
"A::foo(int)"
This file imports xmalloc and xrealloc, which are like malloc and
realloc except that they generate a fatal error if there is no
available memory. */
/* #define nounderscore 1 /* define this is names don't start with _ */
#include <stdio.h>
#include <ctype.h>
#ifdef USG
#include <memory.h>
#include <string.h>
#else
#include <strings.h>
#define memcpy(s1, s2, n) bcopy ((s2), (s1), (n))
#define memcmp(s1, s2, n) bcmp ((s2), (s1), (n))
#define strchr index
#define strrchr rindex
#endif
#ifndef __STDC__
#define const
#endif
#ifdef __STDC__
extern char *cplus_demangle (const char *type);
#else
extern char *cplus_demangle ();
#endif
#ifdef __STDC__
extern char *xmalloc (int);
extern char *xrealloc (char *, int);
#else
extern char *xmalloc ();
extern char *xrealloc ();
#endif
static char **typevec = 0;
static int ntypes = 0;
static int typevec_size = 0;
static struct {
const char *in;
const char *out;
} optable[] = {
"new", " new",
"delete", " delete",
"ne", "!=",
"eq", "==",
"ge", ">=",
"gt", ">",
"le", "<=",
"lt", "<",
"plus", "+",
"minus", "-",
"mult", "*",
"convert", "+", /* unary + */
"negate", "-", /* unary - */
"trunc_mod", "%",
"trunc_div", "/",
"truth_andif", "&&",
"truth_orif", "||",
"truth_not", "!",
"postincrement", "++",
"postdecrement", "--",
"bit_ior", "|",
"bit_xor", "^",
"bit_and", "&",
"bit_not", "~",
"call", "()",
"cond", "?:",
"alshift", "<<",
"arshift", ">>",
"component", "->",
"indirect", "*",
"method_call", "->()",
"addr", "&", /* unary & */
"array", "[]",
"nop", "", /* for operator= */
};
/* Beware: these aren't '\0' terminated. */
typedef struct {
char *b; /* pointer to start of string */
char *p; /* pointer after last character */
char *e; /* pointer after end of allocated space */
} string;
#ifdef __STDC__
static void string_need (string *s, int n);
static void string_delete (string *s);
static void string_init (string *s);
static void string_clear (string *s);
static int string_empty (string *s);
static void string_append (string *p, const char *s);
static void string_appends (string *p, string *s);
static void string_appendn (string *p, const char *s, int n);
static void string_prepend (string *p, const char *s);
#if 0
static void string_prepends (string *p, string *s);
#endif
static void string_prependn (string *p, const char *s, int n);
static int get_count (const char **type, int *count);
static int do_args (const char **type, string *decl);
static int do_type (const char **type, string *result);
static int do_arg (const char **type, string *result);
static int do_args (const char **type, string *decl);
static void munge_function_name (string *name);
static void remember_type (const char *type, int len);
#else
static void string_need ();
static void string_delete ();
static void string_init ();
static void string_clear ();
static int string_empty ();
static void string_append ();
static void string_appends ();
static void string_appendn ();
static void string_prepend ();
static void string_prepends ();
static void string_prependn ();
static int get_count ();
static int do_args ();
static int do_type ();
static int do_arg ();
static int do_args ();
static void munge_function_name ();
static void remember_type ();
#endif
char *
cplus_demangle (type)
const char *type;
{
string decl;
int n;
int success = 0;
int constructor = 0;
int const_flag = 0;
int i;
const char *p;
#ifndef LONGERNAMES
const char *premangle;
#endif
if (type == NULL || *type == '\0')
return NULL;
#ifndef nounderscore
if (*type++ != '_')
return NULL;
#endif
p = type;
while (*p != '\0' && !(*p == '_' && p[1] == '_'))
p++;
if (*p == '\0')
{
/* destructor */
if (type[0] == '_' && type[1] == '$' && type[2] == '_')
{
int n = (strlen (type) - 3)*2 + 3 + 2 + 1;
char *tem = (char *) xmalloc (n);
strcpy (tem, type + 3);
strcat (tem, "::~");
strcat (tem, type + 3);
strcat (tem, "()");
return tem;
}
/* static data member */
if (*type != '_' && (p = strchr (type, '$')) != NULL)
{
int n = strlen (type) + 2;
char *tem = (char *) xmalloc (n);
memcpy (tem, type, p - type);
strcpy (tem + (p - type), "::");
strcpy (tem + (p - type) + 2, p + 1);
return tem;
}
/* virtual table */
if (type[0] == '_' && type[1] == 'v' && type[2] == 't' && type[3] == '$')
{
int n = strlen (type + 4) + 14 + 1;
char *tem = (char *) xmalloc (n);
strcpy (tem, type + 4);
strcat (tem, " virtual table");
return tem;
}
return NULL;
}
string_init (&decl);
if (p == type)
{
if (!isdigit (p[2]))
{
string_delete (&decl);
return NULL;
}
constructor = 1;
}
else
{
string_appendn (&decl, type, p - type);
munge_function_name (&decl);
}
p += 2;
#ifndef LONGERNAMES
premangle = p;
#endif
switch (*p)
{
case 'C':
/* a const member function */
if (!isdigit (p[1]))
{
string_delete (&decl);
return NULL;
}
p += 1;
const_flag = 1;
/* fall through */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
n = 0;
do
{
n *= 10;
n += *p - '0';
p += 1;
}
while (isdigit (*p));
if (strlen (p) < n)
{
string_delete (&decl);
return NULL;
}
if (constructor)
{
string_appendn (&decl, p, n);
string_append (&decl, "::");
string_appendn (&decl, p, n);
}
else
{
string_prepend (&decl, "::");
string_prependn (&decl, p, n);
}
p += n;
#ifndef LONGERNAMES
remember_type (premangle, p - premangle);
#endif
success = do_args (&p, &decl);
if (const_flag)
string_append (&decl, " const");
break;
case 'F':
p += 1;
success = do_args (&p, &decl);
break;
}
for (i = 0; i < ntypes; i++)
if (typevec[i] != NULL)
free (typevec[i]);
ntypes = 0;
if (typevec != NULL)
{
free ((char *)typevec);
typevec = NULL;
typevec_size = 0;
}
if (success)
{
string_appendn (&decl, "", 1);
return decl.b;
}
else
{
string_delete (&decl);
return NULL;
}
}
static int
get_count (type, count)
const char **type;
int *count;
{
if (!isdigit (**type))
return 0;
*count = **type - '0';
*type += 1;
/* see flush_repeats in cplus-method.c */
if (isdigit (**type))
{
const char *p = *type;
int n = *count;
do
{
n *= 10;
n += *p - '0';
p += 1;
}
while (isdigit (*p));
if (*p == '_')
{
*type = p + 1;
*count = n;
}
}
return 1;
}
/* result will be initialised here; it will be freed on failure */
static int
do_type (type, result)
const char **type;
string *result;
{
int n;
int done;
int non_empty = 0;
int success;
string decl;
const char *remembered_type;
string_init (&decl);
string_init (result);
done = 0;
success = 1;
while (success && !done)
{
int member;
switch (**type)
{
case 'P':
*type += 1;
string_prepend (&decl, "*");
break;
case 'R':
*type += 1;
string_prepend (&decl, "&");
break;
case 'T':
*type += 1;
if (!get_count (type, &n) || n >= ntypes)
success = 0;
else
{
remembered_type = typevec[n];
type = &remembered_type;
}
break;
case 'F':
*type += 1;
if (!string_empty (&decl) && decl.b[0] == '*')
{
string_prepend (&decl, "(");
string_append (&decl, ")");
}
if (!do_args (type, &decl) || **type != '_')
success = 0;
else
*type += 1;
break;
case 'M':
case 'O':
{
int constp = 0;
int volatilep = 0;
member = **type == 'M';
*type += 1;
if (!isdigit (**type))
{
success = 0;
break;
}
n = 0;
do
{
n *= 10;
n += **type - '0';
*type += 1;
}
while (isdigit (**type));
if (strlen (*type) < n)
{
success = 0;
break;
}
string_append (&decl, ")");
string_prepend (&decl, "::");
string_prependn (&decl, *type, n);
string_prepend (&decl, "(");
*type += n;
if (member)
{
if (**type == 'C')
{
*type += 1;
constp = 1;
}
if (**type == 'V')
{
*type += 1;
volatilep = 1;
}
if (*(*type)++ != 'F')
{
success = 0;
break;
}
}
if ((member && !do_args (type, &decl)) || **type != '_')
{
success = 0;
break;
}
*type += 1;
if (constp)
{
if (non_empty)
string_append (&decl, " ");
else
non_empty = 1;
string_append (&decl, "const");
}
if (volatilep)
{
if (non_empty)
string_append (&decl, " ");
else
non_empty = 1;
string_append (&decl, "volatilep");
}
break;
}
case 'C':
if ((*type)[1] == 'P')
{
*type += 1;
if (!string_empty (&decl))
string_prepend (&decl, " ");
string_prepend (&decl, "const");
break;
}
/* fall through */
default:
done = 1;
break;
}
}
done = 0;
non_empty = 0;
while (success && !done)
{
switch (**type)
{
case 'C':
*type += 1;
if (non_empty)
string_append (result, " ");
else
non_empty = 1;
string_append (result, "const");
break;
case 'U':
*type += 1;
if (non_empty)
string_append (result, " ");
else
non_empty = 1;
string_append (result, "unsigned");
break;
case 'V':
*type += 1;
if (non_empty)
string_append (result, " ");
else
non_empty = 1;
string_append (result, "volatile");
break;
default:
done = 1;
break;
}
}
if (success)
switch (**type)
{
case '\0':
case '_':
break;
case 'v':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "void");
break;
case 'x':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "long long");
break;
case 'l':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "long");
break;
case 'i':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "int");
break;
case 's':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "short");
break;
case 'c':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "char");
break;
case 'r':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "long double");
break;
case 'd':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "double");
break;
case 'f':
*type += 1;
if (non_empty)
string_append (result, " ");
string_append (result, "float");
break;
case 'G':
*type += 1;
if (!isdigit (**type))
{
success = 0;
break;
}
/* fall through */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
n = 0;
do
{
n *= 10;
n += **type - '0';
*type += 1;
}
while (isdigit (**type));
if (strlen (*type) < n)
{
success = 0;
break;
}
if (non_empty)
string_append (result, " ");
string_appendn (result, *type, n);
*type += n;
break;
default:
success = 0;
break;
}
if (success)
{
if (!string_empty (&decl))
{
string_append (result, " ");
string_appends (result, &decl);
}
string_delete (&decl);
return 1;
}
else
{
string_delete (&decl);
string_delete (result);
return 0;
}
}
/* `result' will be initialised in do_type; it will be freed on failure */
static int
do_arg (type, result)
const char **type;
string *result;
{
const char *start = *type;
if (!do_type (type, result))
return 0;
remember_type (start, *type - start);
return 1;
}
static void
remember_type (start, len)
const char *start;
int len;
{
char *tem;
if (ntypes >= typevec_size)
{
if (typevec_size == 0)
{
typevec_size = 3;
typevec = (char **) xmalloc (sizeof (char*)*typevec_size);
}
else
{
typevec_size *= 2;
typevec = (char **) xrealloc ((char *)typevec, sizeof (char*)*typevec_size);
}
}
tem = (char *) xmalloc (len + 1);
memcpy (tem, start, len);
tem[len] = '\0';
typevec[ntypes++] = tem;
}
/* `decl' must be already initialised, usually non-empty;
it won't be freed on failure */
static int
do_args (type, decl)
const char **type;
string *decl;
{
string arg;
int need_comma = 0;
string_append (decl, "(");
while (**type != '_' && **type != '\0' && **type != 'e' && **type != 'v')
{
if (**type == 'N')
{
int r;
int t;
*type += 1;
if (!get_count (type, &r) || !get_count (type, &t) || t >= ntypes)
return 0;
while (--r >= 0)
{
const char *tem = typevec[t];
if (need_comma)
string_append (decl, ", ");
if (!do_arg (&tem, &arg))
return 0;
string_appends (decl, &arg);
string_delete (&arg);
need_comma = 1;
}
}
else
{
if (need_comma)
string_append (decl, ", ");
if (!do_arg (type, &arg))
return 0;
string_appends (decl, &arg);
string_delete (&arg);
need_comma = 1;
}
}
if (**type == 'v')
*type += 1;
else if (**type == 'e')
{
*type += 1;
if (need_comma)
string_append (decl, ",");
string_append (decl, "...");
}
string_append (decl, ")");
return 1;
}
static void
munge_function_name (name)
string *name;
{
if (!string_empty (name) && name->p - name->b >= 3
&& name->b[0] == 'o' && name->b[1] == 'p' && name->b[2] == '$')
{
int i;
/* see if it's an assignment expression */
if (name->p - name->b >= 10 /* op$assign_ */
&& memcmp (name->b + 3, "assign_", 7) == 0)
{
for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)
{
int len = name->p - name->b - 10;
if (strlen (optable[i].in) == len
&& memcmp (optable[i].in, name->b + 10, len) == 0)
{
string_clear (name);
string_append (name, "operator");
string_append (name, optable[i].out);
string_append (name, "=");
return;
}
}
}
else
{
for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)
{
int len = name->p - name->b - 3;
if (strlen (optable[i].in) == len
&& memcmp (optable[i].in, name->b + 3, len) == 0)
{
string_clear (name);
string_append (name, "operator");
string_append (name, optable[i].out);
return;
}
}
}
return;
}
else if (!string_empty (name) && name->p - name->b >= 5
&& memcmp (name->b, "type$", 5) == 0)
{
/* type conversion operator */
string type;
const char *tem = name->b + 5;
if (do_type (&tem, &type))
{
string_clear (name);
string_append (name, "operator ");
string_appends (name, &type);
string_delete (&type);
return;
}
}
}
/* a mini string-handling package */
static void
string_need (s, n)
string *s;
int n;
{
if (s->b == NULL)
{
if (n < 32)
n = 32;
s->p = s->b = (char *) xmalloc (n);
s->e = s->b + n;
}
else if (s->e - s->p < n)
{
int tem = s->p - s->b;
n += tem;
n *= 2;
s->b = (char *) xrealloc (s->b, n);
s->p = s->b + tem;
s->e = s->b + n;
}
}
static void
string_delete (s)
string *s;
{
if (s->b != NULL)
{
free (s->b);
s->b = s->e = s->p = NULL;
}
}
static void
string_init (s)
string *s;
{
s->b = s->p = s->e = NULL;
}
static void
string_clear (s)
string *s;
{
s->p = s->b;
}
static int
string_empty (s)
string *s;
{
return s->b == s->p;
}
static void
string_append (p, s)
string *p;
const char *s;
{
int n;
if (s == NULL || *s == '\0')
return;
n = strlen (s);
string_need (p, n);
memcpy (p->p, s, n);
p->p += n;
}
static void
string_appends (p, s)
string *p, *s;
{
int n;
if (s->b == s->p)
return;
n = s->p - s->b;
string_need (p, n);
memcpy (p->p, s->b, n);
p->p += n;
}
static void
string_appendn (p, s, n)
string *p;
const char *s;
int n;
{
if (n == 0)
return;
string_need (p, n);
memcpy (p->p, s, n);
p->p += n;
}
static void
string_prepend (p, s)
string *p;
const char *s;
{
if (s == NULL || *s == '\0')
return;
string_prependn (p, s, strlen (s));
}
#if 0
static void
string_prepends (p, s)
string *p, *s;
{
if (s->b == s->p)
return;
string_prependn (p, s->b, s->p - s->b);
}
#endif
static void
string_prependn (p, s, n)
string *p;
const char *s;
int n;
{
char *q;
if (n == 0)
return;
string_need (p, n);
for (q = p->p - 1; q >= p->b; q--)
q[n] = q[0];
memcpy (p->b, s, n);
p->p += n;
}

View File

@ -32,7 +32,7 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91";
Set, indirect, and warning symbol features added by Randy Smith. */
/*
* $Id: ld.c,v 1.35 1996/07/12 19:08:20 jkh Exp $
* $Id: ld.c,v 1.36 1996/10/01 01:22:23 peter Exp $
*/
/* Define how to initialize system-dependent header fields. */
@ -1323,7 +1323,7 @@ enter_file_symbols(entry)
} else if (strcmp(sp->warning, msg))
warnx(
"%s: multiple definitions for warning symbol `%s'",
get_file_name(entry), sp->name);
get_file_name(entry), demangle(sp->name));
}
} else if (p->n_type & N_EXT) {
enter_global_ref(lsp,
@ -1457,7 +1457,7 @@ enter_global_ref(lsp, name, entry)
if (olddef && N_ISWEAK(&nzp->nlist) && !(sp->flags & GS_WEAK)) {
#ifdef DEBUG
printf("%s: not overridden by weak symbol from %s\n",
sp->name, get_file_name(entry));
demangle(sp->name), get_file_name(entry));
#endif
return;
}
@ -1599,7 +1599,7 @@ enter_global_ref(lsp, name, entry)
break;
}
fprintf(stderr, "symbol %s %s%s in ", sp->name,
fprintf(stderr, "symbol %s %s%s in ", demangle(sp->name),
(N_ISWEAK(&nzp->nlist))?"weakly ":"", reftype);
print_file_name (entry, stderr);
fprintf(stderr, "\n");
@ -1856,7 +1856,7 @@ digest_pass1()
if (relocatable_output)
errx(1,
"internal error: global ref to set el %s with -r",
sp->name);
demangle(sp->name));
if (!defs++) {
sp->defined = N_SETV | N_EXT;
sp->value =
@ -1937,7 +1937,7 @@ digest_pass1()
if (undefined_global_sym_count < 0)
errx(1,
"internal error: digest_pass1,1: %s: undefined_global_sym_count = %d",
sp->name, undefined_global_sym_count);
demangle(sp->name), undefined_global_sym_count);
continue;
}
@ -1985,7 +1985,7 @@ digest_pass1()
if (sp->def_lsp) {
#ifdef DEBUG
printf("pass1: SO definition for %s, type %x in %s at %#x\n",
sp->name, sp->so_defined, get_file_name(sp->def_lsp->entry),
demangle(sp->name), sp->so_defined, get_file_name(sp->def_lsp->entry),
sp->def_lsp->nzlist.nz_value);
#endif
sp->def_lsp->entry->flags |= E_SYMBOLS_USED;
@ -1996,7 +1996,7 @@ printf("pass1: SO definition for %s, type %x in %s at %#x\n",
if (undefined_global_sym_count < 0)
errx(1, "internal error: digest_pass1,2: "
"%s: undefined_global_sym_count = %d",
sp->name, undefined_global_sym_count);
demangle(sp->name), undefined_global_sym_count);
if (sp->alias &&
!(sp->alias->flags & GS_REFERENCED)) {
sp = sp->alias;
@ -2006,7 +2006,7 @@ printf("pass1: SO definition for %s, type %x in %s at %#x\n",
if (sp->common_size == 0)
errx(1, "internal error: digest_pass1,3: "
"%s: not a common: %x",
sp->name, sp->defined);
demangle(sp->name), sp->defined);
/*
* Common not bound to shared object data; treat
* it now like other defined symbols were above.
@ -2093,7 +2093,7 @@ consider_relocation(entry, dataseg)
sp = sp->alias;
if (sp->flags & GS_TRACE) {
fprintf(stderr, "symbol %s has jmpslot in %s\n",
sp->name, get_file_name(entry));
demangle(sp->name), get_file_name(entry));
}
alloc_rrs_jmpslot(entry, sp);
@ -2154,7 +2154,7 @@ consider_relocation(entry, dataseg)
if (sp->flags & GS_TRACE) {
fprintf(stderr,
"symbol %s RRS entry in %s\n",
sp->name, get_file_name(entry));
demangle(sp->name), get_file_name(entry));
}
alloc_rrs_reloc(entry, sp);
continue;
@ -2375,7 +2375,7 @@ digest_pass2()
*/
if (sp->so_defined != (N_INDR+N_EXT))
warnx( "pass2: %s: alias isn't",
sp->name);
demangle(sp->name));
sp->defined = sp->so_defined;
sp->so_defined = 0;
}
@ -2445,7 +2445,7 @@ digest_pass2()
undefined_global_sym_count++;
if (sp->flags & GS_TRACE)
printf("symbol %s assigned to location %#lx\n",
sp->name, sp->value);
demangle(sp->name), sp->value);
}
/*
@ -2460,14 +2460,14 @@ digest_pass2()
* It's a common.
*/
if (sp->defined != (N_UNDF + N_EXT))
errx(1, "%s: common isn't", sp->name);
errx(1, "%s: common isn't", demangle(sp->name));
} else if ((size = sp->size) != 0 && sp->defined == N_SIZE) {
/*
* It's data from shared object with size info.
*/
if (!sp->so_defined)
errx(1, "%s: Bogus N_SIZE item", sp->name);
errx(1, "%s: Bogus N_SIZE item", demangle(sp->name));
} else
/*
@ -2511,7 +2511,7 @@ digest_pass2()
if (write_map)
printf("Allocating %s %s: %x at %lx\n",
sp->defined==(N_BSS|N_EXT)?"common":"data",
sp->name, size, sp->value);
demangle(sp->name), size, sp->value);
} END_EACH_SYMBOL;
}
@ -2526,7 +2526,7 @@ write_output()
struct stat statbuf;
int filemode;
mode_t u_mask;
if (lstat(output_filename, &statbuf) == 0) {
if (S_ISREG(statbuf.st_mode))
(void)unlink(output_filename);
@ -2534,7 +2534,7 @@ write_output()
u_mask = umask(0);
(void)umask(u_mask);
outstream = fopen(output_filename, "w");
if (outstream == NULL)
err(1, "fopen: %s", output_filename);
@ -2896,7 +2896,7 @@ perform_relocation(data, data_size, reloc, nreloc, entry, dataseg)
if (sp->flags & GS_TRACE) {
fprintf(stderr,
"symbol %s defined as %x in %s\n",
sp->name, sp->defined,
demangle(sp->name), sp->defined,
get_file_name(entry) );
}
if (sp == got_symbol) {
@ -2923,7 +2923,7 @@ perform_relocation(data, data_size, reloc, nreloc, entry, dataseg)
*/
if (!sp->size)
errx(1, "Copy item isn't: %s",
sp->name);
demangle(sp->name));
relocation = addend + sp->value;
r->r_address = sp->value;
@ -2943,7 +2943,7 @@ perform_relocation(data, data_size, reloc, nreloc, entry, dataseg)
if (sp->flags & GS_TRACE) {
fprintf(stderr,
"symbol %s claims RRS in %s%s\n",
sp->name, get_file_name(entry),
demangle(sp->name), get_file_name(entry),
(sp->so_defined == (N_TEXT+N_EXT) &&
sp->flags & GS_HASJMPSLOT)?
" (JMPSLOT)":"");
@ -3429,7 +3429,7 @@ write_syms()
if (building_shared_object)
continue;
if (!(sp->flags & GS_WEAK))
warnx("symbol %s remains undefined", sp->name);
warnx("symbol %s remains undefined", demangle(sp->name));
}
if (syms_written >= global_sym_count)
@ -3468,7 +3468,7 @@ write_syms()
if (nl.n_type == (N_INDR|N_EXT) &&
sp->value != 0)
errx(1, "%s: N_INDR has value %#x",
sp->name, sp->value);
demangle(sp->name), sp->value);
nl.n_value = sp->value;
if (sp->def_lsp)
bind = N_BIND(&sp->def_lsp->nzlist.nlist);
@ -3494,7 +3494,7 @@ write_syms()
} else
errx(1,
"internal error: %s defined in mysterious way",
sp->name);
demangle(sp->name));
/*
* Allocate string table space for the symbol name.
@ -3537,7 +3537,7 @@ write_syms()
}
#ifdef DEBUG
printf("writesym(#%d): %s, type %x\n", syms_written, sp->name, sp->defined);
printf("writesym(#%d): %s, type %x\n", syms_written, demangle(sp->name), sp->defined);
#endif
} END_EACH_SYMBOL;
@ -3647,7 +3647,7 @@ write_file_syms(entry, syms_written_addr)
continue;
if (discard_locals == DISCARD_ALL ||
(discard_locals == DISCARD_L &&
(discard_locals == DISCARD_L &&
(lsp->flags & LS_L_SYMBOL))) {
/*
* The user wants to discard this symbol, but it

View File

@ -1,5 +1,5 @@
/*
* $Id: ld.h,v 1.16 1996/04/20 18:27:55 jdp Exp $
* $Id: ld.h,v 1.17 1996/10/01 01:22:27 peter Exp $
*/
/*-
* This code is derived from software copyrighted by the Free Software
@ -53,6 +53,11 @@ extern int netzmagic;
#endif
#endif
#ifdef DEMANGLE_CPLUSPLUS
extern char *demangle __P((char*));
#else
#define demangle(name) name
#endif
/*
* Ok. Following are the relocation information macros. If your
@ -342,9 +347,9 @@ struct string_list_element {
};
struct glosym;
#ifndef __symbol_defined__
#define __symbol_defined__
typedef struct glosym symbol;
#ifndef __symbol_defined__
#define __symbol_defined__
typedef struct glosym symbol;
#endif
extern symbol *entry_symbol; /* the entry symbol, if any */

View File

@ -30,7 +30,7 @@
Set, indirect, and warning symbol features added by Randy Smith. */
/*
* $Id: lib.c,v 1.17 1996/07/12 19:08:23 jkh Exp $ - library routines
* $Id: lib.c,v 1.18 1996/10/01 01:22:30 peter Exp $ - library routines
*/
#include <sys/param.h>
@ -544,7 +544,7 @@ subfile_wanted_p(entry)
continue;
if (write_map) {
print_file_name(entry, stdout);
fprintf(stdout, " needed due to %s\n", sp->name);
fprintf(stdout, " needed due to %s\n", demangle(sp->name));
}
return 1;
} else if (!sp->defined && sp->sorefs) {
@ -598,7 +598,7 @@ subfile_wanted_p(entry)
print_file_name(entry, stdout);
fprintf(stdout,
" needed due to shared lib ref %s (%d)\n",
sp->name,
demangle(sp->name),
lsp ? lsp->nzlist.nlist.n_type : -1);
}
return 1;
@ -874,4 +874,3 @@ struct file_entry *p;
(void)free(fname);
return fd;
}

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: rrs.c,v 1.16 1996/07/12 19:08:27 jkh Exp $
* $Id: rrs.c,v 1.17 1996/10/01 01:22:35 peter Exp $
*/
#include <sys/param.h>
@ -174,7 +174,7 @@ alloc_rrs_reloc(entry, sp)
symbol *sp;
{
#ifdef DEBUG
printf("alloc_rrs_reloc: %s in %s\n", sp->name, get_file_name(entry));
printf("alloc_rrs_reloc: %s in %s\n", demangle(sp->name), get_file_name(entry));
#endif
reserved_rrs_relocs++;
}
@ -260,7 +260,7 @@ alloc_rrs_cpy_reloc(entry, sp)
if (sp->flags & GS_CPYRELOCRESERVED)
return;
#ifdef DEBUG
printf("alloc_rrs_copy: %s in %s\n", sp->name, get_file_name(entry));
printf("alloc_rrs_copy: %s in %s\n", demangle(sp->name), get_file_name(entry));
#endif
sp->flags |= GS_CPYRELOCRESERVED;
reserved_rrs_relocs++;
@ -297,10 +297,10 @@ claim_rrs_reloc(entry, rp, sp, relocation)
if (rp->r_address < text_start + text_size)
warnx("%s: RRS text relocation at %#x for \"%s\"",
get_file_name(entry), rp->r_address, sp->name);
get_file_name(entry), rp->r_address, demangle(sp->name));
#ifdef DEBUG
printf("claim_rrs_reloc: %s in %s\n", sp->name, get_file_name(entry));
printf("claim_rrs_reloc: %s in %s\n", demangle(sp->name), get_file_name(entry));
#endif
r->r_address = rp->r_address;
r->r_symbolnum = sp->rrs_symbolnum;
@ -308,7 +308,7 @@ printf("claim_rrs_reloc: %s in %s\n", sp->name, get_file_name(entry));
if (link_mode & SYMBOLIC) {
if (!sp->defined)
warnx("Cannot reduce symbol \"%s\" in %s",
sp->name, get_file_name(entry));
demangle(sp->name), get_file_name(entry));
RELOC_EXTERN_P(r) = 0;
*relocation += sp->value;
(void) md_make_reloc(rp, r, RELTYPE_RELATIVE);
@ -335,7 +335,7 @@ claim_rrs_jmpslot(entry, rp, sp, addend)
errx(1, "internal error: "
"%s: claim_rrs_jmpslot: %s: no reservation",
get_file_name(entry),
sp->name);
demangle(sp->name));
if (sp->jmpslot_offset != -1)
return rrs_sdt.sdt_plt + sp->jmpslot_offset;
@ -346,13 +346,13 @@ claim_rrs_jmpslot(entry, rp, sp, addend)
#ifdef DEBUG
printf("claim_rrs_jmpslot: %s: %s(%d) -> offset %x\n",
get_file_name(entry),
sp->name, sp->rrs_symbolnum, sp->jmpslot_offset);
demangle(sp->name), sp->rrs_symbolnum, sp->jmpslot_offset);
#endif
if ((link_mode & SYMBOLIC) || rrs_section_type == RRS_PARTIAL) {
if (!sp->defined)
warnx("Cannot reduce symbol \"%s\" in %s",
sp->name, get_file_name(entry));
demangle(sp->name), get_file_name(entry));
md_fix_jmpslot( rrs_plt + sp->jmpslot_offset/sizeof(jmpslot_t),
rrs_sdt.sdt_plt + sp->jmpslot_offset,
@ -414,7 +414,7 @@ claim_rrs_gotslot(entry, rp, lsp, addend)
if (!(sp->flags & GS_HASGOTSLOT))
errx(1, "internal error: "
"%s: claim_rrs_gotslot: %s: no reservation",
get_file_name(entry), sp->name);
get_file_name(entry), demangle(sp->name));
if (sp->gotslot_offset != -1) {
#ifdef DIAGNOSTIC
@ -423,7 +423,7 @@ claim_rrs_gotslot(entry, rp, lsp, addend)
? sp->value : 0))
errx(1, "%s: %s: gotslot at %#x is multiple valued, "
"*got = %#x, addend = %#x, sp->value = %#x",
get_file_name(entry), sp->name,
get_file_name(entry), demangle(sp->name),
sp->gotslot_offset,
*GOTP(sp->gotslot_offset), addend, sp->value);
#endif
@ -437,14 +437,14 @@ claim_rrs_gotslot(entry, rp, lsp, addend)
if (current_got_offset > max_got_offset)
errx(1, "%s: GOT overflow on symbol `%s' at %#x",
get_file_name(entry), sp->name, RELOC_ADDRESS(rp));
get_file_name(entry), demangle(sp->name), RELOC_ADDRESS(rp));
sp->gotslot_offset = current_got_offset;
current_got_offset += sizeof(got_t);
#ifdef DEBUG
printf("claim_rrs_gotslot: %s(%d,%#x) slot offset %#x, addend %#x\n",
sp->name, sp->rrs_symbolnum, sp->value, sp->gotslot_offset, addend);
demangle(sp->name), sp->rrs_symbolnum, sp->value, sp->gotslot_offset, addend);
#endif
if (sp->defined &&
@ -464,7 +464,7 @@ printf("claim_rrs_gotslot: %s(%d,%#x) slot offset %#x, addend %#x\n",
* so again all symbols must be known.
*/
warnx("Cannot reduce symbol \"%s\" in %s",
sp->name, get_file_name(entry));
demangle(sp->name), get_file_name(entry));
} else {
@ -483,7 +483,7 @@ printf("claim_rrs_gotslot: %s(%d,%#x) slot offset %#x, addend %#x\n",
*/
if (!sp->defined)
warnx("Cannot reduce symbol \"%s\" in %s",
sp->name, get_file_name(entry));
demangle(sp->name), get_file_name(entry));
discarded_rrs_relocs++;
return sp->gotslot_offset;
}
@ -585,11 +585,11 @@ claim_rrs_cpy_reloc(entry, rp, sp)
if (!(sp->flags & GS_CPYRELOCRESERVED))
errx(1, "internal error: "
"%s: claim_cpy_reloc: %s: no reservation",
get_file_name(entry), sp->name);
get_file_name(entry), demangle(sp->name));
#ifdef DEBUG
printf("claim_rrs_copy: %s: %s -> %x\n",
get_file_name(entry), sp->name, sp->so_defined);
get_file_name(entry), demangle(sp->name), sp->so_defined);
#endif
r = rrs_next_reloc();
@ -1129,14 +1129,14 @@ write_rrs_text()
*/
if (sp->aux != AUX_FUNC)
errx(1, "%s: non-function jmpslot",
sp->name);
demangle(sp->name));
nlp->nz_other = N_OTHER(bind, sp->aux);
nlp->nz_value =
rrs_sdt.sdt_plt + sp->jmpslot_offset;
}
} else
errx(1, "internal error: %s defined in mysterious way",
sp->name);
demangle(sp->name));
/* Set symbol's name */
nlp->nz_strx = offset;

View File

@ -30,7 +30,7 @@
Set, indirect, and warning symbol features added by Randy Smith. */
/*
* $Id: warnings.c,v 1.11 1996/07/12 19:08:29 jkh Exp $
* $Id: warnings.c,v 1.12 1996/10/01 01:22:48 peter Exp $
*/
#include <sys/param.h>
@ -59,6 +59,26 @@
static int reported_undefineds;
#ifdef DEMANGLE_CPLUSPLUS
#include "demangle.h"
char *demangle(name)
char *name;
{
static char* saved_result = NULL;
if (saved_result)
free (saved_result);
saved_result = cplus_demangle (name[0] == '_' ? name + 1 : name, DMGL_PARAMS | DMGL_ANSI);
if (saved_result)
return saved_result;
else
return name;
}
#endif
/*
* Print the filename of ENTRY on OUTFILE (a stdio stream),
* and then a newline.
@ -135,7 +155,7 @@ print_symbols(outfile)
fprintf(outfile, "\nGlobal symbols:\n\n");
FOR_EACH_SYMBOL(i, sp) {
fprintf(outfile, " %s: ", sp->name);
fprintf(outfile, " %s: ", demangle(sp->name));
if (!(sp->flags & GS_REFERENCED))
fprintf(outfile, "unreferenced");
else if (sp->so_defined)
@ -148,7 +168,7 @@ print_symbols(outfile)
fprintf(outfile, "type %d, value %#lx, size %#x",
sp->defined, sp->value, sp->size);
if (sp->alias)
fprintf(outfile, ", aliased to %s", sp->alias->name);
fprintf(outfile, ", aliased to %s", demangle(sp->alias->name));
fprintf(outfile, "\n");
} END_EACH_SYMBOL;
@ -490,7 +510,7 @@ do_relocation_warnings(entry, data_segment, outfile, nlist_bitvector)
if (!(lsp->nzlist.nz_type & N_EXT) &&
!SET_ELEMENT_P(lsp->nzlist.nz_type)) {
warnx("internal error: `%s' N_EXT not set", g->name);
warnx("internal error: `%s' N_EXT not set", demangle(g->name));
continue;
}
@ -534,14 +554,10 @@ do_relocation_warnings(entry, data_segment, outfile, nlist_bitvector)
/* If errfmt == 0, errmsg has already been defined. */
if (errfmt != 0) {
char *nm;
nm = g->name;
char *nm = demangle(g->name);
errmsg = (char *)
xmalloc(strlen(errfmt) + strlen(nm) + 1);
sprintf(errmsg, errfmt, nm, data_segment?"data":"text");
if (nm != g->name)
free(nm);
}
address_to_line(RELOC_ADDRESS(rp) + start_of_segment,
state_pointer);
@ -614,7 +630,7 @@ do_file_warnings (entry, outfile)
continue;
if (!(np->n_type & N_EXT) && !SET_ELEMENT_P(np->n_type)) {
warnx("internal error: `%s' N_EXT not set", g->name);
warnx("internal error: `%s' N_EXT not set", demangle(g->name));
continue;
}
@ -634,7 +650,7 @@ do_file_warnings (entry, outfile)
if (type == (N_UNDF | N_EXT)) {
fprintf(stderr,
"Undefined symbol %s referenced from %s\n",
g->name,
demangle(g->name),
get_file_name(entry));
}
#endif
@ -690,7 +706,7 @@ do_file_warnings (entry, outfile)
warnx("%s: unexpected multiple definitions "
"of symbol `%s', type %#x",
get_file_name(entry),
g->name, np->n_type);
demangle(g->name), np->n_type);
break;
}
@ -714,7 +730,7 @@ do_file_warnings (entry, outfile)
fprintf(outfile,
"%s: Undefined symbol `%s' referenced (use %s ?)\n",
get_file_name(entry),
g->name,
demangle(g->name),
g->def_lsp->entry->local_sym_name);
continue;
} else if (g->warning) {
@ -742,7 +758,7 @@ do_file_warnings (entry, outfile)
if (dont_allow_symbol_name)
fprintf(outfile, "%s", errfmt);
else
fprintf(outfile, errfmt, g->name);
fprintf(outfile, errfmt, demangle(g->name));
fputc('\n', outfile);
}
@ -770,7 +786,7 @@ do_warnings(outfile)
if (entry_symbol && !entry_symbol->defined)
fprintf(outfile, "Undefined entry symbol `%s'\n",
entry_symbol->name);
demangle(entry_symbol->name));
each_file(do_file_warnings, (void *)outfile);
@ -787,4 +803,3 @@ do_warnings(outfile)
return 1;
}