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


When linking objects that contain both normal code and IR, gold
currently copies the IR into the output file. Normally, the linker
will only see such files when not using the LTO linker plugin, which
can happen either when not doing an LTO link or when using the
collect2 LTO path with IR files buried inside archive libraries (which
collect2 does not scan for IR). In both cases, the IR is useless and
ought to be thrown away. Typically, it's many times larger than the
actual code, so it's a tremendous waste.

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.

-cary


	* object.cc (Sized_relobj::do_layout): Ignore LTO sections
	when --strip-lto-sections option is given.
	* options.h (strip_lto_sections): New option.


Index: object.cc
===================================================================
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.78
diff -u -p -r1.78 object.cc
--- object.cc	29 Sep 2008 21:10:26 -0000	1.78
+++ object.cc	4 Dec 2008 21:44:26 -0000
@@ -894,6 +894,16 @@ Sized_relobj<size, big_endian>::do_layou
 	    omit[i] = true;
 	}

+      // 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;
+        }
+
       // The .note.GNU-stack section is special.  It gives the
       // protection flags that this object file requires for the stack
       // in memory.
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	4 Dec 2008 21:44:26 -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', false,
+              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]