This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: The mips gas is broken


On Tue, Jul 03, 2001 at 04:03:31PM +0100, Nick Clifton wrote:
> 
> This is all to do with md_convert_frag which gets called from
> cvt_frag_to_fill which gets called from size_seg.  It seems that MIPS
> (and probably other ports) needs the symbols resolved so that it can
> determine the distance betwen instructions and the symbols that they
> reference.

This small change to S_GET_VALUE would make it irrelevant where we
set finalize_syms.  Unfortunately, backend code needs to change too.

--- symbols.c	2001/06/05 08:29:59	1.25
+++ symbols.c	2001/07/05 04:24:07
@@ -1574,10 +1574,10 @@ S_GET_VALUE (s)
 {
 #ifdef BFD_ASSEMBLER
   if (LOCAL_SYMBOL_CHECK (s))
-    return ((struct local_symbol *) s)->lsy_offset;
+    return resolve_symbol_value (s);
 #endif
 
-  if (!s->sy_resolved && s->sy_value.X_op != O_constant)
+  if (!s->sy_resolved)
     {
       valueT val = resolve_symbol_value (s);
       if (!finalize_syms)

What am I doing here?  Well, fairly obviously, we will be calling
resolve_symbol_value for all unresolved symbols rather than
treating local syms and O_constant expressions specially.  (For
those who haven't poked around this code, most symbols are O_constant,
not O_symbol as you might expect.  A symbol defined in your code with
a `:' for instance, is a constant offset from the start of its frag.)
The special treatment for O_constant meant that S_GET_VALUE returned
the offset from the start of the frag rather than the final value, at
least until finalize_syms is set and resolve_symbol_value called for
that sym.  I guess this was originally an optimization, as frag
addresses are all zero until relax_seg runs.

So...  The above change will cause S_GET_VALUE to return the actual
value of a symbol after relaxation has completed, independent of
where finalize_syms is set and whether resolve_symbol_value has
been called for the symbol.

Pro: Before relaxation, we won't see any change as frag addresses are
     all zero.
   - Cures a potential problem with S_GET_VALUE being called for
     complex expressions after finalize_syms has been set but before
     all symbols are resolved (write.c:1900).  This will resolve all
     symbols in the expression, leading to some symbols having their
     final value, while most have yet to have their frag address added.
   - Removes the necessity for another TC_* macro.
   - Will get rid of comments about S_GET_VALUE not actually returning
     the value of a symbols.

Con: Symbol value during relaxation is a little tricky as the frag
     addresses are in flux, but relaxation needs to deal with this
     problem anyway.
   - Backends, write.c:relax_segment need some tweaks.
   - slower.
   - will probably break something.

Is it worth doing?

Alan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]