public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [gold patch] Allow an ET_EXEC file with the --just-symbols/-R option
@ 2011-07-30  5:49 Cary Coutant
  2011-07-30  6:20 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Cary Coutant @ 2011-07-30  5:49 UTC (permalink / raw)
  To: Ian Lance Taylor, Binutils

[-- Attachment #1: Type: text/plain, Size: 738 bytes --]

Gold currently does not allow the --just-symbols (alias -R) option
with an ET_EXEC file. This patch adds that support, and also prevents
the text segment address from being bumped up by a page when -Ttext is
used.

(A test case is in the works.)

-cary


	* layout.cc (Layout::set_segment_offsets): Don't realign text
	segment if -Ttext was specified.
	* object.cc (Sized_relobj_file::Sized_relobj_file): Store the ELF
	file type.
	* object.h (Sized_relobj_file::e_type): New function.
	(Sized_relobj_file::e_type_): New data member.
	* symtab.cc (Symbol_table::add_from_relobj): Don't add section
	base address for ET_EXEC files.
	* target.cc (Target::do_make_elf_object_implementation): Allow
	ET_EXEC files with --just-symbols option.

[-- Attachment #2: gold-dashr-exec-patch.txt --]
[-- Type: text/plain, Size: 4230 bytes --]

2011-07-29  Cary Coutant  <ccoutant@google.com>

	* layout.cc (Layout::set_segment_offsets): Don't realign text
	segment if -Ttext was specified.
	* object.cc (Sized_relobj_file::Sized_relobj_file): Store the ELF
	file type.
	* object.h (Sized_relobj_file::e_type): New function.
	(Sized_relobj_file::e_type_): New data member.
	* symtab.cc (Symbol_table::add_from_relobj): Don't add section
	base address for ET_EXEC files.
	* target.cc (Target::do_make_elf_object_implementation): Allow
	ET_EXEC files with --just-symbols option.


commit 67a9ad5234d1e87160ae9d7601feffdec8556ed7
Author: Cary Coutant <ccoutant@google.com>
Date:   Fri Jul 29 18:01:35 2011 -0700

    Add support for -R option with an ET_EXEC file.

diff --git a/gold/layout.cc b/gold/layout.cc
index 2a8d3b4..44c2e18 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -3039,6 +3039,11 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
 	      // the physical address.
 	      addr = (*p)->paddr();
 	    }
+	  else if (parameters->options().user_set_Ttext()
+		   && ((*p)->flags() & elfcpp::PF_W) == 0)
+	    {
+	      are_addresses_set = true;
+	    }
 	  else if (parameters->options().user_set_Tdata()
 		   && ((*p)->flags() & elfcpp::PF_W) != 0
 		   && (!parameters->options().user_set_Tbss()
diff --git a/gold/object.cc b/gold/object.cc
index 6f68ed3..4b69696 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -421,6 +421,7 @@ Sized_relobj_file<size, big_endian>::Sized_relobj_file(
     deferred_layout_relocs_(),
     compressed_sections_()
 {
+  this->e_type_ = ehdr.get_e_type();
 }
 
 template<int size, bool big_endian>
diff --git a/gold/object.h b/gold/object.h
index 9c363cd..a389c54 100644
--- a/gold/object.h
+++ b/gold/object.h
@@ -1912,6 +1912,11 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
   sized_relobj() const
   { return this; }
 
+  // Return the ELF file type.
+  int
+  e_type() const
+  { return this->e_type_; }
+
   // Return the number of symbols.  This is only valid after
   // Object::add_symbols has been called.
   unsigned int
@@ -2504,6 +2509,9 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
 
   // General access to the ELF file.
   elfcpp::Elf_file<size, big_endian, Object> elf_file_;
+  // Type of ELF file (ET_REL or ET_EXEC).  ET_EXEC files are allowed
+  // as input files only for the --just-symbols option.
+  int e_type_;
   // Index of SHT_SYMTAB section.
   unsigned int symtab_shndx_;
   // The number of local symbols.
diff --git a/gold/symtab.cc b/gold/symtab.cc
index e289f79..31b5e57 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -1192,12 +1192,13 @@ Symbol_table::add_from_relobj(
 	{
 	  memcpy(symbuf, p, sym_size);
 	  elfcpp::Sym_write<size, big_endian> sw(symbuf);
-	  if (orig_st_shndx != elfcpp::SHN_UNDEF && is_ordinary)
+	  if (orig_st_shndx != elfcpp::SHN_UNDEF && is_ordinary
+	      && relobj->e_type() == elfcpp::ET_REL)
 	    {
-	      // Symbol values in object files are section relative.
-	      // This is normally what we want, but since here we are
-	      // converting the symbol to absolute we need to add the
-	      // section address.  The section address in an object
+	      // Symbol values in relocatable object files are section
+	      // relative.  This is normally what we want, but since here
+	      // we are converting the symbol to absolute we need to add
+	      // the section address.  The section address in an object
 	      // file is normally zero, but people can use a linker
 	      // script to change it.
 	      sw.put_st_value(sym.get_st_value()
diff --git a/gold/target.cc b/gold/target.cc
index 4a7af83..091f9d3 100644
--- a/gold/target.cc
+++ b/gold/target.cc
@@ -72,7 +72,10 @@ Target::do_make_elf_object_implementation(
     const elfcpp::Ehdr<size, big_endian>& ehdr)
 {
   int et = ehdr.get_e_type();
-  if (et == elfcpp::ET_REL)
+  // ET_EXEC files are valid input for --just-symbols/-R,
+  // and we treat them as relocatable objects.
+  if (et == elfcpp::ET_REL
+      || (et == elfcpp::ET_EXEC && input_file->just_symbols()))
     {
       Sized_relobj_file<size, big_endian>* obj =
 	new Sized_relobj_file<size, big_endian>(name, input_file, offset, ehdr);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [gold patch] Allow an ET_EXEC file with the --just-symbols/-R option
  2011-07-30  5:49 [gold patch] Allow an ET_EXEC file with the --just-symbols/-R option Cary Coutant
@ 2011-07-30  6:20 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2011-07-30  6:20 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Binutils

Cary Coutant <ccoutant@google.com> writes:

> 	* layout.cc (Layout::set_segment_offsets): Don't realign text
> 	segment if -Ttext was specified.
> 	* object.cc (Sized_relobj_file::Sized_relobj_file): Store the ELF
> 	file type.
> 	* object.h (Sized_relobj_file::e_type): New function.
> 	(Sized_relobj_file::e_type_): New data member.
> 	* symtab.cc (Symbol_table::add_from_relobj): Don't add section
> 	base address for ET_EXEC files.
> 	* target.cc (Target::do_make_elf_object_implementation): Allow
> 	ET_EXEC files with --just-symbols option.


> -	  if (orig_st_shndx != elfcpp::SHN_UNDEF && is_ordinary)
> +	  if (orig_st_shndx != elfcpp::SHN_UNDEF && is_ordinary
> +	      && relobj->e_type() == elfcpp::ET_REL)

Move the && from the middle of the line to the start of a new
line--i.e., three lines in the condition, the last two starting with
&&.


This is OK with that change.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-30  1:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-30  5:49 [gold patch] Allow an ET_EXEC file with the --just-symbols/-R option Cary Coutant
2011-07-30  6:20 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).