summaryrefslogtreecommitdiff
path: root/patches/glibc/2.15/990-try-link-static.patch
blob: a0ffadd37df7ba34fb3cdbe1e7d089c6e15be789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
[Patch modified to apply to 2.15]

commit 07037eeb43ca1e0ac2802e3a1492cecf869c63c6
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Thu Mar 8 00:17:27 2012 +0000

    Fix .ctors/.dtors header configure test for bootstrapping.

diff -urpN glibc-2.15.orig/aclocal.m4 glibc-2.15/aclocal.m4
--- glibc-2.15.orig/aclocal.m4	2017-02-08 11:27:28.445657746 -0800
+++ glibc-2.15/aclocal.m4	2017-02-08 11:37:25.818463475 -0800
@@ -114,3 +114,17 @@ AC_CACHE_CHECK(whether $LD is GNU ld, li
 [LIBC_PROG_FOO_GNU($LD, libc_cv_prog_ld_gnu=yes, libc_cv_prog_ld_gnu=no)])
 gnu_ld=$libc_cv_prog_ld_gnu
 ])
+
+dnl Run a static link test with -nostdlib -nostartfiles.
+dnl LIBC_TRY_LINK_STATIC([code], [action-if-true], [action-if-false])
+AC_DEFUN([LIBC_TRY_LINK_STATIC],
+[cat > conftest.c <<EOF
+int _start (void) { return 0; }
+int __start (void) { return 0; }
+$1
+EOF
+AS_IF([AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -o conftest
+		       conftest.c -static -nostartfiles -nostdlib
+		       1>&AS_MESSAGE_LOG_FD])],
+      [$2], [$3])
+rm -f conftest*])
diff -urpN glibc-2.15.orig/configure glibc-2.15/configure
--- glibc-2.15.orig/configure	2017-02-08 11:27:28.453657802 -0800
+++ glibc-2.15/configure	2017-02-08 11:47:36.184360147 -0800
@@ -6147,29 +6147,32 @@ $as_echo_n "checking for .preinit_array/
 if ${libc_cv_initfini_array+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-    cat > conftest.c <<EOF
+  cat > conftest.c <<EOF
 int _start (void) { return 0; }
 int __start (void) { return 0; }
+
 int foo (void) { return 1; }
 int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
+
 EOF
-  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -o conftest conftest.c
-		     -static -nostartfiles -nostdlib 1>&5'
+if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -o conftest
+		       conftest.c -static -nostartfiles -nostdlib
+		       1>&5'
   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
   (eval $ac_try) 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }
-  then
-    if $READELF -S conftest | fgrep INIT_ARRAY > /dev/null; then
-      libc_cv_initfini_array=yes
-    else
-      libc_cv_initfini_array=no
-    fi
+  test $ac_status = 0; }; }; then :
+  if $READELF -S conftest | fgrep INIT_ARRAY > /dev/null; then
+    libc_cv_initfini_array=yes
   else
     libc_cv_initfini_array=no
   fi
-  rm -f conftest*
+else
+  libc_cv_initfini_array=no
+fi
+rm -f conftest*
+
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_initfini_array" >&5
 $as_echo "$libc_cv_initfini_array" >&6; }
@@ -6183,21 +6186,22 @@ if ${libc_cv_ctors_header+:} false; then
   $as_echo_n "(cached) " >&6
 else
       libc_cv_ctors_header=yes
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
+    cat > conftest.c <<EOF
+int _start (void) { return 0; }
+int __start (void) { return 0; }
+
+__attribute__ ((constructor)) void ctor (void) { asm (""); }
+__attribute__ ((destructor))  void dtor (void) { asm (""); }
 
-int
-main ()
-{
-
-__attribute__ ((constructor)) void ctor (void) { puts("ctor"); }
-__attribute__ ((destructor))  void dtor (void) { puts("dtor"); }
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
+EOF
+if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -o conftest
+		       conftest.c -static -nostartfiles -nostdlib
+		       1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
         if $READELF -WS conftest$ac_exeext | $AWK '
 	{ gsub(/\[ */, "[") }
 	$2 == ".ctors" || $2 == ".dtors" {
@@ -6219,8 +6223,7 @@ else
         as_fn_error $? "missing __attribute__ ((constructor)) support??" "$LINENO" 5
 
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+rm -f conftest*
 
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ctors_header" >&5
diff -urpN glibc-2.15.orig/configure.in glibc-2.15/configure.in
--- glibc-2.15.orig/configure.in	2017-02-08 11:27:28.433657663 -0800
+++ glibc-2.15/configure.in	2017-02-08 11:46:58.994915812 -0800
@@ -1439,24 +1439,17 @@ EOF
 
   AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
 		 libc_cv_initfini_array, [dnl
-  cat > conftest.c <<EOF
-int _start (void) { return 0; }
-int __start (void) { return 0; }
+LIBC_TRY_LINK_STATIC([
 int foo (void) { return 1; }
 int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
-EOF
-  if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -o conftest conftest.c
-		     -static -nostartfiles -nostdlib 1>&AS_MESSAGE_LOG_FD])
-  then
-    if $READELF -S conftest | fgrep INIT_ARRAY > /dev/null; then
-      libc_cv_initfini_array=yes
-    else
-      libc_cv_initfini_array=no
-    fi
+],
+  [if $READELF -S conftest | fgrep INIT_ARRAY > /dev/null; then
+    libc_cv_initfini_array=yes
   else
     libc_cv_initfini_array=no
-  fi
-  rm -f conftest*])
+  fi],
+  [libc_cv_initfini_array=no])
+])
   if test $libc_cv_initfini_array != yes; then
     AC_MSG_ERROR([Need linker with .init_array/.fini_array support.])
   fi
@@ -1464,9 +1457,9 @@ EOF
   AC_CACHE_CHECK(whether to use .ctors/.dtors header and trailer,
 		 libc_cv_ctors_header, [dnl
     libc_cv_ctors_header=yes
-    AC_TRY_LINK([], [
-__attribute__ ((constructor)) void ctor (void) { puts("ctor"); }
-__attribute__ ((destructor))  void dtor (void) { puts("dtor"); }
+    LIBC_TRY_LINK_STATIC([
+__attribute__ ((constructor)) void ctor (void) { asm (""); }
+__attribute__ ((destructor))  void dtor (void) { asm (""); }
 ],
 		[dnl
       AS_IF([$READELF -WS conftest$ac_exeext | $AWK '