This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR ld/1396: prohibited cross reference to a local symbol
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Sun, 2 Oct 2005 08:57:01 -0700
- Subject: Re: PATCH: PR ld/1396: prohibited cross reference to a local symbol
- References: <20051002142118.GA32215@lucon.org>
On Sun, Oct 02, 2005 at 07:21:18AM -0700, H. J. Lu wrote:
> When we process prohibited cross reference, we need to match the
> symbol type with the type of the symbol the relocation is against.
>
>
Here is an updated patch to check global and local symbols explicitly.
H.J.
-----
2005-10-02 H.J. Lu <hongjiu.lu@intel.com>
PR ld/1396
* ldcref.c (check_refs): Accept asymbol *.
(check_local_sym_xref): Pass sym to check_refs.
(check_nocrossref): Pass NULL to check_refs.
(check_refs_info): Add asymbol *.
(check_refs): Add asymbol * to check_refs_info.
(check_reloc_refs): Match relocations with proper symbols.
* ldmisc.c (vfinfo): Don't add extra ":\n".
--- ld/ldcref.c.local 2005-05-16 11:04:39.000000000 -0700
+++ ld/ldcref.c 2005-10-02 08:53:05.000000000 -0700
@@ -71,7 +71,7 @@ struct cref_hash_table {
static void output_one_cref (FILE *, struct cref_hash_entry *);
static void check_local_sym_xref (lang_input_statement_type *);
static bfd_boolean check_nocrossref (struct cref_hash_entry *, void *);
-static void check_refs (const char *, asection *, bfd *,
+static void check_refs (const char *, asymbol *, asection *, bfd *,
struct lang_nocrossrefs *);
static void check_reloc_refs (bfd *, asection *, void *);
@@ -387,7 +387,7 @@ check_local_sym_xref (lang_input_stateme
for (ncrs = nocrossref_list; ncrs != NULL; ncrs = ncrs->next)
for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
if (strcmp (ncr->name, outsecname) == 0)
- check_refs (symname, sym->section, abfd, ncrs);
+ check_refs (symname, sym, sym->section, abfd, ncrs);
}
}
@@ -429,7 +429,8 @@ check_nocrossref (struct cref_hash_entry
for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
if (strcmp (ncr->name, defsecname) == 0)
for (ref = h->refs; ref != NULL; ref = ref->next)
- check_refs (hl->root.string, hl->u.def.section, ref->abfd, ncrs);
+ check_refs (hl->root.string, NULL, hl->u.def.section,
+ ref->abfd, ncrs);
return TRUE;
}
@@ -439,6 +440,7 @@ check_nocrossref (struct cref_hash_entry
struct check_refs_info {
const char *sym_name;
+ asymbol *sym;
asection *defsec;
struct lang_nocrossrefs *ncrs;
asymbol **asymbols;
@@ -451,6 +453,7 @@ struct check_refs_info {
static void
check_refs (const char *name,
+ asymbol *sym,
asection *sec,
bfd *abfd,
struct lang_nocrossrefs *ncrs)
@@ -488,6 +491,7 @@ check_refs (const char *name,
}
info.sym_name = name;
+ info.sym = sym;
info.defsec = sec;
info.ncrs = ncrs;
info.asymbols = asymbols;
@@ -513,6 +517,7 @@ check_reloc_refs (bfd *abfd, asection *s
const char *outdefsecname;
struct lang_nocrossref *ncr;
const char *symname;
+ asymbol *sym;
long relsize;
arelent **relpp;
long relcount;
@@ -538,9 +543,13 @@ check_reloc_refs (bfd *abfd, asection *s
/* This section is one for which cross references are prohibited.
Look through the relocations, and see if any of them are to
INFO->SYM_NAME. If INFO->SYMNAME is NULL, check for relocations
- against the section symbol. */
+ against the section symbol. If INFO->SYM is NULL, the definition
+ is global, check for relocations against the global symbols.
+ Otherwise check for relocations against the local and section
+ symbols. */
symname = info->sym_name;
+ sym = info->sym;
relsize = bfd_get_reloc_upper_bound (abfd, sec);
if (relsize < 0)
@@ -561,6 +570,11 @@ check_reloc_refs (bfd *abfd, asection *s
if (q->sym_ptr_ptr != NULL
&& *q->sym_ptr_ptr != NULL
+ && (sym == NULL
+ || ((*q->sym_ptr_ptr)->flags & (BSF_LOCAL
+ | BSF_SECTION_SYM)) != 0)
+ && (sym != NULL
+ || ((*q->sym_ptr_ptr)->flags & BSF_GLOBAL) != 0)
&& (symname != NULL
? strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), symname) == 0
: (((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
--- ld/ldmisc.c.local 2005-06-03 22:27:08.000000000 -0700
+++ ld/ldmisc.c 2005-10-01 14:41:32.000000000 -0700
@@ -339,7 +339,7 @@ vfinfo (FILE *fp, const char *fmt, va_li
&& strcmp (last_file, filename) != 0)
|| strcmp (last_function, functionname) != 0)
{
- lfinfo (fp, _("%B: In function `%T':\n"),
+ lfinfo (fp, _("%B: In function `%T'"),
abfd, functionname);
last_bfd = abfd;
@@ -355,19 +355,19 @@ vfinfo (FILE *fp, const char *fmt, va_li
discard_last = FALSE;
}
else
- lfinfo (fp, "%B:", abfd);
+ lfinfo (fp, "%B", abfd);
if (filename != NULL)
- fprintf (fp, "%s:", filename);
+ fprintf (fp, ":%s", filename);
if (functionname != NULL && fmt[-1] == 'G')
- lfinfo (fp, "%T", functionname);
+ lfinfo (fp, ":%T", functionname);
else if (filename != NULL)
{
if (linenumber != 0)
- fprintf (fp, "%u", linenumber);
+ fprintf (fp, ":%u", linenumber);
else
- lfinfo (fp, "(%A+0x%v)", section, offset);
+ lfinfo (fp, ":(%A+0x%v)", section, offset);
}
}
else