Bug 11658 - final_layout.sh failed
Summary: final_layout.sh failed
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: Sriraman Tallam
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-02 17:15 UTC by H.J. Lu
Modified: 2010-06-03 18:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2010-06-02 17:15:17 UTC
On Linux/x86-64 with gcc 4.2.4, I got

final layout of _Z3bazv and _Z3foov is not right.
FAIL: final_layout.sh
Comment 1 cvs-commit@gcc.gnu.org 2010-06-03 18:01:44 UTC
Subject: Bug 11658

CVSROOT:	/cvs/src
Module name:	src
Changes by:	tmsriram@sourceware.org	2010-06-03 18:01:20

Modified files:
	gold           : ChangeLog output.cc 

Log message:
	PR gold/11658
	* output.cc
	(Output_section::Input_section_sort_entry::compare_section_ordering):
	Change to return non-zero correctly.
	(Output_section::Input_section_sort_section_order_index_compare
	::operator()): Change to fix ambiguity in comparisons.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&r1=1.570&r2=1.571
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/output.cc.diff?cvsroot=src&r1=1.127&r2=1.128

Comment 2 Sriraman Tallam 2010-06-03 18:03:26 UTC
Fixed with patch :

2010-06-03  Sriraman Tallam  <tmsriram@google.com>

       PR gold/11658
       * output.cc
       (Output_section::Input_section_sort_entry::compare_section_ordering):
       Change to return non-zero correctly.
       (Output_section::Input_section_sort_section_order_index_compare
       ::operator()): Change to fix ambiguity in comparisons.


Index: output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.127
diff -u -u -p -r1.127 output.cc
--- output.cc	1 Jun 2010 23:37:57 -0000	1.127
+++ output.cc	3 Jun 2010 06:17:16 -0000
@@ -2801,20 +2801,21 @@ class Output_section::Input_section_sort
     return memcmp(base_name + base_len - 2, ".o", 2) == 0;
   }
 
-  // Returns 0 if sections are not comparable. Returns 1 if THIS is the
-  // first section in order, returns -1 for S.
+  // Returns 1 if THIS should appear before S in section order, -1 if S
+  // appears before THIS and 0 if they are not comparable.
   int
   compare_section_ordering(const Input_section_sort_entry& s) const
   {
-    gold_assert(this->index_ != -1U);
-    if (this->input_section_.section_order_index() == 0
-        || s.input_section().section_order_index() == 0)
-      return 0;
-    if (this->input_section_.section_order_index()
-        < s.input_section().section_order_index())
-      return 1;
-    else
-      return -1;
+    unsigned int this_secn_index = this->input_section_.section_order_index();
+    unsigned int s_secn_index = s.input_section().section_order_index();
+    if (this_secn_index > 0 && s_secn_index > 0)
+      {
+        if (this_secn_index < s_secn_index)
+          return 1;
+        else if (this_secn_index > s_secn_index)
+          return -1;
+      }
+    return 0;
   }
 
  private:
@@ -2935,20 +2936,23 @@ Output_section::Input_section_sort_init_
   return s1.index() < s2.index();
 }
 
-// Return true if S1 should come before S2.
+// Return true if S1 should come before S2.  Sections that do not match
+// any pattern in the section ordering file are placed ahead of the sections
+// that match some pattern.
+
 bool
 Output_section::Input_section_sort_section_order_index_compare::operator()(
     const Output_section::Input_section_sort_entry& s1,
     const Output_section::Input_section_sort_entry& s2) const
 {
-  // Check if a section order exists for these sections through a section
-  // ordering file.  If sequence_num is 0, an order does not exist.
-  int sequence_num = s1.compare_section_ordering(s2);
-  if (sequence_num != 0)
-    return sequence_num == 1;
+  unsigned int s1_secn_index = s1.input_section().section_order_index();
+  unsigned int s2_secn_index = s2.input_section().section_order_index();
 
-  // Otherwise we keep the input order.
-  return s1.index() < s2.index();
+  // Keep input order if section ordering cannot determine order.
+  if (s1_secn_index == s2_secn_index)
+    return s1.index() < s2.index();
+  
+  return s1_secn_index < s2_secn_index;
 }