diff mbox

[gomp4] Add tables generation

Message ID 87wq9jfq3z.fsf@schwinge.name
State New
Headers show

Commit Message

Thomas Schwinge Sept. 4, 2014, 1:54 p.m. UTC
Hi!

On Thu, 04 Sep 2014 15:08:06 +0200, I wrote:
> On Tue, 2 Sep 2014 21:49:46 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > This patch allows to compile binaries with offloading without passing -flto option, and
> > w/o performing link-time optimizations of the host code.
> 
> Thanks for working on this!
> 
> > How it works:
> > 1.  If there is at least one function or global variable to offload, gcc sets flag_generate_lto.
> > This enables writing the bytecode produced by ipa_write_summaries into
> > .gnu.target_lto_* sections (.gnu.lto_* sections are not created).
> > Also this flag emits LTO marker (__gnu_lto_v1).
> > 2.  This step is not changed: collect2 scans object files for the LTO marker and fills the list
> > of LTO objects.  If the list is not empty, it runs lto-wrapper to perform link-time recompilation.
> > 3.  lto-wrapper compiles images for targets.  And if -flto option is absent
> > (lto_mode == LTO_MODE_NONE), then it just returns the list of input objects without recompilation.
> 
> That seems sane to me.  (But you guys have looked into this design/code
> in much more detail than I have.)
> 
> I'm facing one problem; I guess the crucial detail is that in my scenario
> I'm using the linker plugin.  The lto-wrapper is not being executed (and
> thus no mkoffload being run), because »num_claimed_files == 0«.  In
> lto-plugin/lto-plugin.c:process_symtab, only LTO_SECTION_PREFIX
> (".gnu.lto_.symtab") is considered, which (correctly so) is not generated
> anymore by GCC in the new scenario, but ".gnu.target_lto_" is not
> considered there.  (Should this maybe look only for the LTO marker
> "__gnu_lto_v1", or am I misunderstanding what this is doing?)  If I make
> that also accept the offloading section, the compilation process proceeds
> further, but still fails, because no resolution file is available:
> »[...]/ld: cannot find -fresolution=/tmp/cc7xeiW0.res: No such file or
> directory«.  Is this enough information for someone who is more familiar
> with the design/code to already see what needs to be done?

Aha, it's gcc/gcc.c:LINK_PLUGIN_SPEC that is unconditionally adding the
-fresolution option.  Here is a hack that seems to make it work, but that
most certainly should be done differently:

commit 9de71e209f5a75454ddb6922009425eb1f6bec1c
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Thu Sep 4 15:44:37 2014 +0200

    Hack for offloading without -flto, with linker plugin.



Grüße,
 Thomas
diff mbox

Patch

diff --git gcc/lto-wrapper.c gcc/lto-wrapper.c
index d40f8ae..9556cdc 100644
--- gcc/lto-wrapper.c
+++ gcc/lto-wrapper.c
@@ -910,7 +910,8 @@  run_gcc (unsigned argc, char *argv[])
 	 there is no need to perform a link-time recompilation, i.e. lto-wrapper
 	 is used only for compiling offload images.  */
       for (i = 1; i < argc; ++i)
-	printf ("%s\n", argv[i]);
+	if (strncmp (argv[i], "-fresolution=", sizeof ("-fresolution=") - 1))
+	  printf ("%s\n", argv[i]);
       goto finish;
     }
   else if (lto_mode == LTO_MODE_LTO)
diff --git lto-plugin/lto-plugin.c lto-plugin/lto-plugin.c
index 910e23c..a397276 100644
--- lto-plugin/lto-plugin.c
+++ lto-plugin/lto-plugin.c
@@ -84,8 +84,8 @@  along with this program; see the file COPYING3.  If not see
 
 /* LTO magic section name.  */
 
-#define LTO_SECTION_PREFIX	".gnu.lto_.symtab"
-#define LTO_SECTION_PREFIX_LEN	(sizeof (LTO_SECTION_PREFIX) - 1)
+#define LTO_SECTION_SYMTAB	".gnu.lto_.symtab"
+#define OMP_SECTION_SYMTAB	".gnu.target_lto_.symtab"
 
 /* The part of the symbol table the plugin has to keep track of. Note that we
    must keep SYMS until all_symbols_read is called to give the linker time to
@@ -820,7 +820,8 @@  process_symtab (void *data, const char *name, off_t offset, off_t length)
   char *s;
   char *secdatastart, *secdata;
 
-  if (strncmp (name, LTO_SECTION_PREFIX, LTO_SECTION_PREFIX_LEN) != 0)
+  if (strncmp (name, LTO_SECTION_SYMTAB, strlen (LTO_SECTION_SYMTAB)) != 0
+      && strncmp (name, OMP_SECTION_SYMTAB, strlen (OMP_SECTION_SYMTAB)) != 0)
     return 1;
 
   s = strrchr (name, '.');