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]

gold patch committed: Implement --check-sections


I committed this patch to implement --check-sections in gold.
--check-sections is on by default, as it is in GNU ld.

Ian


2008-07-22  Ian Lance Taylor  <iant@google.com>

	* options.h (class General_options): Define --check-sections.
	* layout.cc (Layout::set_segment_offsets): Handle
	--check-sections.


Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.109
diff -p -u -r1.109 layout.cc
--- layout.cc	22 Jul 2008 23:01:20 -0000	1.109
+++ layout.cc	22 Jul 2008 23:51:14 -0000
@@ -1732,6 +1732,9 @@ Layout::set_segment_offsets(const Target
 	}
     }
 
+  const bool check_sections = parameters->options().check_sections();
+  Output_segment* last_load_segment = NULL;
+
   bool was_readonly = false;
   for (Segment_list::iterator p = this->segment_list_.begin();
        p != this->segment_list_.end();
@@ -1848,6 +1851,25 @@ Layout::set_segment_offsets(const Target
 
 	  if (((*p)->flags() & elfcpp::PF_W) == 0)
 	    was_readonly = true;
+
+	  // Implement --check-sections.  We know that the segments
+	  // are sorted by LMA.
+	  if (check_sections && last_load_segment != NULL)
+	    {
+	      gold_assert(last_load_segment->paddr() <= (*p)->paddr());
+	      if (last_load_segment->paddr() + last_load_segment->memsz()
+		  > (*p)->paddr())
+		{
+		  unsigned long long lb1 = last_load_segment->paddr();
+		  unsigned long long le1 = lb1 + last_load_segment->memsz();
+		  unsigned long long lb2 = (*p)->paddr();
+		  unsigned long long le2 = lb2 + (*p)->memsz();
+		  gold_error(_("load segment overlap [0x%llx -> 0x%llx] and "
+			       "[0x%llx -> 0x%llx]"),
+			     lb1, le1, lb2, le2);
+		}
+	    }
+	  last_load_segment = *p;
 	}
     }
 
Index: options.h
===================================================================
RCS file: /cvs/src/src/gold/options.h,v
retrieving revision 1.82
diff -p -u -r1.82 options.h
--- options.h	22 Jul 2008 23:01:20 -0000	1.82
+++ options.h	22 Jul 2008 23:51:14 -0000
@@ -576,6 +576,10 @@ class General_options
 			 N_("Generate build ID note"),
 			 N_("[=STYLE]"));
 
+  DEFINE_bool(check_sections, options::TWO_DASHES, '\0', true,
+	      N_("Check segment addresses for overlaps (default)"),
+	      N_("Do not check segment addresses for overlaps"));
+
 #ifdef HAVE_ZLIB_H
   DEFINE_enum(compress_debug_sections, options::TWO_DASHES, '\0', "none",
               N_("Compress .debug_* sections in the output file"),

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