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: gold linker: Access section start & end address w/o using a linker script


To complete the story: While adding such symbols would be quite easy (see prototype-hack below), it's by far not enough to abandon linker scripts from our embedded project (and probably for embedded project  in general). In order to abandon linker scripts, we'd probably first need to analyse all relevant use-cases to come up with something else... 

Therefore, I stop investigating towards this direction. Just in case that someone stumbles over this thread and would find having start and end symbols useful, I post the code I came up with. But again: This is just a prototype.

Raphael

### Eclipse Workspace Patch 1.0
#P binutils-cvs
Index: gold/gold.h
===================================================================
RCS file: /cvs/src/src/gold/gold.h,v
retrieving revision 1.50
diff -u -r1.50 gold.h
--- gold/gold.h	24 Oct 2012 02:26:39 -0000	1.50
+++ gold/gold.h	12 May 2013 11:56:47 -0000
@@ -262,6 +262,15 @@
 	  == '\0');
 }
 
+inline bool
+matches_predefined_sectionname_scheme(const char* name)
+{
+	if ((strlen(name) > 0) && (name[0] == '.') ) {
+	    return is_cident(name+1);
+	}
+	return false;
+}
+
 // We sometimes need to hash strings.  Ideally we should use std::tr1::hash or
 // __gnu_cxx::hash on some systems but there is no guarantee that either
 // one is available.  For portability, we define simple string hash functions.
Index: gold/incremental.cc
===================================================================
RCS file: /cvs/src/src/gold/incremental.cc,v
retrieving revision 1.56
diff -u -r1.56 incremental.cc
--- gold/incremental.cc	1 Nov 2012 22:35:06 -0000	1.56
+++ gold/incremental.cc	12 May 2013 11:56:55 -0000
@@ -1947,16 +1947,20 @@
   struct Got_plt_view_info view_info;
   view_info.got_count = target->got_entry_count();
   view_info.plt_count = target->plt_entry_count();
-  view_info.first_plt_entry_offset = target->first_plt_entry_offset();
-  view_info.plt_entry_size = target->plt_entry_size();
+  if( view_info.plt_count ) {
+	  view_info.first_plt_entry_offset = target->first_plt_entry_offset();
+	  view_info.plt_entry_size = target->plt_entry_size();
+  } else {
+	  view_info.first_plt_entry_offset = 0;
+	  view_info.plt_entry_size = 0;
+  }
   view_info.got_type_p = pov + 8;
   view_info.got_desc_p = (view_info.got_type_p
 			  + ((view_info.got_count + 3) & ~3));
   view_info.plt_desc_p = view_info.got_desc_p + view_info.got_count * 8;
 
   gold_assert(pov + view_size ==
-	      view_info.plt_desc_p + view_info.plt_count * 4);
-
+		  view_info.plt_desc_p + view_info.plt_count * 4);
   // Write the section header.
   Swap32::writeval(pov, view_info.got_count);
   Swap32::writeval(pov + 4, view_info.plt_count);
Index: gold/layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.249
diff -u -r1.249 layout.cc
--- gold/layout.cc	15 Apr 2013 16:40:59 -0000	1.249
+++ gold/layout.cc	12 May 2013 11:57:02 -0000
@@ -2122,6 +2122,40 @@
 					0, // nonvis
 					true, // offset_is_from_end
 					true); // only_if_ref
+	} if (matches_predefined_sectionname_scheme(name)) {
+		  std::string name_string(name + 1);
+		  std::transform(name_string.begin(), name_string.end(),name_string.begin(), ::toupper);
+		  const std::string start_name("__"
+					       + name_string + "_START");
+		  const std::string stop_name("__"
+					      + name_string + "_END");
+
+                  fprintf(stderr, "Geil2: '%s', '%s'\n", start_name.c_str(), stop_name.c_str());
+		  symtab->define_in_output_data(start_name.c_str(),
+						NULL, // version
+						Symbol_table::PREDEFINED,
+						*p,
+						0, // value
+						0, // symsize
+						elfcpp::STT_NOTYPE,
+						elfcpp::STB_GLOBAL,
+						elfcpp::STV_DEFAULT,
+						0, // nonvis
+						false, // offset_is_from_end
+						true); // only_if_ref
+
+		  symtab->define_in_output_data(stop_name.c_str(),
+						NULL, // version
+						Symbol_table::PREDEFINED,
+						*p,
+						0, // value
+						0, // symsize
+						elfcpp::STT_NOTYPE,
+						elfcpp::STB_GLOBAL,
+						elfcpp::STV_DEFAULT,
+						0, // nonvis
+						true, // offset_is_from_end
+						true); // only_if_ref
 	}
     }
 }

 
On Apr 22, 2013, at 7:51 PM, Ian Lance Taylor <iant@google.com> wrote:

> On Mon, Apr 22, 2013 at 4:39 AM, Raphael Zulliger <zulli73@gmail.com> wrote:
>> 
>> Is there a chance to enhance gold to better support such use cases? Or is that out-of focus for gold? I'm not familiar with linking internals, but I think that providing additional start/end address symbols for section names starting with a '.' wouldn't be that tricky to be added, right?
> 
> I'm fine with it.  Look for uses of is_cident in the gold source code.
> 
> Ian


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