This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Re: as bug (was: Re: smp/up alternatives crash when CONFIG_HOTPLUG_CPU)


On Sat, May 06, 2006 at 12:41:41PM +0930, Alan Modra wrote:
> The reason why gas -al helps with this case is that gas creates a new
> frag for each line as somewhere to hang the file/line number info.  So
> both "661" and "662" start off at offset zero in their frags and the
> initial pass .fill has a zero length rather than a negative one.
> 
> So perhaps gas ought to be able to handle this after all..

Like this.

	* write.c (relax_segment): Add pass count arg.  Don't error on
	negative org/space on first two passes.
	(relax_seg_info): New struct.
	(relax_seg, write_object_file): Adjust.
	* write.h (relax_segment): Update prototype.

Index: gas/write.c
===================================================================
RCS file: /cvs/src/src/gas/write.c,v
retrieving revision 1.100
diff -u -p -r1.100 write.c
--- gas/write.c	3 May 2006 23:52:15 -0000	1.100
+++ gas/write.c	6 May 2006 06:44:19 -0000
@@ -512,19 +512,21 @@ cvt_frag_to_fill (segT sec ATTRIBUTE_UNU
 #endif
 }
 
-static void relax_seg (bfd *, asection *, PTR);
+struct relax_seg_info
+{
+  int pass;
+  int changed;
+};
 
 static void
-relax_seg (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, PTR xxx)
+relax_seg (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *xxx)
 {
   segment_info_type *seginfo = seg_info (sec);
+  struct relax_seg_info *info = (struct relax_seg_info *) xxx;
 
   if (seginfo && seginfo->frchainP
-      && relax_segment (seginfo->frchainP->frch_root, sec))
-    {
-      int *result = (int *) xxx;
-      *result = 1;
-    }
+      && relax_segment (seginfo->frchainP->frch_root, sec, info->pass))
+    info->changed = 1;
 }
 
 static void size_seg (bfd *, asection *, PTR);
@@ -1206,6 +1208,7 @@ subsegs_finish (void)
 void
 write_object_file (void)
 {
+  struct relax_seg_info rsi;
 #ifndef WORKING_DOT_WORD
   fragS *fragP;			/* Track along all frags.  */
 #endif
@@ -1264,10 +1267,9 @@ write_object_file (void)
       merge_data_into_text ();
     }
 
+  rsi.pass = 0;
   while (1)
     {
-      int changed;
-
 #ifndef WORKING_DOT_WORD
       /* We need to reset the markers in the broken word list and
 	 associated frags between calls to relax_segment (via
@@ -1288,9 +1290,10 @@ write_object_file (void)
 	}
 #endif
 
-      changed = 0;
-      bfd_map_over_sections (stdoutput, relax_seg, &changed);
-      if (!changed)
+      rsi.changed = 0;
+      bfd_map_over_sections (stdoutput, relax_seg, &rsi);
+      rsi.pass++;
+      if (!rsi.changed)
 	break;
     }
 
@@ -1721,7 +1724,7 @@ relax_align (register relax_addressT add
    addresses.  */
 
 int
-relax_segment (struct frag *segment_frag_root, segT segment)
+relax_segment (struct frag *segment_frag_root, segT segment, int pass)
 {
   unsigned long frag_count;
   struct frag *fragP;
@@ -1835,6 +1838,7 @@ relax_segment (struct frag *segment_frag
     if (max_iterations < frag_count)
       max_iterations = frag_count;
 
+    ret = 0;
     do
       {
 	stretch = 0;
@@ -1964,6 +1968,16 @@ relax_segment (struct frag *segment_frag
 		  growth = target - after;
 		  if (growth < 0)
 		    {
+		      growth = 0;
+
+		      /* Don't error on first few frag relax passes.  */
+		      if (pass < 2)
+			{
+			  /* Force another pass.  */
+			  ret = 1;
+			  break;
+			}
+
 		      /* Growth may be negative, but variable part of frag
 			 cannot have fewer than 0 chars.  That is, we can't
 			 .org backwards.  */
@@ -1976,7 +1990,7 @@ relax_segment (struct frag *segment_frag
 		      fragP->fr_subtype = 0;
 		      fragP->fr_offset = 0;
 		      fragP->fr_fix = after - was_address;
-		      growth = stretch;
+		      break;
 		    }
 
 		  /* This is an absolute growth factor  */
@@ -2002,6 +2016,14 @@ relax_segment (struct frag *segment_frag
 		      }
 		    else if (amount < 0)
 		      {
+			/* Don't error on first few frag relax passes.  */
+			if (pass < 2)
+			  {
+			    /* Force another pass.  */
+			    ret = 1;
+			    break;
+			  }
+
 			as_warn_where (fragP->fr_file, fragP->fr_line,
 				       _(".space or .fill with negative value, ignored"));
 			fragP->fr_symbol = 0;
@@ -2063,7 +2085,6 @@ relax_segment (struct frag *segment_frag
 		segment_name (segment));
   }
 
-  ret = 0;
   for (fragP = segment_frag_root; fragP; fragP = fragP->fr_next)
     if (fragP->last_fr_address != fragP->fr_address)
       {
Index: gas/write.h
===================================================================
RCS file: /cvs/src/src/gas/write.h,v
retrieving revision 1.14
diff -u -p -r1.14 write.h
--- gas/write.h	11 Aug 2005 01:25:20 -0000	1.14
+++ gas/write.h	6 May 2006 06:44:19 -0000
@@ -1,6 +1,6 @@
 /* write.h
    Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
-   2002, 2003, 2005 Free Software Foundation, Inc.
+   2002, 2003, 2005, 2006 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -156,7 +156,7 @@ extern int get_recorded_alignment (segT 
 extern void subsegs_finish (void);
 extern void write_object_file (void);
 extern long relax_frag (segT, fragS *, long);
-extern int relax_segment (struct frag * seg_frag_root, segT seg_type);
+extern int relax_segment (struct frag *, segT, int);
 extern void number_to_chars_littleendian (char *, valueT, int);
 extern void number_to_chars_bigendian (char *, valueT, int);
 extern fixS *fix_new


-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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