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][patch] Add option to strip LTO sections from output


>> This patch adds a --strip-lto-sections option to gold, which tells it
>> to ignore any PROGBITS section where SHF_ALLOC is not set and whose
>> name begins with ".gnu.lto_".
>>
>> It may be worth making this the default behavior.
>
> I agree that it seems simpler to make this the default behaviour.
> Does anybody see a problem with that?

I've made it the default, but added a condition to not strip during a -r link.

> Really we should modify gas to always recognize 'e' as a section flag
> setting SHF_EXCLUDE, and modify ld and gold to always recognize
> SHF_EXCLUDE.  That flag seems generically useful, and given its use by
> several targets it seems quite unlikely that it will ever get another
> meaning for generic ELF.

I've added a check for SHF_EXCLUDE.

>> +      // Ignore LTO sections containing intermediate code if requested.
>> +      if (parameters->options().strip_lto_sections()
>> +          && shdr.get_sh_type() == elfcpp::SHT_PROGBITS
>> +          && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0)
>> +        {
>> +          const char* const lto_prefix = ".gnu.lto_";
>> +          if (strncmp(name, lto_prefix, strlen(lto_prefix)) == 0)
>> +            omit[i] = true;
>> +        }
>
> Please do this in Layout::include_section instead, like
> --strip-debug-gdb, etc.

Done. (Embarrassed that I didn't put it there in the first place.)

-cary


	* layout.cc (Layout::include_section): Check for SHF_EXCLUDE.
	Handle --strip-lto-sections option.
	* options.h (strip_lto_sections): New option.


Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.113
diff -u -p -r1.113 layout.cc
--- layout.cc	12 Sep 2008 05:42:27 -0000	1.113
+++ layout.cc	5 Dec 2008 19:52:13 -0000
@@ -206,6 +206,9 @@ bool
 Layout::include_section(Sized_relobj<size, big_endian>*, const char* name,
 			const elfcpp::Shdr<size, big_endian>& shdr)
 {
+  if (shdr.get_sh_flags() & elfcpp::SHF_EXCLUDE)
+    return false;
+
   switch (shdr.get_sh_type())
     {
     case elfcpp::SHT_NULL:
@@ -256,6 +259,14 @@ Layout::include_section(Sized_relobj<siz
               && !is_gdb_debug_section(name))
 	    return false;
 	}
+      if (parameters->options().strip_lto_sections()
+          && !parameters->options().relocatable()
+          && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0)
+        {
+          // Ignore LTO sections containing intermediate code.
+          if (is_prefix_of(".gnu.lto_", name))
+            return false;
+        }
       return true;

     default:
Index: options.h
===================================================================
RCS file: /cvs/src/src/gold/options.h,v
retrieving revision 1.88
diff -u -p -r1.88 options.h
--- options.h	6 Nov 2008 07:23:31 -0000	1.88
+++ options.h	5 Dec 2008 19:52:13 -0000
@@ -748,6 +748,8 @@ class General_options
   DEFINE_bool(strip_debug_gdb, options::TWO_DASHES, '\0', false,
               N_("Strip debug symbols that are unused by gdb "
                  "(at least versions <= 6.7)"), NULL);
+  DEFINE_bool(strip_lto_sections, options::TWO_DASHES, '\0', true,
+              N_("Strip LTO intermediate code sections"), NULL);

   DEFINE_bool(shared, options::ONE_DASH, '\0', false,
               N_("Generate shared library"), NULL);


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