This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[lto] Do not emit the LTO marker as an undefined symbol


This patch changes the LTO marker so that it's not an undefined
symbol.  This was tripping up ld in certain scenarios.  From an
internal bug report:

> Consider the example:
> 
> ==> main.c <==
> extern void foo();
> int main() { foo(); }
> 
> ==> foo.c <==
> #include <stdio.h>
> void foo() { printf("bar!  HA HA!\n"); }
> 
> 
> $ gcc -fwhopr -c foo.c
> $ ar crv foo.a foo.o
> $ gcc -fwhopr -o foo.so -shared -Wl,--whole-archive foo.a -Wl,--no-whole-archive
> $ gcc -fwhopr -c main.c
> $ gcc -fwhopr -o main main.o foo.so
> 
> This results in:
> 
> ld: foo.so: undefined reference to 'gnu_lto_v1'
> collect2: ld returned 1 exit status
> 
> When the linker actually uses the plugin and searches .a files,
> this particular example won't work.  When that's the case, the
> following example will still work:
> 
> $ gcc -fwhopr -c foo.c
> $ ar crv foo.a foo.o
> $ gcc -o foo.so -shared -Wl,--whole-archive foo.a -Wl,--no-whole-archive
> $ gcc -fwhopr -c main.c
> $ gcc -fwhopr -o main main.o foo.so
> 
> That's still a little bit pathological, but may be more frequent.
> Direct use of 'ld' would lose similarly.  (In general, anything
> that takes LTO .o files and turns them into a shlib without
> invoking LTO is going to lose AFAICT.)

Fixed by putting the LTO marker in .comm storage.  Creating a
test case for this looks difficult as it involves creating an
archive and I don't know enough dejagnu to do it quickly.  I've
added a comment to the marker that explains why this is needed.

At some point Cary had mentioned that we should be able to detect
LTO files without this marker.  Cary?

Tested on x86_64.


Diego.



	* toplev.c (compile_file): Emit gnu_lto_v1 in .comm.

Index: toplev.c
===================================================================
--- toplev.c	(revision 142823)
+++ toplev.c	(working copy)
@@ -1031,9 +1031,13 @@ compile_file (void)
   /* Flush any pending external directives.  */
   process_pending_assemble_externals ();
 
-  /* Emit LTO marker if LTO info has been previously emitted.  */
+  /* Emit LTO marker if LTO info has been previously emitted.  This is
+     used by collect2 to determine whether an object file contains IL.
+     We used to emit an undefined reference here, but this produces
+     link errors if an object file with IL is stored into a shared
+     library without invoking lto1.  */
   if (flag_generate_lto)
-    fprintf (asm_out_file,".globl\tgnu_lto_v1\n");
+    fprintf (asm_out_file,"\t.comm\tgnu_lto_v1,1,1\n");
 
   /* Attach a special .ident directive to the end of the file to identify
      the version of GCC which compiled this code.  The format of the .ident


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