Patchwork gcc/go/gospec.c: fix static linking of Go programs (issue 7130047)

login
register
mail settings
Submitter minux.ma@gmail.com
Date Jan. 16, 2013, 3:57 p.m.
Message ID <089e013a2a6a2c555004d369efff@google.com>
Download mbox | patch
Permalink /patch/212583/
State New
Headers show

Comments

minux.ma@gmail.com - Jan. 16, 2013, 3:57 p.m.
Reviewers: iant,

Message:
please take another look.

Description:
2013-01-16  Shenghou Ma  <minux.ma@gmail.com>

      * gospec.c: pass -u pthread_create to linker when static linking.



Please review this at https://codereview.appspot.com/7130047/

Affected files:
   M     gcc/go/gospec.c

Patch

Index: gcc/go/gospec.c
===================================================================
--- gcc/go/gospec.c	(revision 195240)
+++ gcc/go/gospec.c	(working copy)
@@ -227,7 +227,7 @@ 
  #endif

    /* Make sure to have room for the trailing NULL argument.  */
-  num_args = argc + need_math + shared_libgcc + (library > 0) * 5 + 5;
+  num_args = argc + need_math + shared_libgcc + (library > 0) * 5 + 10;
    new_decoded_options = XNEWVEC (struct cl_decoded_option, num_args);

    i = 0;
@@ -381,6 +381,20 @@ 
      generate_option (OPT_shared_libgcc, NULL, 1, CL_DRIVER,
  		     &new_decoded_options[j++]);

+#ifdef TARGET_CAN_SPLIT_STACK
+  /* libgcc wraps pthread_create to support split stack, however, due to
+     relative ordering of -lpthread and -lgcc, we can't just mark
+     __real_pthread_create in libgcc as non-weak.  But we need to link in
+     pthread_create from pthread if we are statically linking, so we work-
+     around by passing -u pthread_create to to the linker. */
+  if (static_link)
+    {
+      generate_option (OPT_Wl_, "-u,pthread_create", 1, CL_DRIVER,
+		       &new_decoded_options[j]);
+      j++;
+    }
+#endif
+
    *in_decoded_options_count = j;
    *in_decoded_options = new_decoded_options;
    *in_added_libraries = added_libraries;