summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/binutils/binutils/binutils-pr12366.patch
blob: c11a802941fc86539a9a4ae3bafa18a29b079e35 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
This is backport from 2.21 branch

Upstream-Status: Backport

Signed-off-by: Khem Raj <raj.khem@gmail.com>


commit 946593d19f203b02efd45b5102dd2787d9418e24
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed May 25 17:41:32 2011 +0000

    Handle STT_GNU_IFUNC symols when building shared library.
    
    bfd/
    
    2012-05-25  H.J. Lu  <hongjiu.lu@intel.com>
    
    	Backport from mainline
    	2012-01-06  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR ld/12366
    	PR ld/12371
    	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Properly
    	handle symbols marked with regular reference, but not non-GOT
    	reference when building shared library.
    
    	* elf32-i386.c (elf_i386_gc_sweep_hook): Properly handle
    	local and global STT_GNU_IFUNC symols when building shared
    	library.
    	* elf64-x86-64.c (elf_x86_64_gc_sweep_hook): Likewise.
    
    ld/testsuite/
    
    2012-05-25  H.J. Lu  <hongjiu.lu@intel.com>
    
    	Backport from mainline
    	2012-01-06  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR ld/12366
    	PR ld/12371
    	* ld-ifunc/ifunc-10-i386.s: Add more tests.
    	* ld-ifunc/ifunc-10-x86-64.s: Likewise.
    	* ld-ifunc/ifunc-11-i386.s: Likewise.
    	* ld-ifunc/ifunc-11-x86-64.s: Likewise.
    
    	* ld-ifunc/ifunc-12-i386.d: New.
    	* ld-ifunc/ifunc-12-i386.s: Likewise.
    	* ld-ifunc/ifunc-12-x86-64.d: Likewise.
    	* ld-ifunc/ifunc-12-x86-64.s: Likewise.
    	* ld-ifunc/ifunc-13-i386.d: Likewise.
    	* ld-ifunc/ifunc-13-x86-64.d: Likewise.
    	* ld-ifunc/ifunc-13a-i386.s: Likewise.
    	* ld-ifunc/ifunc-13a-x86-64.s: Likewise.
    	* ld-ifunc/ifunc-13b-i386.s: Likewise.
    	* ld-ifunc/ifunc-13b-x86-64.s: Likewise.

Index: binutils-2.21/bfd/elf-ifunc.c
===================================================================
--- binutils-2.21.orig/bfd/elf-ifunc.c	2010-07-13 09:59:10.000000000 -0700
+++ binutils-2.21/bfd/elf-ifunc.c	2011-06-21 16:33:40.751884107 -0700
@@ -190,10 +190,29 @@
   /* Support garbage collection against STT_GNU_IFUNC symbols.  */
   if (h->plt.refcount <= 0 && h->got.refcount <= 0)
     {
-      h->got = htab->init_got_offset;
-      h->plt = htab->init_plt_offset;
-      *head = NULL;
-      return TRUE;
+      /* When building shared library, we need to handle the case
+         where it is marked with regular reference, but not non-GOT
+	 reference.  It may happen if we didn't see STT_GNU_IFUNC
+	 symbol at the time when checking relocations.  */
+      bfd_size_type count = 0;
+
+      if (info->shared
+	  && !h->non_got_ref
+	  && h->ref_regular)
+	{
+	  for (p = *head; p != NULL; p = p->next)
+	    count += p->count;
+	  if (count != 0)
+	    h->non_got_ref = 1;
+	}
+
+      if (count == 0)
+	{
+	  h->got = htab->init_got_offset;
+	  h->plt = htab->init_plt_offset;
+	  *head = NULL;
+	  return TRUE;
+	}
     }
 
   /* Return and discard space for dynamic relocations against it if
Index: binutils-2.21/bfd/elf32-i386.c
===================================================================
--- binutils-2.21.orig/bfd/elf32-i386.c	2010-10-21 05:29:02.000000000 -0700
+++ binutils-2.21/bfd/elf32-i386.c	2011-06-21 16:33:40.761884138 -0700
@@ -1807,23 +1807,10 @@
       r_symndx = ELF32_R_SYM (rel->r_info);
       if (r_symndx >= symtab_hdr->sh_info)
 	{
-	  struct elf_i386_link_hash_entry *eh;
-	  struct elf_dyn_relocs **pp;
-	  struct elf_dyn_relocs *p;
-
 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
 	  while (h->root.type == bfd_link_hash_indirect
 		 || h->root.type == bfd_link_hash_warning)
 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
-	  eh = (struct elf_i386_link_hash_entry *) h;
-
-	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
-	    if (p->sec == sec)
-	      {
-		/* Everything must go for SEC.  */
-		*pp = p->next;
-		break;
-	      }
 	}
       else
 	{
@@ -1843,6 +1830,22 @@
 	    }
 	}
 
