This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH 2.5/4 v2] GAS: Make new fake labels when cloning a symbol
- From: "Maciej W. Rozycki" <macro at codesourcery dot com>
- To: Richard Sandiford <rdsandiford at googlemail dot com>
- Cc: Catherine Moore <clm at codesourcery dot com>, binutils at sourceware dot org
- Date: Wed, 1 Dec 2010 21:34:39 +0000 (GMT)
- Subject: Re: [PATCH 2.5/4 v2] GAS: Make new fake labels when cloning a symbol
- References: <alpine.DEB.1.10.1007241721120.29495@tp.orcam.me.uk> <alpine.DEB.1.10.1010291442440.25860@tp.orcam.me.uk> <87aalwngmr.fsf@firetop.home> <alpine.DEB.1.10.1011011201550.27998@tp.orcam.me.uk> <87r5f4d92p.fsf@firetop.home>
On Mon, 1 Nov 2010, Richard Sandiford wrote:
> Sounds good, but please don't let it get in the way of applying this patch
> (when the time comes). The change above seems entirely in keeping with
> the way that abs_symbol is initialised.
This is the version I applied.
2010-12-01 Maciej W. Rozycki <macro@codesourcery.com>
* symbols.h (dot_symbol): New declaration.
(dot_symbol_init): New prototype.
* symbols.c (dot_symbol): New variable.
(symbol_clone): Assert it's not dot_symbol being cloned.
(dot_symbol_init): New function.
(symbol_clone_if_forward_ref): Create a new temporary symbol
when trying to clone dot_symbol.
* expr.c (current_location): Refer to dot_symbol instead of
making a new temporary symbol.
* read.c (read_a_source_file): Update dot_symbol as we go.
* as.c (main): Call dot_symbol_init.
Thanks,
Maciej
binutils-gas-dot.diff
Index: binutils-fsf-trunk-quilt/gas/symbols.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/symbols.c 2010-12-01 21:05:48.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/symbols.c 2010-12-01 21:05:48.000000000 +0000
@@ -48,6 +48,7 @@ static struct hash_control *local_hash;
symbolS *symbol_rootP;
symbolS *symbol_lastP;
symbolS abs_symbol;
+symbolS dot_symbol;
#ifdef DEBUG_SYMS
#define debug_verify_symchain verify_symbol_chain
@@ -557,6 +558,9 @@ symbol_clone (symbolS *orgsymP, int repl
symbolS *newsymP;
asymbol *bsymorg, *bsymnew;
+ /* Make sure we never clone the dot special symbol. */
+ gas_assert (orgsymP != &dot_symbol);
+
/* Running local_symbol_convert on a clone that's not the one currently
in local_hash would incorrectly replace the hash entry. Thus the
symbol must be converted here. Note that the rest of the function
@@ -658,8 +662,13 @@ symbol_clone_if_forward_ref (symbolS *sy
|| add_symbol != symbolP->sy_value.X_add_symbol
|| op_symbol != symbolP->sy_value.X_op_symbol)
{
- symbolP = symbol_clone (symbolP, 0);
- symbolP->sy_resolving = 0;
+ if (symbolP != &dot_symbol)
+ {
+ symbolP = symbol_clone (symbolP, 0);
+ symbolP->sy_resolving = 0;
+ }
+ else
+ symbolP = symbol_temp_new_now ();
}
symbolP->sy_value.X_add_symbol = add_symbol;
@@ -2749,6 +2758,17 @@ symbol_begin (void)
if (LOCAL_LABELS_FB)
fb_label_init ();
}
+
+void
+dot_symbol_init (void)
+{
+ dot_symbol.bsym = bfd_make_empty_symbol (stdoutput);
+ if (dot_symbol.bsym == NULL)
+ as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ()));
+ dot_symbol.bsym->name = ".";
+ dot_symbol.sy_forward_ref = 1;
+ dot_symbol.sy_value.X_op = O_constant;
+}
int indent_level;
Index: binutils-fsf-trunk-quilt/gas/expr.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/expr.c 2010-12-01 21:05:48.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/expr.c 2010-12-01 21:05:48.000000000 +0000
@@ -705,7 +705,7 @@ current_location (expressionS *expressio
else
{
expressionp->X_op = O_symbol;
- expressionp->X_add_symbol = symbol_temp_new_now ();
+ expressionp->X_add_symbol = &dot_symbol;
expressionp->X_add_number = 0;
}
}
Index: binutils-fsf-trunk-quilt/gas/symbols.h
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/symbols.h 2010-12-01 21:05:41.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/symbols.h 2010-12-01 21:05:48.000000000 +0000
@@ -28,6 +28,7 @@ extern symbolS *symbol_rootP; /* all the
extern symbolS *symbol_lastP; /* last struct symbol we made, or NULL */
extern symbolS abs_symbol;
+extern symbolS dot_symbol;
extern int symbol_table_frozen;
@@ -60,6 +61,7 @@ symbolS *symbol_temp_make (void);
symbolS *colon (const char *sym_name);
void local_colon (int n);
void symbol_begin (void);
+void dot_symbol_init (void);
void symbol_print_statistics (FILE *);
void symbol_table_insert (symbolS * symbolP);
valueT resolve_symbol_value (symbolS *);
Index: binutils-fsf-trunk-quilt/gas/read.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/read.c 2010-12-01 21:05:41.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/read.c 2010-12-01 21:05:48.000000000 +0000
@@ -629,6 +629,7 @@ read_a_source_file (char *name)
was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
if (was_new_line)
{
+ symbol_set_value_now (&dot_symbol);
#ifdef md_start_line_hook
md_start_line_hook ();
#endif
@@ -1128,6 +1129,7 @@ read_a_source_file (char *name)
md_after_pass_hook ();
#endif
}
+ symbol_set_value_now (&dot_symbol);
quit:
Index: binutils-fsf-trunk-quilt/gas/as.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/as.c 2010-12-01 21:05:41.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/as.c 2010-12-01 21:05:48.000000000 +0000
@@ -1181,6 +1181,8 @@ main (int argc, char ** argv)
output_file_create (out_file_name);
gas_assert (stdoutput != 0);
+ dot_symbol_init ();
+
#ifdef tc_init_after_args
tc_init_after_args ();
#endif