PATCH: PR 857: Disallow local symbol set to undefined symbol
H. J. Lu
hjl@lucon.org
Tue Apr 19 21:21:00 GMT 2005
We shouldn't allow local symbol set to undefined symbol. Also we
don't allow
.set bar,foo
.comm foo,4,4
But allow
.comm foo,4,4
.set bar,foo
This patch fixes those bugs.
H.J.
----
2005-04-19 H.J. Lu <hongjiu.lu@intel.com>
* read.c (pseudo_set): Disallow symbol set to common symbol.
* write.c (write_object_file): Report common symbol name when
disallowing symbol set to common symbol. Call S_IS_EXTERNAL
instead of S_IS_EXTERN.
PR 857
* write.c (adjust_reloc_syms): Disallow local symbol set to
undefined symbol.
--- gas/read.c.set 2005-04-11 09:10:33.000000000 -0700
+++ gas/read.c 2005-04-19 13:35:07.000000000 -0700
@@ -3299,6 +3299,10 @@ pseudo_set (symbolS *symbolP)
{
symbolS *s = exp.X_add_symbol;
+ if (S_IS_COMMON (s))
+ as_bad (_("`%s' can't be equated to common symbol '%s'"),
+ S_GET_NAME (symbolP), S_GET_NAME (s));
+
S_SET_SEGMENT (symbolP, seg);
S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
symbol_set_frag (symbolP, symbol_get_frag (s));
--- gas/write.c.set 2005-03-03 08:56:18.000000000 -0800
+++ gas/write.c 2005-04-19 13:39:34.000000000 -0700
@@ -787,12 +787,18 @@ adjust_reloc_syms (bfd *abfd ATTRIBUTE_U
if (fixp->fx_subsy != NULL)
resolve_symbol_value (fixp->fx_subsy);
- /* If this symbol is equated to an undefined symbol, convert
- the fixup to being against that symbol. */
+ /* If this symbol is equated to an undefined or common symbol,
+ convert the fixup to being against that symbol. */
if (symbol_equated_reloc_p (sym))
{
+ symbolS *new_sym
+ = symbol_get_value_expression (sym)->X_add_symbol;
+ if (!S_IS_COMMON (new_sym)
+ && (!S_IS_EXTERNAL (sym) || S_IS_LOCAL (sym)))
+ as_bad (_("Local symbol `%s' can't be equated to undefined symbol `%s'"),
+ S_GET_NAME (sym), S_GET_NAME (new_sym));
fixp->fx_offset += symbol_get_value_expression (sym)->X_add_number;
- sym = symbol_get_value_expression (sym)->X_add_symbol;
+ sym = new_sym;
fixp->fx_addsy = sym;
}
@@ -1928,8 +1934,12 @@ write_object_file (void)
if (symbol_equated_reloc_p (symp))
{
if (S_IS_COMMON (symp))
- as_bad (_("`%s' can't be equated to common symbol"),
- S_GET_NAME (symp));
+ {
+ symbolS *c
+ = symbol_get_value_expression (symp)->X_add_symbol;
+ as_bad (_("`%s' can't be equated to common symbol `%s'"),
+ S_GET_NAME (symp), S_GET_NAME (c));
+ }
symbol_remove (symp, &symbol_rootP, &symbol_lastP);
continue;
}
@@ -1956,10 +1966,10 @@ write_object_file (void)
if (symp == abs_section_sym
|| (! EMIT_SECTION_SYMBOLS
&& symbol_section_p (symp))
- /* Note that S_IS_EXTERN and S_IS_LOCAL are not always
+ /* Note that S_IS_EXTERNAL and S_IS_LOCAL are not always
opposites. Sometimes the former checks flags and the
latter examines the name... */
- || (!S_IS_EXTERN (symp)
+ || (!S_IS_EXTERNAL (symp)
&& (punt || S_IS_LOCAL (symp))
&& ! symbol_used_in_reloc_p (symp)))
{
More information about the Binutils
mailing list