+      if (h)
+	{
+	  struct elf_i386_link_hash_entry *eh;
+	  struct elf_dyn_relocs **pp;
+	  struct elf_dyn_relocs *p;
+
+	  eh = (struct elf_i386_link_hash_entry *) h;
+	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
+	    if (p->sec == sec)
+	      {
+		/* Everything must go for SEC.  */
+		*pp = p->next;
+		break;
+	      }
+	}
+
       r_type = ELF32_R_TYPE (rel->r_info);
       if (! elf_i386_tls_transition (info, abfd, sec, NULL,
 				     symtab_hdr, sym_hashes,
@@ -1883,7 +1886,8 @@
 
 	case R_386_32:
 	case R_386_PC32:
-	  if (info->shared)
+	  if (info->shared
+	      && (h == NULL || h->type != STT_GNU_IFUNC))
 	    break;
 	  /* Fall through */
 
Index: binutils-2.21/bfd/elf64-x86-64.c
===================================================================
--- binutils-2.21.orig/bfd/elf64-x86-64.c	2010-10-21 05:29:02.000000000 -0700
+++ binutils-2.21/bfd/elf64-x86-64.c	2011-06-21 16:33:40.761884138 -0700
@@ -1645,23 +1645,10 @@
       r_symndx = ELF64_R_SYM (rel->r_info);
       if (r_symndx >= symtab_hdr->sh_info)
 	{
-	  struct elf64_x86_64_link_hash_entry *eh;
-	  struct elf_dyn_relocs **pp;
-	  struct elf_dyn_relocs *p;
-
 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
 	  while (h->root.type == bfd_link_hash_indirect
 		 || h->root.type == bfd_link_hash_warning)
 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
-	  eh = (struct elf64_x86_64_link_hash_entry *) h;
-
-	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
-	    if (p->sec == sec)
-	      {
-		/* Everything must go for SEC.  */
-		*pp = p->next;
-		break;
-	      }
 	}
       else
 	{
@@ -1682,7 +1669,24 @@
 	    }
 	}
 
-      r_type = ELF64_R_TYPE (rel->r_info);
+      if (h)
+	{
+	  struct elf64_x86_64_link_hash_entry *eh;
+	  struct elf_dyn_relocs **pp;
+	  struct elf_dyn_relocs *p;
+
+	  eh = (struct elf64_x86_64_link_hash_entry *) h;
+
+	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
+	    if (p->sec == sec)
+	      {
+		/* Everything must go for SEC.  */
+		*pp = p->next;
+		break;
+	      }
+	}
+
+      r_type = ELF32_R_TYPE (rel->r_info);
       if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
 					 symtab_hdr, sym_hashes,
 					 &r_type, GOT_UNKNOWN,
@@ -1733,7 +1737,8 @@
 	case R_X86_64_PC16:
 	case R_X86_64_PC32:
 	case R_X86_64_PC64:
-	  if (info->shared)
+	  if (info->shared
+	      && (h == NULL || h->type != STT_GNU_IFUNC))
 	    break;
 	  /* Fall thru */
 
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-10-i386.s
===================================================================
--- binutils-2.21.orig/ld/testsuite/ld-ifunc/ifunc-10-i386.s	2010-07-13 09:59:14.000000000 -0700
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-10-i386.s	2011-06-21 16:36:36.832142380 -0700
@@ -6,6 +6,8 @@
         movl ifunc@GOTOFF(%ecx), %eax
 	call ifunc@PLT
 	call ifunc
+        movl xxx@GOT(%ecx), %eax
+        movl xxx, %eax
         ret
 
         .section .text.bar,"ax",@progbits
@@ -18,3 +20,7 @@
         .type ifunc, @gnu_indirect_function
 ifunc:
         ret
+
+        .section .data.foo,"aw",@progbits
+xxx:
+	.long ifunc
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-10-x86-64.s
===================================================================
--- binutils-2.21.orig/ld/testsuite/ld-ifunc/ifunc-10-x86-64.s	2010-07-13 09:59:14.000000000 -0700
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-10-x86-64.s	2011-06-21 16:36:36.822142371 -0700
@@ -6,6 +6,7 @@
         movl ifunc(%rip), %eax
 	call ifunc@PLT
 	call ifunc
+        movl xxx(%rip), %eax
         ret
 
         .section .text.bar,"ax",@progbits
@@ -18,3 +19,7 @@
         .type ifunc, @gnu_indirect_function
 ifunc:
         ret
+
+        .section .data.foo,"aw",@progbits
+xxx:
+	.quad ifunc
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-11-i386.s
===================================================================
--- binutils-2.21.orig/ld/testsuite/ld-ifunc/ifunc-11-i386.s	2010-07-13 09:59:14.000000000 -0700
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-11-i386.s	2011-06-21 16:36:36.832142380 -0700
@@ -3,9 +3,11 @@
 foo:
         .global foo
         movl ifunc@GOT(%ecx), %eax
-	movl ifunc@GOTOFF(%ecx), %eax
+        movl ifunc@GOTOFF(%ecx), %eax
 	call ifunc@PLT
 	call ifunc
+        movl xxx@GOT(%ecx), %eax
+        movl xxx, %eax
         ret
 
         .section .text.bar,"ax",@progbits
@@ -16,6 +18,10 @@
 
         .section .text.ifunc,"ax",@progbits
         .type ifunc, @gnu_indirect_function
-        .global ifunc
+	.global ifunc
 ifunc:
         ret
+
+        .section .data.foo,"aw",@progbits
+xxx:
+	.long ifunc
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-11-x86-64.s
===================================================================
--- binutils-2.21.orig/ld/testsuite/ld-ifunc/ifunc-11-x86-64.s	2010-07-13 09:59:14.000000000 -0700
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-11-x86-64.s	2011-06-21 16:36:36.822142371 -0700
@@ -6,6 +6,7 @@
         movl ifunc(%rip), %eax
 	call ifunc@PLT
 	call ifunc
+        movl xxx(%rip), %eax
         ret
 
         .section .text.bar,"ax",@progbits
@@ -19,3 +20,7 @@
         .global ifunc
 ifunc:
         ret
+
+        .section .data.foo,"aw",@progbits
+xxx:
+	.quad ifunc
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-12-i386.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-12-i386.d	2011-06-21 16:33:40.761884138 -0700
@@ -0,0 +1,6 @@
+#ld: -shared -m elf_i386 -e bar --gc-sections
+#as: --32
+#readelf: -r --wide
+#target: x86_64-*-* i?86-*-*
+
+There are no relocations in this file.
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-12-x86-64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-12-x86-64.d	2011-06-21 16:33:40.761884138 -0700
@@ -0,0 +1,6 @@
+#ld: -shared -m elf_x86_64 -e bar --gc-sections
+#as: --64
+#readelf: -r --wide
+#target: x86_64-*-*
+
+There are no relocations in this file.
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13-i386.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13-i386.d	2011-06-21 16:33:40.761884138 -0700
@@ -0,0 +1,19 @@
+#source: ifunc-13a-i386.s
+#source: ifunc-13b-i386.s
+#ld: -shared -m elf_i386 -z nocombreloc
+#as: --32
+#readelf: -r --wide
+#target: x86_64-*-* i?86-*-*
+
+Relocation section '.rel.got' at .*
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+#...
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_GLOB_DAT[ ]+ifunc\(\)[ ]+ifunc
+#...
+Relocation section '.rel.ifunc' at .*
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_32[ ]+ifunc\(\)[ ]+ifunc
+#...
+Relocation section '.rel.plt' at .*
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_JUMP_SLOT[ ]+ifunc\(\)[ ]+ifunc
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13-x86-64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13-x86-64.d	2011-06-21 16:33:40.761884138 -0700
@@ -0,0 +1,18 @@
+#source: ifunc-13a-x86-64.s
+#source: ifunc-13b-x86-64.s
+#ld: -shared -m elf_x86_64 -z nocombreloc
+#as: --64
+#readelf: -r --wide
+#target: x86_64-*-*
+
+Relocation section '.rela.got' at .*
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_GLOB_DAT[ ]+ifunc\(\)[ ]+ifunc \+ 0
+#...
+Relocation section '.rela.ifunc' at .*
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_64[ ]+ifunc\(\)[ ]+ifunc \+ 0
+#...
+Relocation section '.rela.plt' at .*
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_JUMP_SLOT[ ]+ifunc\(\)[ ]+ifunc \+ 0
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13a-i386.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13a-i386.s	2011-06-21 16:36:36.822142371 -0700
@@ -0,0 +1,10 @@
+	.text
+        .type foo, @function
+	.global
+foo:
+	movl xxx@GOT(%ebx), %eax
+        ret
+
+	.data
+xxx:
+	.long ifunc
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13a-x86-64.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13a-x86-64.s	2011-06-21 16:36:36.822142371 -0700
@@ -0,0 +1,10 @@
+	.text
+        .type foo, @function
+	.global
+foo:
+        movl xxx(%rip), %eax
+        ret
+
+	.data
+xxx:
+	.quad ifunc
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13b-i386.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13b-i386.s	2011-06-21 16:33:40.761884138 -0700
@@ -0,0 +1,5 @@
+	.text
+        .type ifunc, @gnu_indirect_function
+	.globl ifunc
+ifunc:
+        ret
Index: binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13b-x86-64.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.21/ld/testsuite/ld-ifunc/ifunc-13b-x86-64.s	2011-06-21 16:33:40.761884138 -0700
@@ -0,0 +1,5 @@
+	.text
+        .type ifunc, @gnu_indirect_function
+	.globl ifunc
+ifunc:
+        ret
OpenPOWER on IntegriCloud