]> git.pld-linux.org Git - packages/cross-binutils.git/blame - binutils-2.25-kernel-ld-r.patch
fix symlinked packages files (ppc64)
[packages/cross-binutils.git] / binutils-2.25-kernel-ld-r.patch
CommitLineData
59e455fe
ER
1diff -rup binutils-2.25.orig/bfd/bfd.c binutils-2.25/bfd/bfd.c
2--- binutils-2.25.orig/bfd/bfd.c 2014-12-24 10:46:27.893435026 +0000
3+++ binutils-2.25/bfd/bfd.c 2014-12-24 10:48:25.666096395 +0000
4@@ -44,6 +44,14 @@ CODE_FRAGMENT
5 . both_direction = 3
6 . };
7 .
8+.enum bfd_lto_object_type
9+. {
10+. lto_non_object,
11+. lto_non_ir_object,
12+. lto_ir_object,
13+. lto_mixed_object
14+. };
15+.
16 .struct bfd
17 .{
18 . {* The filename the application opened the BFD with. *}
19@@ -221,6 +229,9 @@ CODE_FRAGMENT
20 . {* The last section on the section list. *}
21 . struct bfd_section *section_last;
22 .
23+. {* The object-only section on the section list. *}
24+. struct bfd_section *object_only_section;
25+.
26 . {* The number of sections. *}
27 . unsigned int section_count;
28 .
29@@ -310,6 +321,9 @@ CODE_FRAGMENT
30 . struct objalloc *, but we use void * to avoid requiring the inclusion
31 . of objalloc.h. *}
32 . void *memory;
33+.
34+. {* LTO object type. *}
35+. unsigned int lto_type : 2;
36 .};
37 .
38 .{* See note beside bfd_set_section_userdata. *}
39@@ -1923,3 +1937,36 @@ bfd_demangle (bfd *abfd, const char *nam
40
41 return res;
42 }
43+
44+/*
45+FUNCTION
46+ bfd_group_signature
47+
48+SYNOPSIS
49+ asymbol *bfd_group_signature (asection *group, asymbol **isympp);
50+
51+DESCRIPTION
52+ Return a pointer to the symbol used as a signature for GROUP.
53+*/
54+
55+asymbol *
56+bfd_group_signature (asection *group, asymbol **isympp)
57+{
58+ bfd *abfd = group->owner;
59+ Elf_Internal_Shdr *ghdr;
60+
61+ if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
62+ return NULL;
63+
64+ ghdr = &elf_section_data (group)->this_hdr;
65+ if (ghdr->sh_link < elf_numsections (abfd))
66+ {
67+ const struct elf_backend_data *bed = get_elf_backend_data (abfd);
68+ Elf_Internal_Shdr *symhdr = elf_elfsections (abfd) [ghdr->sh_link];
69+
70+ if (symhdr->sh_type == SHT_SYMTAB
71+ && ghdr->sh_info < symhdr->sh_size / bed->s->sizeof_sym)
72+ return isympp[ghdr->sh_info - 1];
73+ }
74+ return NULL;
75+}
76Only in binutils-2.25/bfd: bfd.c.orig
77Only in binutils-2.25/bfd: bfd.c.rej
78diff -rup binutils-2.25.orig/bfd/bfd-in2.h binutils-2.25/bfd/bfd-in2.h
79--- binutils-2.25.orig/bfd/bfd-in2.h 2014-12-24 10:46:27.890435009 +0000
80+++ binutils-2.25/bfd/bfd-in2.h 2014-12-24 10:54:21.498104097 +0000
81@@ -1078,6 +1078,9 @@ struct bfd_section *bfd_create_gnu_debug
82 bfd_boolean bfd_fill_in_gnu_debuglink_section
83 (bfd *abfd, struct bfd_section *sect, const char *filename);
84
85+const char *bfd_extract_object_only_section
86+ (bfd *abfd);
87+
88 /* Extracted from libbfd.c. */
89
90 /* Byte swapping macros for user section data. */
91@@ -1650,6 +1653,9 @@ extern asection _bfd_std_section[4];
92 || ((SEC) == bfd_com_section_ptr) \
93 || ((SEC) == bfd_ind_section_ptr))
94
95+/* GNU object-only section name. */
96+#define GNU_OBJECT_ONLY_SECTION_NAME ".gnu_object_only"
97+
98 /* Macros to handle insertion and deletion of a bfd's sections. These
99 only handle the list pointers, ie. do not adjust section_count,
100 target_index etc. */
101@@ -6269,6 +6275,14 @@ enum bfd_direction
102 both_direction = 3
103 };
104
105+enum bfd_lto_object_type
106+ {
107+ lto_non_object,
108+ lto_non_ir_object,
109+ lto_ir_object,
110+ lto_mixed_object
111+ };
112+
113 struct bfd
114 {
115 /* The filename the application opened the BFD with. */
116@@ -6446,6 +6460,9 @@ struct bfd
117 /* The last section on the section list. */
118 struct bfd_section *section_last;
119
120+ /* The object-only section on the section list. */
121+ struct bfd_section *object_only_section;
122+
123 /* The number of sections. */
124 unsigned int section_count;
125
126@@ -6535,6 +6552,9 @@ struct bfd
127 struct objalloc *, but we use void * to avoid requiring the inclusion
128 of objalloc.h. */
129 void *memory;
130+
131+ /* LTO object type. */
132+ unsigned int lto_type : 2;
133 };
134
135 /* See note beside bfd_set_section_userdata. */
136@@ -6747,6 +6767,8 @@ void bfd_emul_set_commonpagesize (const
137
138 char *bfd_demangle (bfd *, const char *, int);
139
140+asymbol *bfd_group_signature (asection *group, asymbol **isympp);
141+
142 /* Extracted from archive.c. */
143 symindex bfd_get_next_mapent
144 (bfd *abfd, symindex previous, carsym **sym);
145Only in binutils-2.25/bfd: bfd-in2.h.orig
146Only in binutils-2.25/bfd: bfd-in2.h.rej
147diff -rup binutils-2.25.orig/bfd/elf.c binutils-2.25/bfd/elf.c
148--- binutils-2.25.orig/bfd/elf.c 2014-12-24 10:46:27.884434975 +0000
149+++ binutils-2.25/bfd/elf.c 2014-12-24 10:47:06.954654379 +0000
150@@ -2208,6 +2208,7 @@ static const struct bfd_elf_special_sect
151 { STRING_COMMA_LEN (".gnu.linkonce.b"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
152 { STRING_COMMA_LEN (".gnu.lto_"), -1, SHT_PROGBITS, SHF_EXCLUDE },
153 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
154+ { STRING_COMMA_LEN (".gnu_object_only"), 0, SHT_GNU_OBJECT_ONLY, SHF_EXCLUDE },
155 { STRING_COMMA_LEN (".gnu.version"), 0, SHT_GNU_versym, 0 },
156 { STRING_COMMA_LEN (".gnu.version_d"), 0, SHT_GNU_verdef, 0 },
157 { STRING_COMMA_LEN (".gnu.version_r"), 0, SHT_GNU_verneed, 0 },
158diff -rup binutils-2.25.orig/bfd/format.c binutils-2.25/bfd/format.c
159--- binutils-2.25.orig/bfd/format.c 2014-12-24 10:46:27.897435048 +0000
160+++ binutils-2.25/bfd/format.c 2014-12-24 10:47:06.961654419 +0000
161@@ -94,6 +94,33 @@ bfd_check_format (bfd *abfd, bfd_format
162 return bfd_check_format_matches (abfd, format, NULL);
163 }
164
165+/* Set lto_type in ABFD. */
166+
167+static void
168+bfd_set_lto_type (bfd *abfd)
169+{
170+ if (abfd->format == bfd_object
171+ && abfd->lto_type == lto_non_object
172+ && (abfd->flags & (DYNAMIC | EXEC_P)) == 0)
173+ {
174+ asection *sec;
175+ enum bfd_lto_object_type type = lto_non_ir_object;
176+ for (sec = abfd->sections; sec != NULL; sec = sec->next)
177+ {
178+ if (strcmp (sec->name, GNU_OBJECT_ONLY_SECTION_NAME) == 0)
179+ {
180+ type = lto_mixed_object;
181+ abfd->object_only_section = sec;
182+ break;
183+ }
184+ else if (type != lto_ir_object
185+ && strncmp (sec->name, ".gnu.lto_", 9) == 0)
186+ type = lto_ir_object;
187+ }
188+ abfd->lto_type = type;
189+ }
190+}
191+
192 struct bfd_preserve
193 {
194 void *marker;
195@@ -221,7 +248,10 @@ bfd_check_format_matches (bfd *abfd, bfd
196 }
197
198 if (abfd->format != bfd_unknown)
199- return abfd->format == format;
200+ {
201+ bfd_set_lto_type (abfd);
202+ return abfd->format == format;
203+ }
204
205 if (matching != NULL || *bfd_associated_vector != NULL)
206 {
207@@ -449,6 +479,9 @@ bfd_check_format_matches (bfd *abfd, bfd
208 if (matching_vector)
209 free (matching_vector);
210
211+ bfd_set_lto_type (abfd);
212+
213+
214 /* File position has moved, BTW. */
215 return TRUE;
216 }
217Only in binutils-2.25/bfd: format.c.orig
218diff -rup binutils-2.25.orig/bfd/opncls.c binutils-2.25/bfd/opncls.c
219--- binutils-2.25.orig/bfd/opncls.c 2014-12-24 10:46:27.903435082 +0000
220+++ binutils-2.25/bfd/opncls.c 2014-12-24 10:47:06.962654424 +0000
221@@ -1711,3 +1711,69 @@ bfd_fill_in_gnu_debuglink_section (bfd *
222
223 return TRUE;
224 }
225+
226+/*
227+FUNCTION
228+ bfd_extract_object_only_section
229+
230+SYNOPSIS
231+ const char *bfd_extract_object_only_section
232+ (bfd *abfd);
233+
234+DESCRIPTION
235+
236+ Takes a @var{ABFD} and extract the .gnu_object_only section into
237+ a temporary file.
238+
239+RETURNS
240+ The name of the temporary file is returned if all is ok.
241+ Otherwise <<NULL>> is returned and bfd_error is set.
242+*/
243+
244+const char *
245+bfd_extract_object_only_section (bfd *abfd)
246+{
247+ asection *sec = abfd->object_only_section;
248+ const char *name;
249+ FILE *file;
250+ bfd_byte *memhunk = NULL;
251+ size_t off, size;
252+ bfd_error_type err;
253+
254+ /* Get a temporary object-only file. */
255+ name = make_temp_file (".obj-only.o");
256+
257+ /* Open the object-only file. */
258+ file = real_fopen (name, FOPEN_WB);
259+ if (!bfd_get_full_section_contents (abfd, sec, &memhunk))
260+ {
261+ err = bfd_get_error ();
262+
263+loser:
264+ free (memhunk);
265+ fclose (file);
266+ unlink (name);
267+ bfd_set_error (err);
268+ return NULL;
269+ }
270+
271+ off = 0;
272+ size = sec->size;
273+ while (off != size)
274+ {
275+ size_t written, nwrite = size - off;
276+
277+ written = fwrite (memhunk + off, 1, nwrite, file);
278+ if (written < nwrite && ferror (file))
279+ {
280+ err = bfd_error_system_call;
281+ goto loser;
282+ }
283+
284+ off += written;
285+ }
286+
287+ free (memhunk);
288+ fclose (file);
289+ return name;
290+}
291Only in binutils-2.25/bfd: opncls.c.orig
292diff -rup binutils-2.25.orig/bfd/plugin.c binutils-2.25/bfd/plugin.c
293--- binutils-2.25.orig/bfd/plugin.c 2014-12-24 10:46:27.898435054 +0000
294+++ binutils-2.25/bfd/plugin.c 2014-12-24 10:47:06.963654430 +0000
295@@ -129,6 +129,139 @@ register_claim_file (ld_plugin_claim_fil
296 return LDPS_OK;
297 }
298
299+static asection bfd_plugin_fake_text_section
300+ = BFD_FAKE_SECTION (bfd_plugin_fake_text_section, 0, 0, ".text", 0);
301+static asection bfd_plugin_fake_common_section
302+ = BFD_FAKE_SECTION (bfd_plugin_fake_common_section, SEC_IS_COMMON, 0,
303+ NULL, 0);
304+
305+/* Get symbols from object only section. */
306+
307+static void
308+bfd_plugin_get_symbols_in_object_only (bfd *abfd)
309+{
310+ struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
311+ const char *object_only_file;
312+ bfd *nbfd;
313+ long storage;
314+ long object_only_nsyms, added_nsyms, i;
315+ asymbol **object_only_syms, **added_syms;
316+
317+ plugin_data->object_only_syms = NULL;
318+ plugin_data->object_only_nsyms = 0;
319+
320+ if (abfd->sections == NULL && abfd->my_archive == NULL)
321+ {
322+ nbfd = bfd_openr (abfd->filename, NULL);
323+ if (nbfd == NULL || !bfd_check_format (nbfd, bfd_object))
324+ {
325+ (*_bfd_error_handler)
326+ (_("%s: failed to open to extract object only section: %s"),
327+ abfd->filename, bfd_errmsg (bfd_get_error ()));
328+ bfd_close (nbfd);
329+ return;
330+ }
331+ }
332+ else
333+ {
334+ if (!bfd_check_format (abfd, bfd_object))
335+ {
336+ (*_bfd_error_handler)
337+ (_("%B: invalid file to extract object only section: %s"),
338+ abfd, bfd_errmsg (bfd_get_error ()));
339+ return;
340+ }
341+ nbfd = abfd;
342+ }
343+
344+ if (nbfd->lto_type == lto_mixed_object
345+ && (nbfd->flags & HAS_SYMS) != 0)
346+ {
347+ object_only_file = bfd_extract_object_only_section (nbfd);
348+ if (object_only_file == NULL)
349+ (*_bfd_error_handler)
350+ (_("%B: failed to extract object only section: %s"),
351+ abfd, bfd_errmsg (bfd_get_error ()));
352+ }
353+ else
354+ object_only_file = NULL;
355+
356+ /* Close the new bfd we just opened. */
357+ if (nbfd != abfd)
358+ bfd_close (nbfd);
359+
360+ /* Return if there is no object only section or there is no
361+ symbol in object only section. */
362+ if (!object_only_file)
363+ return;
364+
365+ /* Open the file containing object only section. */
366+ nbfd = bfd_openr (object_only_file, NULL);
367+ if (!bfd_check_format (nbfd, bfd_object))
368+ {
369+ (*_bfd_error_handler)
370+ (_("%B: failed to open object only section: %s"),
371+ abfd, bfd_errmsg (bfd_get_error ()));
372+ goto quit;
373+ }
374+
375+ storage = bfd_get_symtab_upper_bound (nbfd);
376+ if (storage <= 0)
377+ {
378+ if (storage < 0)
379+ (*_bfd_error_handler)
380+ (_("%B: failed to get symbol table in object only section: %s"),
381+ abfd, bfd_errmsg (bfd_get_error ()));
382+
383+ goto quit;
384+ }
385+
386+ object_only_syms = (asymbol **) bfd_malloc (storage);
387+ object_only_nsyms = bfd_canonicalize_symtab (nbfd, object_only_syms);
388+
389+ /* FIXME: We waste some spaces if not all symbols are copied. */
390+ added_syms = (asymbol **) bfd_alloc (abfd, storage);
391+ added_nsyms = 0;
392+
393+ /* Copy only global symbols from object only section. */
394+ for (i = 0; i < object_only_nsyms; i++)
395+ {
396+ asection *sec = object_only_syms[i]->section;
397+ flagword flags = object_only_syms[i]->flags;
398+ asymbol *s;
399+
400+ if (bfd_is_com_section (sec))
401+ sec = &bfd_plugin_fake_common_section;
402+ else if (bfd_is_und_section (sec))
403+ ;
404+ else if ((flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE)) != 0)
405+ sec = &bfd_plugin_fake_text_section;
406+ else
407+ continue;
408+
409+ s = bfd_alloc (abfd, sizeof (asymbol));
410+ BFD_ASSERT (s);
411+ added_syms[added_nsyms++] = s;
412+
413+ s->section = sec;
414+ s->the_bfd = abfd;
415+ s->name = xstrdup (object_only_syms[i]->name);
416+ s->value = 0;
417+ s->flags = flags;
418+ s->udata.p = NULL;
419+ }
420+
421+ plugin_data->object_only_syms = added_syms;
422+ plugin_data->object_only_nsyms = added_nsyms;
423+
424+ free (object_only_syms);
425+
426+quit:
427+ /* Close and remove the object only section file. */
428+ bfd_close (nbfd);
429+ unlink (object_only_file);
430+}
431+
432 static enum ld_plugin_status
433 add_symbols (void * handle,
434 int nsyms,
435@@ -141,7 +274,9 @@ add_symbols (void * handle,
436 plugin_data->nsyms = nsyms;
437 plugin_data->syms = syms;
438
439- if (nsyms != 0)
440+ bfd_plugin_get_symbols_in_object_only (abfd);
441+
442+ if ((nsyms + plugin_data->object_only_nsyms) != 0)
443 abfd->flags |= HAS_SYMS;
444
445 abfd->tdata.plugin_data = plugin_data;
446@@ -390,7 +525,8 @@ static long
447 bfd_plugin_get_symtab_upper_bound (bfd *abfd)
448 {
449 struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
450- long nsyms = plugin_data->nsyms;
451+ /* Add symbols from object only section. */
452+ long nsyms = plugin_data->nsyms + plugin_data->object_only_nsyms;
453
454 BFD_ASSERT (nsyms >= 0);
455
456@@ -424,12 +560,7 @@ bfd_plugin_canonicalize_symtab (bfd *abf
457 struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
458 long nsyms = plugin_data->nsyms;
459 const struct ld_plugin_symbol *syms = plugin_data->syms;
460- static asection fake_section;
461- static asection fake_common_section;
462- int i;
463-
464- fake_section.name = ".text";
465- fake_common_section.flags = SEC_IS_COMMON;
466+ int i, j;
467
468 for (i = 0; i < nsyms; i++)
469 {
470@@ -442,10 +573,11 @@ bfd_plugin_canonicalize_symtab (bfd *abf
471 s->name = syms[i].name;
472 s->value = 0;
473 s->flags = convert_flags (&syms[i]);
474+ s->udata.p = NULL;
475 switch (syms[i].def)
476 {
477 case LDPK_COMMON:
478- s->section = &fake_common_section;
479+ s->section = &bfd_plugin_fake_common_section;
480 break;
481 case LDPK_UNDEF:
482 case LDPK_WEAKUNDEF:
483@@ -453,15 +585,18 @@ bfd_plugin_canonicalize_symtab (bfd *abf
484 break;
485 case LDPK_DEF:
486 case LDPK_WEAKDEF:
487- s->section = &fake_section;
488+ s->section = &bfd_plugin_fake_text_section;
489 break;
490 default:
491 BFD_ASSERT (0);
492 }
493-
494- s->udata.p = (void *) &syms[i];
495 }
496
497+ /* Copy symbols from object only section. */
498+ nsyms += plugin_data->object_only_nsyms;
499+ for (j = 0; j < plugin_data->object_only_nsyms; j++, i++)
500+ alocation[i] = plugin_data->object_only_syms[j];
501+
502 return nsyms;
503 }
504
505Only in binutils-2.25/bfd: plugin.c.orig
506diff -rup binutils-2.25.orig/bfd/plugin.h binutils-2.25/bfd/plugin.h
507--- binutils-2.25.orig/bfd/plugin.h 2014-12-24 10:46:27.894435031 +0000
508+++ binutils-2.25/bfd/plugin.h 2014-12-24 10:47:06.964654436 +0000
509@@ -30,6 +30,8 @@ typedef struct plugin_data_struct
510 {
511 int nsyms;
512 const struct ld_plugin_symbol *syms;
513+ int object_only_nsyms;
514+ asymbol **object_only_syms;
515 }
516 plugin_data_struct;
517
518diff -rup binutils-2.25.orig/bfd/section.c binutils-2.25/bfd/section.c
519--- binutils-2.25.orig/bfd/section.c 2014-12-24 10:46:27.882434964 +0000
520+++ binutils-2.25/bfd/section.c 2014-12-24 10:47:07.163655553 +0000
521@@ -595,6 +595,9 @@ CODE_FRAGMENT
522 . || ((SEC) == bfd_com_section_ptr) \
523 . || ((SEC) == bfd_ind_section_ptr))
524 .
525+.{* GNU object-only section name. *}
526+.#define GNU_OBJECT_ONLY_SECTION_NAME ".gnu_object_only"
527+.
528 .{* Macros to handle insertion and deletion of a bfd's sections. These
529 . only handle the list pointers, ie. do not adjust section_count,
530 . target_index etc. *}
531Only in binutils-2.25/bfd: section.c.orig
532diff -rup binutils-2.25.orig/binutils/objcopy.c binutils-2.25/binutils/objcopy.c
533--- binutils-2.25.orig/binutils/objcopy.c 2014-12-24 10:46:27.917435160 +0000
534+++ binutils-2.25/binutils/objcopy.c 2014-12-24 10:47:07.165655564 +0000
535@@ -1009,30 +1009,6 @@ is_specified_symbol (const char *name, h
536 return htab_find (htab, name) != NULL;
537 }
538
539-/* Return a pointer to the symbol used as a signature for GROUP. */
540-
541-static asymbol *
542-group_signature (asection *group)
543-{
544- bfd *abfd = group->owner;
545- Elf_Internal_Shdr *ghdr;
546-
547- if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
548- return NULL;
549-
550- ghdr = &elf_section_data (group)->this_hdr;
551- if (ghdr->sh_link < elf_numsections (abfd))
552- {
553- const struct elf_backend_data *bed = get_elf_backend_data (abfd);
554- Elf_Internal_Shdr *symhdr = elf_elfsections (abfd) [ghdr->sh_link];
555-
556- if (symhdr->sh_type == SHT_SYMTAB
557- && ghdr->sh_info < symhdr->sh_size / bed->s->sizeof_sym)
558- return isympp[ghdr->sh_info - 1];
559- }
560- return NULL;
561-}
562-
563 /* Return TRUE if the section is a DWO section. */
564
565 static bfd_boolean
566@@ -1114,7 +1090,7 @@ is_strip_section (bfd *abfd ATTRIBUTE_UN
567 /* PR binutils/3181
568 If we are going to strip the group signature symbol, then
569 strip the group section too. */
570- gsym = group_signature (sec);
571+ gsym = bfd_group_signature (sec, isympp);
572 if (gsym != NULL)
573 gname = gsym->name;
574 else
575@@ -2823,7 +2799,7 @@ setup_section (bfd *ibfd, sec_ptr isecti
576
577 if ((isection->flags & SEC_GROUP) != 0)
578 {
579- asymbol *gsym = group_signature (isection);
580+ asymbol *gsym = bfd_group_signature (isection, isympp);
581
582 if (gsym != NULL)
583 {
584Only in binutils-2.25/binutils: objcopy.c.orig
585diff -rup binutils-2.25.orig/binutils/readelf.c binutils-2.25/binutils/readelf.c
586--- binutils-2.25.orig/binutils/readelf.c 2014-12-24 10:46:27.916435155 +0000
587+++ binutils-2.25/binutils/readelf.c 2014-12-24 10:47:07.170655592 +0000
588@@ -3624,6 +3624,7 @@ get_section_type_name (unsigned int sh_t
589 case 0x7ffffffd: return "AUXILIARY";
590 case 0x7fffffff: return "FILTER";
591 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
592+ case SHT_GNU_OBJECT_ONLY: return "GNU_OBJECT_ONLY";
593
594 default:
595 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
596Only in binutils-2.25/binutils: readelf.c.orig
597diff -rup binutils-2.25.orig/include/bfdlink.h binutils-2.25/include/bfdlink.h
598--- binutils-2.25.orig/include/bfdlink.h 2014-12-24 10:46:27.704433964 +0000
599+++ binutils-2.25/include/bfdlink.h 2014-12-24 10:47:07.170655592 +0000
600@@ -389,6 +389,12 @@ struct bfd_link_info
601 /* TRUE if ok to have multiple definition. */
602 unsigned int allow_multiple_definition: 1;
603
604+ /* TRUE if .gnu_object_only section should be created. */
605+ unsigned int emit_gnu_object_only: 1;
606+
607+ /* TRUE if .gnu_object_only section is being created. */
608+ unsigned int emitting_gnu_object_only: 1;
609+
610 /* TRUE if ok to have version with no definition. */
611 unsigned int allow_undefined_version: 1;
612
613Only in binutils-2.25/include: bfdlink.h.orig
614diff -rup binutils-2.25.orig/include/elf/common.h binutils-2.25/include/elf/common.h
615--- binutils-2.25.orig/include/elf/common.h 2014-12-24 10:46:27.698433930 +0000
616+++ binutils-2.25/include/elf/common.h 2014-12-24 10:47:07.171655598 +0000
617@@ -472,6 +472,7 @@
618 #define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes */
619 #define SHT_GNU_HASH 0x6ffffff6 /* GNU style symbol hash table */
620 #define SHT_GNU_LIBLIST 0x6ffffff7 /* List of prelink dependencies */
621+#define SHT_GNU_OBJECT_ONLY 0x6ffffff8 /* Object only */
622
623 /* The next three section types are defined by Solaris, and are named
624 SHT_SUNW*. We use them in GNU code, so we also define SHT_GNU*
625diff -rup binutils-2.25.orig/ld/emultempl/alphaelf.em binutils-2.25/ld/emultempl/alphaelf.em
626--- binutils-2.25.orig/ld/emultempl/alphaelf.em 2014-12-24 10:46:27.717434037 +0000
627+++ binutils-2.25/ld/emultempl/alphaelf.em 2014-12-24 10:47:07.172655604 +0000
628@@ -100,7 +100,7 @@ alpha_finish (void)
629 if (limit_32bit)
630 elf_elfheader (link_info.output_bfd)->e_flags |= EF_ALPHA_32BIT;
631
632- finish_default ();
633+ gld${EMULATION_NAME}_finish ();
634 }
635 EOF
636
637diff -rup binutils-2.25.orig/ld/emultempl/armelf.em binutils-2.25/ld/emultempl/armelf.em
638--- binutils-2.25.orig/ld/emultempl/armelf.em 2014-12-24 10:46:27.718434043 +0000
639+++ binutils-2.25/ld/emultempl/armelf.em 2014-12-24 10:47:07.172655604 +0000
640@@ -370,7 +370,7 @@ gld${EMULATION_NAME}_after_allocation (v
641 }
642
643 static void
644-gld${EMULATION_NAME}_finish (void)
645+arm_finish (void)
646 {
647 struct bfd_link_hash_entry * h;
648
649@@ -393,7 +393,7 @@ gld${EMULATION_NAME}_finish (void)
650 }
651 }
652
653- finish_default ();
654+ gld${EMULATION_NAME}_finish ();
655
656 if (thumb_entry_symbol)
657 {
658@@ -702,4 +702,4 @@ LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=
659 LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
660
661 # Call the extra arm-elf function
662-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
663+LDEMUL_FINISH=arm_finish
664Only in binutils-2.25/ld/emultempl: armelf.em.orig
665diff -rup binutils-2.25.orig/ld/emultempl/elf32.em binutils-2.25/ld/emultempl/elf32.em
666--- binutils-2.25.orig/ld/emultempl/elf32.em 2014-12-24 10:46:27.717434037 +0000
667+++ binutils-2.25/ld/emultempl/elf32.em 2014-12-24 10:47:07.174655615 +0000
668@@ -65,6 +65,7 @@ static void gld${EMULATION_NAME}_before_
669 static void gld${EMULATION_NAME}_after_allocation (void);
670 static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan
671 (asection *, const char *, int);
672+static void gld${EMULATION_NAME}_finish (void);
673 EOF
674
675 if [ "x${USE_LIBPATH}" = xyes ] ; then
676@@ -1730,6 +1731,8 @@ output_rel_find (asection *sec, int isdy
677 return last;
678 }
679
680+static int orphan_init_done = 0;
681+
682 /* Place an orphan section. We use this to put random SHF_ALLOC
683 sections in the right segment. */
684
685@@ -1738,7 +1741,7 @@ gld${EMULATION_NAME}_place_orphan (asect
686 const char *secname,
687 int constraint)
688 {
689- static struct orphan_save hold[] =
690+ static struct orphan_save orig_hold[] =
691 {
692 { ".text",
693 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
694@@ -1768,6 +1771,7 @@ gld${EMULATION_NAME}_place_orphan (asect
695 SEC_HAS_CONTENTS,
696 0, 0, 0, 0 },
697 };
698+ static struct orphan_save hold[ARRAY_SIZE (orig_hold)];
699 enum orphan_save_index
700 {
701 orphan_text = 0,
702@@ -1780,7 +1784,6 @@ gld${EMULATION_NAME}_place_orphan (asect
703 orphan_sdata,
704 orphan_nonalloc
705 };
706- static int orphan_init_done = 0;
707 struct orphan_save *place;
708 lang_output_section_statement_type *after;
709 lang_output_section_statement_type *os;
710@@ -1857,15 +1860,22 @@ gld${EMULATION_NAME}_place_orphan (asect
711
712 if (!orphan_init_done)
713 {
714- struct orphan_save *ho;
715+ struct orphan_save *ho, *horig;
716
717 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
718+ for (ho = hold, horig = orig_hold;
719+ ho < hold + ARRAY_SIZE (hold);
720+ ++ho, ++horig)
721+ {
722+ *ho = *horig;
723+ if (ho->name != NULL)
724 if (ho->name != NULL)
725 {
726 ho->os = lang_output_section_find (ho->name);
727 if (ho->os != NULL && ho->os->flags == 0)
728 ho->os->flags = ho->flags;
729 }
730+ }
731 orphan_init_done = 1;
732 }
733
734@@ -1937,6 +1947,27 @@ gld${EMULATION_NAME}_place_orphan (asect
735 EOF
736 fi
737
738+fragment <<EOF
739+
740+/* Final emulation specific call. */
741+
742+static void
743+gld${EMULATION_NAME}_finish (void)
744+{
745+EOF
746+if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
747+fragment <<EOF
748+ /* Support the object-only output. */
749+ if (link_info.emit_gnu_object_only)
750+ orphan_init_done = 0;
751+
752+EOF
753+fi
754+fragment <<EOF
755+ finish_default ();
756+}
757+EOF
758+
759 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
760 fragment <<EOF
761
762@@ -2505,7 +2536,7 @@ struct ld_emulation_xfer_struct ld_${EMU
763 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
764 "${EMULATION_NAME}",
765 "${OUTPUT_FORMAT}",
766- ${LDEMUL_FINISH-finish_default},
767+ ${LDEMUL_FINISH-gld${EMULATION_NAME}_finish},
768 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
769 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
770 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
771Only in binutils-2.25/ld/emultempl: elf32.em.orig
772diff -rup binutils-2.25.orig/ld/emultempl/ppc64elf.em binutils-2.25/ld/emultempl/ppc64elf.em
773--- binutils-2.25.orig/ld/emultempl/ppc64elf.em 2014-12-24 10:46:27.717434037 +0000
774+++ binutils-2.25/ld/emultempl/ppc64elf.em 2014-12-24 10:47:07.174655615 +0000
775@@ -522,7 +522,7 @@ gld${EMULATION_NAME}_after_allocation (v
776 /* Final emulation specific call. */
777
778 static void
779-gld${EMULATION_NAME}_finish (void)
780+ppc_finish (void)
781 {
782 char *msg = NULL;
783 char *line, *endline;
784@@ -554,7 +554,7 @@ gld${EMULATION_NAME}_finish (void)
785 free (msg);
786
787 ppc64_elf_restore_symbols (&link_info);
788- finish_default ();
789+ gld${EMULATION_NAME}_finish ();
790 }
791
792
793@@ -876,6 +876,6 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LI
794 #
795 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
796 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
797-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
798+LDEMUL_FINISH=ppc_finish
799 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_create_output_section_statements
800 LDEMUL_NEW_VERS_PATTERN=gld${EMULATION_NAME}_new_vers_pattern
801Only in binutils-2.25/ld/emultempl: ppc64elf.em.orig
802diff -rup binutils-2.25.orig/ld/emultempl/spuelf.em binutils-2.25/ld/emultempl/spuelf.em
803--- binutils-2.25.orig/ld/emultempl/spuelf.em 2014-12-24 10:46:27.716434032 +0000
804+++ binutils-2.25/ld/emultempl/spuelf.em 2014-12-24 10:47:07.175655620 +0000
805@@ -416,7 +416,7 @@ spu_elf_relink (void)
806 /* Final emulation specific call. */
807
808 static void
809-gld${EMULATION_NAME}_finish (void)
810+spu_finish (void)
811 {
812 if (is_spu_target ())
813 {
814@@ -432,7 +432,7 @@ gld${EMULATION_NAME}_finish (void)
815 einfo ("%P: --auto-overlay ignored with zero local store range\n");
816 }
817
818- finish_default ();
819+ gld${EMULATION_NAME}_finish ();
820 }
821
822 static char *
823@@ -832,5 +832,5 @@ PARSE_AND_LIST_ARGS_CASES='
824
825 LDEMUL_AFTER_OPEN=spu_after_open
826 LDEMUL_BEFORE_ALLOCATION=spu_before_allocation
827-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
828+LDEMUL_FINISH=spu_finish
829 LDEMUL_CHOOSE_TARGET=gld${EMULATION_NAME}_choose_target
830diff -rup binutils-2.25.orig/ld/ldfile.c binutils-2.25/ld/ldfile.c
831--- binutils-2.25.orig/ld/ldfile.c 2014-12-24 10:46:27.708433987 +0000
832+++ binutils-2.25/ld/ldfile.c 2014-12-24 10:57:43.021241971 +0000
833@@ -317,7 +317,9 @@ success:
834 plugin_maybe_claim (&file, entry);
835 }
836 }
837+ else
838 #endif /* ENABLE_PLUGINS */
839+ cmdline_check_object_only_section (entry->the_bfd, FALSE);
840
841 /* It opened OK, the format checked out, and the plugins have had
842 their chance to claim it, so this is success. */
843Only in binutils-2.25/ld: ldfile.c.orig
844diff -rup binutils-2.25.orig/ld/ldlang.c binutils-2.25/ld/ldlang.c
845--- binutils-2.25.orig/ld/ldlang.c 2014-12-24 10:46:27.712434009 +0000
846+++ binutils-2.25/ld/ldlang.c 2014-12-24 11:00:13.328090658 +0000
847@@ -36,6 +36,7 @@
848 #include "ldctor.h"
849 #include "ldfile.h"
850 #include "ldemul.h"
851+#include "ldwrite.h"
852 #include "fnmatch.h"
853 #include "demangle.h"
854 #include "hashtab.h"
855@@ -45,6 +46,9 @@
856 #include "plugin.h"
857 #endif /* ENABLE_PLUGINS */
858
859+/* FIXME: Put it here to avoid NAME conflict from ldgram.h. */
860+#include "elf-bfd.h"
861+
862 #ifndef offsetof
863 #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER))
864 #endif
865@@ -69,6 +73,9 @@ static lang_statement_list_type *stat_sa
866 static lang_statement_list_type **stat_save_ptr = &stat_save[0];
867 static struct unique_sections *unique_section_list;
868 static struct asneeded_minfo *asneeded_list_head;
869+static cmdline_list_type cmdline_object_only_file_list;
870+static cmdline_list_type cmdline_object_only_archive_list;
871+static cmdline_list_type cmdline_temp_object_only_list;
872
873 /* Forward declarations. */
874 static void exp_init_os (etree_type *);
875@@ -88,6 +95,10 @@ static void lang_record_phdrs (void);
876 static void lang_do_version_exports_section (void);
877 static void lang_finalize_version_expr_head
878 (struct bfd_elf_version_expr_head *);
879+static void cmdline_lists_init (void);
880+static void cmdline_get_object_only_input_files (void);
881+static void print_cmdline_list (cmdline_union_type *);
882+static bfd_boolean cmdline_on_object_only_archive_list_p (bfd *);
883
884 /* Exported variables. */
885 const char *output_target;
886@@ -1221,14 +1232,17 @@ output_section_statement_table_free (voi
887 /* Build enough state so that the parser can build its tree. */
888
889 void
890-lang_init (void)
891+lang_init (bfd_boolean object_only)
892 {
893- obstack_begin (&stat_obstack, 1000);
894+ if (!object_only)
895+ obstack_begin (&stat_obstack, 1000);
896
897 stat_ptr = &statement_list;
898
899 output_section_statement_table_init ();
900
901+ cmdline_lists_init ();
902+
903 lang_list_init (stat_ptr);
904
905 lang_list_init (&input_file_chain);
906@@ -1243,10 +1257,11 @@ lang_init (void)
907
908 /* The value "13" is ad-hoc, somewhat related to the expected number of
909 assignments in a linker script. */
910- if (!bfd_hash_table_init_n (&lang_definedness_table,
911- lang_definedness_newfunc,
912- sizeof (struct lang_definedness_hash_entry),
913- 13))
914+ if (!object_only
915+ && !bfd_hash_table_init_n (&lang_definedness_table,
916+ lang_definedness_newfunc,
917+ sizeof (struct lang_definedness_hash_entry),
918+ 13))
919 einfo (_("%P%F: can not create hash table: %E\n"));
920
921 asneeded_list_head = NULL;
922@@ -2839,6 +2854,12 @@ load_symbols (lang_input_statement_type
923 loaded = FALSE;
924 }
925
926+ if (link_info.emitting_gnu_object_only)
927+ {
928+ if (!cmdline_on_object_only_archive_list_p (member))
929+ continue;
930+ }
931+
932 subsbfd = member;
933 if (!(*link_info.callbacks
934 ->add_archive_element) (&link_info, member,
935@@ -6740,7 +6761,37 @@ lang_process (void)
936 open_input_bfds (statement_list.head, OPEN_BFD_RESCAN);
937 }
938 }
939+ else
940 #endif /* ENABLE_PLUGINS */
941+ if (link_info.relocatable)
942+ {
943+ /* Check if .gnu_object_only section should be created. */
944+ bfd *p;
945+ int object_type;
946+
947+ object_type = 0;
948+ for (p = link_info.input_bfds; p != (bfd *) NULL; p = p->link.next)
949+ {
950+ object_type |= 1 << p->lto_type;
951+ if ((object_type & (1 << lto_mixed_object)) != 0
952+ || ((object_type
953+ & (1 << lto_non_ir_object
954+ | 1 << lto_ir_object))
955+ == (1 << lto_non_ir_object | 1 << lto_ir_object)))
956+ {
957+ link_info.emit_gnu_object_only = TRUE;
958+ break;
959+ }
960+ }
961+
962+ if (trace_files
963+ && (cmdline_object_only_file_list.head
964+ || cmdline_object_only_archive_list.head))
965+ {
966+ print_cmdline_list (cmdline_object_only_file_list.head);
967+ print_cmdline_list (cmdline_object_only_archive_list.head);
968+ }
969+ }
970
971 link_info.gc_sym_list = &entry_symbol;
972 if (entry_symbol.name == NULL)
973@@ -8142,3 +8193,961 @@ lang_ld_feature (char *str)
974 p = q;
975 }
976 }
977+
978+static void
979+cmdline_lists_init (void)
980+{
981+ cmdline_object_only_file_list.tail
982+ = &cmdline_object_only_file_list.head;
983+ cmdline_object_only_archive_list.tail
984+ = &cmdline_object_only_archive_list.head;
985+ cmdline_temp_object_only_list.tail
986+ = &cmdline_temp_object_only_list.head;
987+}
988+
989+/* Allocate an item with TYPE and DATA. */
990+
991+static cmdline_union_type *
992+cmdline_list_new (cmdline_enum_type type, void *data)
993+{
994+ cmdline_union_type *new_opt;
995+
996+ new_opt = (cmdline_union_type *) stat_alloc (sizeof (*new_opt));
997+ new_opt->header.type = type;
998+ switch (type)
999+ {
1000+ default:
1001+ break;
1002+ case cmdline_is_file_enum:
1003+ new_opt->file.filename = (const char *) data;
1004+ break;
1005+ case cmdline_is_bfd_enum:
1006+ new_opt->abfd.abfd = (bfd *) data;
1007+ break;
1008+ }
1009+ return new_opt;
1010+}
1011+
1012+/* Append an item with TYPE and DATA to LIST. */
1013+
1014+static void
1015+cmdline_list_append (cmdline_list_type *list, cmdline_enum_type type,
1016+ void *data)
1017+{
1018+ cmdline_union_type *new_opt = cmdline_list_new (type, data);
1019+ new_opt->header.next = NULL;
1020+ *list->tail = new_opt;
1021+ list->tail = &new_opt->header.next;
1022+}
1023+
1024+static void
1025+print_cmdline_list (cmdline_union_type *c)
1026+{
1027+ for (; c != NULL; c = c->header.next)
1028+ switch (c->header.type)
1029+ {
1030+ default:
1031+ abort ();
1032+ case cmdline_is_file_enum:
1033+ info_msg (" %s", c->file.filename);
1034+ break;
1035+ case cmdline_is_bfd_enum:
1036+ info_msg (" [%B]", c->abfd.abfd);
1037+ break;
1038+ }
1039+
1040+ info_msg ("\n");
1041+}
1042+
1043+/* Return TRUE if ABFD is on cmdline_object_only_archive_list. */
1044+
1045+static bfd_boolean
1046+cmdline_on_object_only_archive_list_p (bfd *abfd)
1047+{
1048+ cmdline_union_type *c, *next;
1049+ bfd *archive, *obfd, *oarchive;
1050+ ufile_ptr origin = abfd->origin;
1051+
1052+ archive = bfd_my_archive (abfd);
1053+ for (c = cmdline_object_only_archive_list.head; c != NULL; c = next)
1054+ {
1055+ if (c->header.type != cmdline_is_bfd_enum)
1056+ abort ();
1057+
1058+ next = c->header.next;
1059+ obfd = c->abfd.abfd;
1060+ oarchive = bfd_my_archive (obfd);
1061+
1062+ /* The list is grouped by archive file name and sorted by member
1063+ origin. */
1064+ if (strcmp (archive->filename, oarchive->filename) != 0)
1065+ continue;
1066+
1067+ if (origin == obfd->origin)
1068+ return TRUE;
1069+ else if (origin < obfd->origin)
1070+ return FALSE;
1071+ }
1072+
1073+ return FALSE;
1074+}
1075+
1076+/* Append an item with TYPE and DATA to cmdline_object_only_file_list
1077+ or cmdline_object_only_archive_list if needed. */
1078+
1079+static void
1080+cmdline_object_only_list_append (cmdline_enum_type type, void *data)
1081+{
1082+ cmdline_union_type *c;
1083+ cmdline_union_type *new_opt, *next, **prev;
1084+ bfd *abfd, *archive;
1085+ bfd *obfd, *oarchive;
1086+ bfd *nbfd, *narchive;
1087+ ufile_ptr origin, norigin;
1088+
1089+ /* Put it on cmdline_object_only_file_list if it isn't an archive
1090+ member. */
1091+ switch (type)
1092+ {
1093+ default:
1094+ abort ();
1095+ case cmdline_is_bfd_enum:
1096+ abfd = (bfd *) data;
1097+ archive = bfd_my_archive (abfd);
1098+ if (archive)
1099+ break;
1100+ case cmdline_is_file_enum:
1101+ cmdline_list_append (&cmdline_object_only_file_list, type, data);
1102+ return;
1103+ }
1104+
1105+ /* Put archive member on cmdline_object_only_archive_list and sort
1106+ the list by archive name and archive member origin. */
1107+ new_opt = (cmdline_union_type *) stat_alloc (sizeof (*new_opt));
1108+ new_opt->header.type = cmdline_is_bfd_enum;
1109+ new_opt->header.next = NULL;
1110+ new_opt->abfd.abfd = (bfd *) data;
1111+
1112+ c = cmdline_object_only_archive_list.head;
1113+ if (c == NULL)
1114+ {
1115+ cmdline_object_only_archive_list.head = new_opt;
1116+ cmdline_object_only_archive_list.tail = &new_opt->header.next;
1117+ return;
1118+ }
1119+
1120+ prev = NULL;
1121+ origin = abfd->origin;
1122+ for (; c != NULL; c = next)
1123+ {
1124+ if (c->header.type != cmdline_is_bfd_enum)
1125+ abort ();
1126+
1127+ next = c->header.next;
1128+
1129+ obfd = c->abfd.abfd;
1130+ oarchive = bfd_my_archive (obfd);
1131+
1132+ if (strcmp (archive->filename, oarchive->filename) == 0)
1133+ {
1134+ bfd_boolean after;
1135+
1136+ if (origin < obfd->origin)
1137+ {
1138+ /* Insert it before the current. */
1139+ new_opt->header.next = c;
1140+ if (prev)
1141+ *prev = new_opt;
1142+ else
1143+ cmdline_object_only_archive_list.head = new_opt;
1144+ return;
1145+ }
1146+
1147+ after = TRUE;
1148+
1149+ /* Check origin. */
1150+ while (next)
1151+ {
1152+ if (next->header.type != cmdline_is_bfd_enum)
1153+ abort ();
1154+
1155+ nbfd = next->abfd.abfd;
1156+ norigin = nbfd->origin;
1157+ if (origin > norigin)
1158+ {
1159+ /* Insert it after NEXT. */
1160+ break;
1161+ }
1162+
1163+ narchive = bfd_my_archive (nbfd);
1164+ if (strcmp (archive->filename, narchive->filename) != 0)
1165+ {
1166+ /* Insert it befor NEXT. */
1167+ after = FALSE;
1168+ break;
1169+ }
1170+
1171+ c = next;
1172+ next = next->header.next;
1173+ }
1174+
1175+ if (after && next)
1176+ {
1177+ c = next;
1178+ next = next->header.next;
1179+ }
1180+
1181+ if (*cmdline_object_only_archive_list.tail == c->header.next)
1182+ cmdline_object_only_archive_list.tail
1183+ = &new_opt->header.next;
1184+
1185+ prev = &c->header.next;
1186+ new_opt->header.next = next;
1187+ *prev = new_opt;
1188+ return;
1189+ }
1190+
1191+ prev = &c->header.next;
1192+ }
1193+
1194+ *cmdline_object_only_archive_list.tail = new_opt;
1195+ cmdline_object_only_archive_list.tail = &new_opt->header.next;
1196+}
1197+
1198+
1199+static void
1200+cmdline_get_object_only_input_files (void)
1201+{
1202+ cmdline_union_type *c, *next;
1203+ bfd *abfd, *archive;
1204+ bfd *nbfd, *narchive;
1205+
1206+ /* Add files first. */
1207+ for (c = cmdline_object_only_file_list.head;
1208+ c != NULL; c = c->header.next)
1209+ switch (c->header.type)
1210+ {
1211+ default:
1212+ abort ();
1213+ case cmdline_is_file_enum:
1214+ lang_add_input_file (c->file.filename,
1215+ lang_input_file_is_file_enum, NULL);
1216+ break;
1217+ case cmdline_is_bfd_enum:
1218+ abfd = c->abfd.abfd;
1219+ if (bfd_my_archive (abfd))
1220+ abort ();
1221+ lang_add_input_file (abfd->filename,
1222+ lang_input_file_is_file_enum, NULL);
1223+ break;
1224+ }
1225+
1226+ /* Add archive members next. */
1227+ for (c = cmdline_object_only_archive_list.head; c != NULL; c = next)
1228+ {
1229+ if (c->header.type != cmdline_is_bfd_enum)
1230+ abort ();
1231+
1232+ next = c->header.next;
1233+
1234+ abfd = c->abfd.abfd;
1235+ archive = bfd_my_archive (abfd);
1236+
1237+ /* Add the first archive of the archive member group. */
1238+ lang_add_input_file (archive->filename,
1239+ lang_input_file_is_file_enum, NULL);
1240+
1241+ /* Skip the rest members in the archive member group. */
1242+ do
1243+ {
1244+ if (!next)
1245+ break;
1246+
1247+ if (next->header.type != cmdline_is_bfd_enum)
1248+ abort ();
1249+
1250+ next = next->header.next;
1251+ if (!next)
1252+ break;
1253+ nbfd = next->abfd.abfd;
1254+ narchive = bfd_my_archive (nbfd);
1255+ }
1256+ while (strcmp (archive->filename, narchive->filename) == 0);
1257+ }
1258+}
1259+
1260+struct cmdline_arg
1261+{
1262+ bfd *obfd;
1263+ asymbol **isympp;
1264+ int status;
1265+};
1266+
1267+/* Create a section in OBFD with the same
1268+ name and attributes as ISECTION in IBFD. */
1269+
1270+static void
1271+setup_section (bfd *ibfd, sec_ptr isection, void *p)
1272+{
1273+ struct cmdline_arg *arg = (struct cmdline_arg *) p;
1274+ bfd *obfd = arg->obfd;
1275+ asymbol **isympp = arg->isympp;
1276+ const char *name = isection->name;
1277+ sec_ptr osection;
1278+ const char *err;
1279+
1280+ /* Skip the object-only section. */
1281+ if (ibfd->object_only_section == isection)
1282+ return;
1283+
1284+ /* If we have already failed earlier on, do not keep on generating
1285+ complaints now. */
1286+ if (arg->status)
1287+ return;
1288+
1289+ osection = bfd_make_section_anyway_with_flags (obfd, name,
1290+ isection->flags);
1291+
1292+ if (osection == NULL)
1293+ {
1294+ err = _("failed to create output section");
1295+ goto loser;
1296+ }
1297+
1298+ osection->size = isection->size;
1299+ osection->vma = isection->vma;
1300+ osection->lma = isection->lma;
1301+ osection->alignment_power = isection->alignment_power;
1302+
1303+ /* Copy merge entity size. */
1304+ osection->entsize = isection->entsize;
1305+
1306+ /* This used to be mangle_section; we do here to avoid using
1307+ bfd_get_section_by_name since some formats allow multiple
1308+ sections with the same name. */
1309+ isection->output_section = osection;
1310+ isection->output_offset = 0;
1311+
1312+ if ((isection->flags & SEC_GROUP) != 0)
1313+ {
1314+ asymbol *gsym = bfd_group_signature (isection, isympp);
1315+
1316+ if (gsym != NULL)
1317+ {
1318+ gsym->flags |= BSF_KEEP;
1319+ if (ibfd->xvec->flavour == bfd_target_elf_flavour)
1320+ elf_group_id (isection) = gsym;
1321+ }
1322+ }
1323+
1324+ /* Allow the BFD backend to copy any private data it understands
1325+ from the input section to the output section. */
1326+ if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
1327+ {
1328+ err = _("failed to copy private data");
1329+ goto loser;
1330+ }
1331+
1332+ /* All went well. */
1333+ return;
1334+
1335+loser:
1336+ arg->status = 1;
1337+ einfo (_("%P%F: setup_section: %s: %s\n"), err, name);
1338+}
1339+
1340+/* Copy the data of input section ISECTION of IBFD
1341+ to an output section with the same name in OBFD.
1342+ If stripping then don't copy any relocation info. */
1343+
1344+static void
1345+copy_section (bfd *ibfd, sec_ptr isection, void *p)
1346+{
1347+ struct cmdline_arg *arg = (struct cmdline_arg *) p;
1348+ bfd *obfd = arg->obfd;
1349+ asymbol **isympp = arg->isympp;
1350+ arelent **relpp;
1351+ long relcount;
1352+ sec_ptr osection;
1353+ bfd_size_type size;
1354+ long relsize;
1355+ flagword flags;
1356+ const char *err;
1357+
1358+ /* Skip the object-only section. */
1359+ if (ibfd->object_only_section == isection)
1360+ return;
1361+
1362+ /* If we have already failed earlier on, do not keep on generating
1363+ complaints now. */
1364+ if (arg->status)
1365+ return;
1366+
1367+ flags = bfd_get_section_flags (ibfd, isection);
1368+ if ((flags & SEC_GROUP) != 0)
1369+ return;
1370+
1371+ osection = isection->output_section;
1372+ size = bfd_get_section_size (isection);
1373+
1374+ if (size == 0 || osection == 0)
1375+ return;
1376+
1377+ relsize = bfd_get_reloc_upper_bound (ibfd, isection);
1378+
1379+ if (relsize < 0)
1380+ {
1381+ /* Do not complain if the target does not support relocations. */
1382+ if (relsize == -1
1383+ && bfd_get_error () == bfd_error_invalid_operation)
1384+ relsize = 0;
1385+ else
1386+ {
1387+ err = bfd_errmsg (bfd_get_error ());
1388+ goto loser;
1389+ }
1390+ }
1391+
1392+ if (relsize == 0)
1393+ bfd_set_reloc (obfd, osection, NULL, 0);
1394+ else
1395+ {
1396+ relpp = (arelent **) xmalloc (relsize);
1397+ relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
1398+ if (relcount < 0)
1399+ {
1400+ err = _("relocation count is negative");
1401+ goto loser;
1402+ }
1403+
1404+ bfd_set_reloc (obfd, osection,
1405+ relcount == 0 ? NULL : relpp, relcount);
1406+ if (relcount == 0)
1407+ free (relpp);
1408+ }
1409+
1410+ if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS)
1411+ {
1412+ bfd_byte *memhunk = NULL;
1413+
1414+ if (!bfd_get_full_section_contents (ibfd, isection, &memhunk))
1415+ {
1416+ err = bfd_errmsg (bfd_get_error ());
1417+ goto loser;
1418+ }
1419+
1420+ if (!bfd_set_section_contents (obfd, osection, memhunk, 0, size))
1421+ {
1422+ err = bfd_errmsg (bfd_get_error ());
1423+ goto loser;
1424+ }
1425+ free (memhunk);
1426+ }
1427+
1428+ /* All went well. */
1429+ return;
1430+
1431+loser:
1432+ einfo (_("%P%F: copy_section: %s: %s\n"), err, isection->name);
1433+}
1434+/* Open the temporary bfd created in the same directory as PATH. */
1435+
1436+static bfd *
1437+cmdline_fopen_temp (const char *path, const char *target,
1438+ const char *mode)
1439+{
1440+#define template "ldXXXXXX"
1441+ const char *slash = strrchr (path, '/');
1442+ char *tmpname;
1443+ size_t len;
1444+ int fd;
1445+
1446+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
1447+ {
1448+ /* We could have foo/bar\\baz, or foo\\bar, or d:bar. */
1449+ char *bslash = strrchr (path, '\\');
1450+
1451+ if (slash == NULL || (bslash != NULL && bslash > slash))
1452+ slash = bslash;
1453+ if (slash == NULL && path[0] != '\0' && path[1] == ':')
1454+ slash = path + 1;
1455+ }
1456+#endif
1457+
1458+ if (slash != (char *) NULL)
1459+ {
1460+ len = slash - path;
1461+ tmpname = (char *) xmalloc (len + sizeof (template) + 2);
1462+ memcpy (tmpname, path, len);
1463+
1464+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
1465+ /* If tmpname is "X:", appending a slash will make it a root
1466+ directory on drive X, which is NOT the same as the current
1467+ directory on drive X. */
1468+ if (len == 2 && tmpname[1] == ':')
1469+ tmpname[len++] = '.';
1470+#endif
1471+ tmpname[len++] = '/';
1472+ }
1473+ else
1474+ {
1475+ tmpname = (char *) xmalloc (sizeof (template));
1476+ len = 0;
1477+ }
1478+
1479+ memcpy (tmpname + len, template, sizeof (template));
1480+#undef template
1481+
1482+#ifdef HAVE_MKSTEMP
1483+ fd = mkstemp (tmpname);
1484+#else
1485+ tmpname = mktemp (tmpname);
1486+ if (tmpname == NULL)
1487+ return NULL;
1488+ fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
1489+#endif
1490+ if (fd == -1)
1491+ return NULL;
1492+ return bfd_fopen (tmpname, target, mode, fd);
1493+}
1494+
1495+/* Add the object-only section. */
1496+
1497+static void
1498+cmdline_add_object_only_section (bfd_byte *contents, size_t size)
1499+{
1500+ bfd_vma start;
1501+ flagword flags;
1502+ enum bfd_architecture iarch;
1503+ unsigned int imach;
1504+ long symcount;
1505+ long symsize;
1506+ asymbol **isympp = NULL;
1507+ asymbol **osympp = NULL;
1508+ bfd *obfd = NULL, *ibfd;
1509+ const char *err;
1510+ struct arg
1511+ {
1512+ bfd *obfd;
1513+ asymbol **isympp;
1514+ int status;
1515+ } arg;
1516+ char **matching;
1517+ const char *ofilename = NULL;
1518+ asection *sec;
1519+
1520+ ibfd = bfd_openr (output_filename, output_target);
1521+ if (!ibfd)
1522+ {
1523+ err = bfd_errmsg (bfd_get_error ());
1524+ goto loser;
1525+ }
1526+
1527+ if (!bfd_check_format_matches (ibfd, bfd_object, &matching))
1528+ {
1529+ err = bfd_errmsg (bfd_get_error ());
1530+ goto loser;
1531+ }
1532+
1533+ obfd = cmdline_fopen_temp (output_filename, output_target, "w");
1534+ if (!obfd)
1535+ {
1536+ err = bfd_errmsg (bfd_get_error ());
1537+ goto loser;
1538+ }
1539+ ofilename = bfd_get_filename (obfd);
1540+
1541+ if (!bfd_set_format (obfd, bfd_object))
1542+ {
1543+ err = bfd_errmsg (bfd_get_error ());
1544+ goto loser;
1545+ }
1546+
1547+ /* Copy the start address, flags and architecture of input file to
1548+ output file. */
1549+ flags = bfd_get_file_flags (ibfd);
1550+ start = bfd_get_start_address (ibfd);
1551+ iarch = bfd_get_arch (ibfd);
1552+ imach = bfd_get_mach (ibfd);
1553+ if (!bfd_set_start_address (obfd, start)
1554+ || !bfd_set_file_flags (obfd, flags)
1555+ || !bfd_set_arch_mach (obfd, iarch, imach))
1556+ {
1557+ err = bfd_errmsg (bfd_get_error ());
1558+ goto loser;
1559+ }
1560+
1561+ symsize = bfd_get_symtab_upper_bound (ibfd);
1562+ if (symsize < 0)
1563+ {
1564+ err = bfd_errmsg (bfd_get_error ());
1565+ goto loser;
1566+ }
1567+
1568+ isympp = (asymbol **) xmalloc (symsize);
1569+ symcount = bfd_canonicalize_symtab (ibfd, isympp);
1570+ if (symcount < 0)
1571+ {
1572+ err = bfd_errmsg (bfd_get_error ());
1573+ goto loser;
1574+ }
1575+
1576+ arg.obfd = obfd;
1577+ arg.isympp = isympp;
1578+ arg.status = 0;
1579+
1580+ /* BFD mandates that all output sections be created and sizes set before
1581+ any output is done. Thus, we traverse all sections multiple times. */
1582+ bfd_map_over_sections (ibfd, setup_section, &arg);
1583+
1584+ if (arg.status)
1585+ {
1586+ err = _("error setting up sections");
1587+ goto loser;
1588+ }
1589+
1590+ /* Allow the BFD backend to copy any private data it understands
1591+ from the input section to the output section. */
1592+ if (! bfd_copy_private_header_data (ibfd, obfd))
1593+ {
1594+ err = _("error copying private header data");
1595+ goto loser;
1596+ }
1597+
1598+ /* Create the object-only section. */
1599+ sec = bfd_make_section_with_flags (obfd,
1600+ GNU_OBJECT_ONLY_SECTION_NAME,
1601+ (SEC_HAS_CONTENTS
1602+ | SEC_READONLY
1603+ | SEC_DATA
1604+ | SEC_LINKER_CREATED));
1605+ if (sec == NULL)
1606+ {
1607+ err = _("can't create object-only section");
1608+ goto loser;
1609+ }
1610+
1611+ if (! bfd_set_section_size (obfd, sec, size))
1612+ {
1613+ err = _("can't set object-only section size");
1614+ goto loser;
1615+ }
1616+
1617+ if (ibfd->object_only_section)
1618+ {
1619+ /* Filter out the object-only section symbol. */
1620+ long src_count = 0, dst_count = 0;
1621+ asymbol **from, **to;
1622+
1623+ osympp = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
1624+ from = isympp;
1625+ to = osympp;
1626+ for (; src_count < symcount; src_count++)
1627+ {
1628+ asymbol *sym = from[src_count];
1629+ if (bfd_get_section (sym) != ibfd->object_only_section)
1630+ to[dst_count++] = sym;
1631+ }
1632+ to[dst_count] = NULL;
1633+ symcount = dst_count;
1634+ bfd_set_symtab (obfd, osympp, symcount);
1635+ }
1636+ else
1637+ bfd_set_symtab (obfd, isympp, symcount);
1638+
1639+ /* This has to happen after the symbol table has been set. */
1640+ bfd_map_over_sections (ibfd, copy_section, &arg);
1641+
1642+ if (arg.status)
1643+ {
1644+ err = _("error copying sections");
1645+ goto loser;
1646+ }
1647+
1648+ /* Copy the object-only section to the output. */
1649+ if (! bfd_set_section_contents (obfd, sec, contents, 0, size))
1650+ {
1651+ err = _("error adding object-only section");
1652+ goto loser;
1653+ }
1654+
1655+ /* Allow the BFD backend to copy any private data it understands
1656+ from the input BFD to the output BFD. This is done last to
1657+ permit the routine to look at the filtered symbol table, which is
1658+ important for the ECOFF code at least. */
1659+ if (! bfd_copy_private_bfd_data (ibfd, obfd))
1660+ {
1661+ err = _("error copying private BFD data");
1662+ goto loser;
1663+ }
1664+
1665+ if (!bfd_close (obfd))
1666+ {
1667+ unlink (ofilename);
1668+ einfo (_("%P%F: failed to finish output with object-only section\n"));
1669+ }
1670+
1671+ /* Must be freed after bfd_close (). */
1672+ free (isympp);
1673+ if (osympp)
1674+ free (osympp);
1675+
1676+ if (rename (ofilename, output_filename))
1677+ {
1678+ unlink (ofilename);
1679+ einfo (_("%P%F: failed to rename output with object-only section\n"));
1680+ }
1681+
1682+ return;
1683+
1684+loser:
1685+ if (isympp)
1686+ free (isympp);
1687+ if (osympp)
1688+ free (osympp);
1689+ if (obfd)
1690+ bfd_close (obfd);
1691+ if (ofilename)
1692+ unlink (ofilename);
1693+ einfo (_("%P%F: failed to add object-only section: %s\n"), err);
1694+}
1695+
1696+/* Emit the final output with object-only section. */
1697+
1698+void
1699+cmdline_emit_object_only_section (void)
1700+{
1701+ const char *saved_output_filename = output_filename;
1702+ int fd;
1703+ size_t size, off;
1704+ bfd_byte *contents;
1705+ struct stat st;
1706+
1707+ /* Get a temporary object-only file. */
1708+ output_filename = make_temp_file (".obj-only.o");
1709+
1710+ had_output_filename = FALSE;
1711+ link_info.input_bfds = NULL;
1712+ link_info.input_bfds_tail = &link_info.input_bfds;
1713+
1714+ lang_init (TRUE);
1715+
1716+ ld_parse_linker_script ();
1717+
1718+ /* Set up the object-only output. */
1719+ lang_final ();
1720+
1721+ /* Open the object-only file for output. */
1722+ lang_for_each_statement (ldlang_open_output);
1723+
1724+ ldemul_create_output_section_statements ();
1725+
1726+ if (!bfd_section_already_linked_table_init ())
1727+ einfo (_("%P%F: Failed to create hash table\n"));
1728+
1729+ /* Call cmdline_on_object_only_archive_list_p to check which member
1730+ should be loaded. */
1731+ input_flags.whole_archive = TRUE;
1732+
1733+ /* Set it to avoid adding more to cmdline lists. */
1734+ link_info.emitting_gnu_object_only = TRUE;
1735+
1736+ cmdline_get_object_only_input_files ();
1737+
1738+ open_input_bfds (statement_list.head, FALSE);
1739+
1740+ ldemul_after_open ();
1741+
1742+ bfd_section_already_linked_table_free ();
1743+
1744+ /* Make sure that we're not mixing architectures. We call this
1745+ after all the input files have been opened, but before we do any
1746+ other processing, so that any operations merge_private_bfd_data
1747+ does on the output file will be known during the rest of the
1748+ link. */
1749+ lang_check ();
1750+
1751+ /* Size up the common data. */
1752+ lang_common ();
1753+
1754+ /* Update wild statements. */
1755+ update_wild_statements (statement_list.head);
1756+
1757+ /* Run through the contours of the script and attach input sections
1758+ to the correct output sections. */
1759+ map_input_to_output_sections (statement_list.head, NULL, NULL);
1760+
1761+ /* Find any sections not attached explicitly and handle them. */
1762+ lang_place_orphans ();
1763+
1764+ /* Do anything special before sizing sections. This is where ELF
1765+ and other back-ends size dynamic sections. */
1766+ ldemul_before_allocation ();
1767+
1768+ /* Size up the sections. */
1769+ lang_size_sections (NULL, ! RELAXATION_ENABLED);
1770+
1771+ /* See if anything special should be done now we know how big
1772+ everything is. This is where relaxation is done. */
1773+ ldemul_after_allocation ();
1774+
1775+ ldemul_finish ();
1776+
1777+ /* Make sure that the section addresses make sense. */
1778+ if (command_line.check_section_addresses)
1779+ lang_check_section_addresses ();
1780+
1781+ lang_end ();
1782+
1783+ ldwrite ();
1784+
1785+ lang_finish ();
1786+
1787+ if (! bfd_close (link_info.output_bfd))
1788+ einfo (_("%P%F:%s: final close failed on object-only output: %E\n"),
1789+ output_filename);
1790+
1791+ /* Read in the object-only file. */
1792+ fd = open (output_filename, O_RDONLY | O_BINARY);
1793+ if (fd < 0)
1794+ {
1795+ bfd_set_error (bfd_error_system_call);
1796+ einfo (_("%P%F:%s: cannot open object-only output: %E"),
1797+ output_filename);
1798+ }
1799+
1800+ /* Get the object-only file size. */
1801+ if (fstat (fd, &st) != 0)
1802+ {
1803+ bfd_set_error (bfd_error_system_call);
1804+ einfo (_("%P%F:%s: cannot stat object-only output: %E"),
1805+ output_filename);
1806+ }
1807+
1808+ size = st.st_size;
1809+ off = 0;
1810+ contents = (bfd_byte *) xmalloc (size);
1811+ while (off != size)
1812+ {
1813+ ssize_t got;
1814+
1815+ got = read (fd, contents + off, size - off);
1816+ if (got < 0)
1817+ {
1818+ bfd_set_error (bfd_error_system_call);
1819+ einfo (_("%P%F:%s: read failed on object-only output: %E"),
1820+ output_filename);
1821+ }
1822+
1823+ off += got;
1824+ }
1825+
1826+ close (fd);
1827+
1828+ /* Remove the temporary object-only file. */
1829+ unlink (output_filename);
1830+
1831+ output_filename = saved_output_filename;
1832+
1833+ cmdline_add_object_only_section (contents, size);
1834+
1835+ free (contents);
1836+}
1837+
1838+/* Extract the object-only section. */
1839+
1840+static const char *
1841+cmdline_extract_object_only_section (bfd *abfd)
1842+{
1843+ const char *name = bfd_extract_object_only_section (abfd);
1844+
1845+ if (name == NULL)
1846+ einfo (_("%P%F: cannot extract object-only section from %B: %E"),
1847+ abfd);
1848+
1849+ /* It should be removed after it is done. */
1850+ cmdline_list_append (&cmdline_temp_object_only_list,
1851+ cmdline_is_file_enum, (void *) name);
1852+
1853+ return name;
1854+}
1855+
1856+/* Check and handle the object-only section. */
1857+
1858+void
1859+cmdline_check_object_only_section (bfd *abfd, bfd_boolean lto)
1860+{
1861+ const char *filename;
1862+
1863+ if (link_info.emitting_gnu_object_only
1864+ || abfd->format != bfd_object)
1865+ return;
1866+
1867+ if (lto)
1868+ {
1869+ /* For LTO link, we only need to extract object-only section
1870+ from the mixed object, add it to input, and put it on LTO
1871+ claimed output. */
1872+ switch (abfd->lto_type)
1873+ {
1874+ default:
1875+ abort ();
1876+ case lto_mixed_object:
1877+ filename = cmdline_extract_object_only_section (abfd);
1878+ lang_add_input_file (filename,
1879+ lang_input_file_is_file_enum, NULL);
1880+ break;
1881+ case lto_non_ir_object:
1882+ case lto_ir_object:
1883+ break;
1884+ }
1885+ }
1886+ else if (link_info.relocatable)
1887+ {
1888+ /* For non-LTO relocatable link, we need to append non-IR object
1889+ file and the object file in object-only section to the object
1890+ only list. */
1891+ switch (abfd->lto_type)
1892+ {
1893+ default:
1894+ abort ();
1895+ case lto_mixed_object:
1896+ filename = cmdline_extract_object_only_section (abfd);
1897+ cmdline_object_only_list_append (cmdline_is_file_enum,
1898+ (void *) filename);
1899+ break;
1900+ case lto_non_ir_object:
1901+ cmdline_object_only_list_append (cmdline_is_bfd_enum, abfd);
1902+ break;
1903+ case lto_ir_object:
1904+ break;
1905+ }
1906+ }
1907+}
1908+
1909+/* Remove temporary object-only files. */
1910+
1911+void
1912+cmdline_remove_object_only_files (void)
1913+{
1914+ cmdline_union_type *c;
1915+
1916+#ifdef ENABLE_PLUGINS
1917+ if (plugin_save_temps)
1918+ return;
1919+#endif
1920+
1921+ c = cmdline_temp_object_only_list.head;
1922+ for (; c != NULL; c = c->header.next)
1923+ switch (c->header.type)
1924+ {
1925+ default:
1926+ abort ();
1927+ case cmdline_is_file_enum:
1928+ unlink (c->file.filename);
1929+ break;
1930+ }
1931+}
1932+
1933+
1934+
1935Only in binutils-2.25/ld: ldlang.c.orig
1936Only in binutils-2.25/ld: ldlang.c.rej
1937diff -rup binutils-2.25.orig/ld/ldlang.h binutils-2.25/ld/ldlang.h
1938--- binutils-2.25.orig/ld/ldlang.h 2014-12-24 10:46:27.718434043 +0000
1939+++ binutils-2.25/ld/ldlang.h 2014-12-24 10:47:07.181655654 +0000
1940@@ -523,7 +523,7 @@ extern struct asneeded_minfo **asneeded_
1941 extern void (*output_bfd_hash_table_free_fn) (struct bfd_link_hash_table *);
1942
1943 extern void lang_init
1944- (void);
1945+ (bfd_boolean);
1946 extern void lang_finish
1947 (void);
1948 extern lang_memory_region_type * lang_memory_region_lookup
1949@@ -698,4 +698,45 @@ ldlang_override_segment_assignment
1950 extern void
1951 lang_ld_feature (char *);
1952
1953+typedef enum
1954+{
1955+ cmdline_is_file_enum,
1956+ cmdline_is_bfd_enum
1957+} cmdline_enum_type;
1958+
1959+typedef struct cmdline_header_struct
1960+{
1961+ union cmdline_union *next;
1962+ cmdline_enum_type type;
1963+} cmdline_header_type;
1964+
1965+typedef struct cmdline_file_struct
1966+{
1967+ cmdline_header_type header;
1968+ const char *filename;
1969+} cmdline_file_type;
1970+
1971+typedef struct cmdline_bfd_struct
1972+{
1973+ cmdline_header_type header;
1974+ bfd *abfd;
1975+} cmdline_bfd_type;
1976+
1977+typedef union cmdline_union
1978+{
1979+ cmdline_header_type header;
1980+ cmdline_file_type file;
1981+ cmdline_bfd_type abfd;
1982+} cmdline_union_type;
1983+
1984+typedef struct cmdline_list
1985+{
1986+ cmdline_union_type *head;
1987+ cmdline_union_type **tail;
1988+} cmdline_list_type;
1989+
1990+extern void cmdline_emit_object_only_section (void);
1991+extern void cmdline_check_object_only_section (bfd *, bfd_boolean);
1992+extern void cmdline_remove_object_only_files (void);
1993+
1994 #endif
1995Only in binutils-2.25/ld: ldlang.h.orig
1996diff -rup binutils-2.25.orig/ld/ldlex.h binutils-2.25/ld/ldlex.h
1997--- binutils-2.25.orig/ld/ldlex.h 2014-12-24 10:46:27.720434054 +0000
1998+++ binutils-2.25/ld/ldlex.h 2014-12-24 10:47:07.181655654 +0000
1999@@ -133,6 +133,7 @@ enum option_values
2000 #ifdef ENABLE_PLUGINS
2001 OPTION_PLUGIN,
2002 OPTION_PLUGIN_OPT,
2003+ OPTION_PLUGIN_SAVE_TEMPS,
2004 #endif /* ENABLE_PLUGINS */
2005 OPTION_DEFAULT_SCRIPT,
2006 OPTION_PRINT_OUTPUT_FORMAT,
2007diff -rup binutils-2.25.orig/ld/ldmain.c binutils-2.25/ld/ldmain.c
2008--- binutils-2.25.orig/ld/ldmain.c 2014-12-24 10:46:27.715434026 +0000
2009+++ binutils-2.25/ld/ldmain.c 2014-12-24 11:02:55.443006018 +0000
2010@@ -220,6 +220,9 @@ main (int argc, char **argv)
2011
2012 xatexit (ld_cleanup);
2013
2014+ /* Remove temporary object-only files. */
2015+ xatexit (cmdline_remove_object_only_files);
2016+
2017 /* Set up the sysroot directory. */
2018 ld_sysroot = get_sysroot (argc, argv);
2019 if (*ld_sysroot)
2020@@ -296,7 +299,7 @@ main (int argc, char **argv)
2021 default_target = ldemul_choose_target (argc, argv);
2022 config.maxpagesize = bfd_emul_get_maxpagesize (default_target);
2023 config.commonpagesize = bfd_emul_get_commonpagesize (default_target);
2024- lang_init ();
2025+ lang_init (FALSE);
2026 ldemul_before_parse ();
2027 lang_has_input_file = FALSE;
2028 parse_args (argc, argv);
2029@@ -311,34 +314,7 @@ main (int argc, char **argv)
2030
2031 ldemul_set_symbols ();
2032
2033- /* If we have not already opened and parsed a linker script,
2034- try the default script from command line first. */
2035- if (saved_script_handle == NULL
2036- && command_line.default_script != NULL)
2037- {
2038- ldfile_open_command_file (command_line.default_script);
2039- parser_input = input_script;
2040- yyparse ();
2041- }
2042-
2043- /* If we have not already opened and parsed a linker script
2044- read the emulation's appropriate default script. */
2045- if (saved_script_handle == NULL)
2046- {
2047- int isfile;
2048- char *s = ldemul_get_script (&isfile);
2049-
2050- if (isfile)
2051- ldfile_open_default_command_file (s);
2052- else
2053- {
2054- lex_string = s;
2055- lex_redirect (s, _("built in linker script"), 1);
2056- }
2057- parser_input = input_script;
2058- yyparse ();
2059- lex_string = NULL;
2060- }
2061+ ld_parse_linker_script ();
2062
2063 if (verbose)
2064 {
2065@@ -459,6 +435,8 @@ main (int argc, char **argv)
2066 if (! bfd_close (link_info.output_bfd))
2067 einfo (_("%F%B: final close failed: %E\n"), link_info.output_bfd);
2068
2069+ link_info.output_bfd = NULL;
2070+
2071 /* If the --force-exe-suffix is enabled, and we're making an
2072 executable file and it doesn't end in .exe, copy it to one
2073 which does. */
2074@@ -505,6 +483,9 @@ main (int argc, char **argv)
2075 }
2076 }
2077
2078+ if (link_info.emit_gnu_object_only)
2079+ cmdline_emit_object_only_section ();
2080+
2081 END_PROGRESS (program_name);
2082
2083 if (config.stats)
2084@@ -814,7 +795,9 @@ add_archive_element (struct bfd_link_inf
2085 }
2086 }
2087 }
2088+ else
2089 #endif /* ENABLE_PLUGINS */
2090+ cmdline_check_object_only_section (input->the_bfd, FALSE);
2091
2092 ldlang_add_file (input);
2093
2094@@ -1207,7 +1190,8 @@ warning_callback (struct bfd_link_info *
2095 einfo ("%P: %s%s\n", _("warning: "), warning);
2096 else if (symbol == NULL)
2097 einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
2098- else if (! symbol_warning (warning, symbol, abfd))
2099+ else if (((abfd->flags & BFD_PLUGIN) == 0)
2100+ && ! symbol_warning (warning, symbol, abfd))
2101 {
2102 bfd *b;
2103 /* Search all input files for a reference to SYMBOL. */
2104@@ -1493,3 +1477,38 @@ notice (struct bfd_link_info *info,
2105
2106 return TRUE;
2107 }
2108+
2109+/* Parse the linker script. */
2110+
2111+void
2112+ld_parse_linker_script ()
2113+{
2114+ /* If we have not already opened and parsed a linker script,
2115+ try the default script from command line first. */
2116+ if (saved_script_handle == NULL
2117+ && command_line.default_script != NULL)
2118+ {
2119+ ldfile_open_command_file (command_line.default_script);
2120+ parser_input = input_script;
2121+ yyparse ();
2122+ }
2123+
2124+ /* If we have not already opened and parsed a linker script
2125+ read the emulation's appropriate default script. */
2126+ if (saved_script_handle == NULL)
2127+ {
2128+ int isfile;
2129+ char *s = ldemul_get_script (&isfile);
2130+
2131+ if (isfile)
2132+ ldfile_open_default_command_file (s);
2133+ else
2134+ {
2135+ lex_string = s;
2136+ lex_redirect (s, _("built in linker script"), 1);
2137+ }
2138+ parser_input = input_script;
2139+ yyparse ();
2140+ lex_string = NULL;
2141+ }
2142+}
2143Only in binutils-2.25/ld: ldmain.c.orig
2144Only in binutils-2.25/ld: ldmain.c.rej
2145diff -rup binutils-2.25.orig/ld/ldmain.h binutils-2.25/ld/ldmain.h
2146--- binutils-2.25.orig/ld/ldmain.h 2014-12-24 10:46:27.715434026 +0000
2147+++ binutils-2.25/ld/ldmain.h 2014-12-24 10:47:07.183655665 +0000
2148@@ -59,4 +59,6 @@ extern void add_wrap (const char *);
2149 extern void add_ignoresym (struct bfd_link_info *, const char *);
2150 extern void add_keepsyms_file (const char *);
2151
2152+extern void ld_parse_linker_script (void);
2153+
2154 #endif
2155Only in binutils-2.25/ld: ldmain.h.orig
2156diff -rup binutils-2.25.orig/ld/lexsup.c binutils-2.25/ld/lexsup.c
2157--- binutils-2.25.orig/ld/lexsup.c 2014-12-24 10:46:27.870434896 +0000
2158+++ binutils-2.25/ld/lexsup.c 2014-12-24 10:47:07.184655671 +0000
2159@@ -166,6 +166,9 @@ static const struct ld_option ld_options
2160 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
2161 { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
2162 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
2163+ { {"plugin-save-temps", no_argument, NULL, OPTION_PLUGIN_SAVE_TEMPS},
2164+ '\0', NULL, N_("Store plugin intermediate files permanently"),
2165+ ONE_DASH },
2166 { {"flto", optional_argument, NULL, OPTION_IGNORE},
2167 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
2168 ONE_DASH },
2169@@ -978,6 +981,9 @@ parse_args (unsigned argc, char **argv)
2170 if (plugin_opt_plugin_arg (optarg))
2171 einfo(_("%P%F: bad -plugin-opt option\n"));
2172 break;
2173+ case OPTION_PLUGIN_SAVE_TEMPS:
2174+ plugin_save_temps = TRUE;
2175+ break;
2176 #endif /* ENABLE_PLUGINS */
2177 case 'q':
2178 link_info.emitrelocations = TRUE;
2179Only in binutils-2.25/ld: lexsup.c.orig
2180diff -rup binutils-2.25.orig/ld/plugin.c binutils-2.25/ld/plugin.c
2181--- binutils-2.25.orig/ld/plugin.c 2014-12-24 10:46:27.719434048 +0000
2182+++ binutils-2.25/ld/plugin.c 2014-12-24 10:47:07.185655677 +0000
2183@@ -39,6 +39,9 @@
2184 /* Report plugin symbols. */
2185 bfd_boolean report_plugin_symbols;
2186
2187+/* Store plugin intermediate files permanently. */
2188+bfd_boolean plugin_save_temps;
2189+
2190 /* The suffix to append to the name of the real (claimed) object file
2191 when generating a dummy BFD to hold the IR symbols sent from the
2192 plugin. For cosmetic use only; appears in maps, crefs etc. */
2193@@ -229,6 +232,17 @@ plugin_opt_plugin_arg (const char *arg)
2194 return 0;
2195 }
2196
2197+ /* Ignore -pass-through= from GCC driver. */
2198+ if (*arg == '-')
2199+ {
2200+ const char *p;
2201+ for (p = arg + 1; p; p++)
2202+ if (*p != '-')
2203+ break;
2204+ if (strncmp (p, "pass-through=", 13) == 0)
2205+ return 0;
2206+ }
2207+
2208 newarg = xmalloc (sizeof *newarg);
2209 newarg->arg = arg;
2210 newarg->next = NULL;
2211@@ -882,6 +896,9 @@ plugin_maybe_claim (struct ld_plugin_inp
2212 close (file->fd);
2213 if (claimed)
2214 {
2215+ /* Check object only section. */
2216+ cmdline_check_object_only_section (entry->the_bfd, TRUE);
2217+
2218 /* Discard the real file's BFD and substitute the dummy one. */
2219
2220 /* BFD archive handling caches elements so we can't call
2221@@ -935,14 +952,17 @@ plugin_call_cleanup (void)
2222 {
2223 if (curplug->cleanup_handler && !curplug->cleanup_done)
2224 {
2225- enum ld_plugin_status rv;
2226- curplug->cleanup_done = TRUE;
2227- called_plugin = curplug;
2228- rv = (*curplug->cleanup_handler) ();
2229- called_plugin = NULL;
2230- if (rv != LDPS_OK)
2231- info_msg (_("%P: %s: error in plugin cleanup: %d (ignored)\n"),
2232- curplug->name, rv);
2233+ if (!plugin_save_temps)
2234+ {
2235+ enum ld_plugin_status rv;
2236+ curplug->cleanup_done = TRUE;
2237+ called_plugin = curplug;
2238+ rv = (*curplug->cleanup_handler) ();
2239+ called_plugin = NULL;
2240+ if (rv != LDPS_OK)
2241+ info_msg (_("%P: %s: error in plugin cleanup: %d (ignored)\n"),
2242+ curplug->name, rv);
2243+ }
2244 dlclose (curplug->dlhandle);
2245 }
2246 curplug = curplug->next;
2247Only in binutils-2.25/ld: plugin.c.orig
2248diff -rup binutils-2.25.orig/ld/plugin.h binutils-2.25/ld/plugin.h
2249--- binutils-2.25.orig/ld/plugin.h 2014-12-24 10:46:27.718434043 +0000
2250+++ binutils-2.25/ld/plugin.h 2014-12-24 10:47:07.185655677 +0000
2251@@ -24,6 +24,9 @@
2252 /* Report plugin symbols. */
2253 extern bfd_boolean report_plugin_symbols;
2254
2255+/* Store plugin intermediate files permanently. */
2256+extern bfd_boolean plugin_save_temps;
2257+
2258 /* Set at all symbols read time, to avoid recursively offering the plugin
2259 its own newly-added input files and libs to claim. */
2260 extern bfd_boolean no_more_claiming;
2261diff -rup binutils-2.25.orig/ld/scripttempl/armbpabi.sc binutils-2.25/ld/scripttempl/armbpabi.sc
2262--- binutils-2.25.orig/ld/scripttempl/armbpabi.sc 2014-12-24 10:46:27.709433992 +0000
2263+++ binutils-2.25/ld/scripttempl/armbpabi.sc 2014-12-24 10:47:07.400656884 +0000
2264@@ -36,7 +36,7 @@ INTERP=".interp 0 : { *(.interp) }
2265 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
2266 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
2267 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro .data.rel.ro.*) }"
2268-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
2269+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
2270 if test -z "${NO_SMALL_DATA}"; then
2271 SBSS=".sbss ${RELOCATING-0} :
2272 {
2273Only in binutils-2.25/ld/scripttempl: armbpabi.sc.orig
2274diff -rup binutils-2.25.orig/ld/scripttempl/elf32sh-symbian.sc binutils-2.25/ld/scripttempl/elf32sh-symbian.sc
2275--- binutils-2.25.orig/ld/scripttempl/elf32sh-symbian.sc 2014-12-24 10:46:27.709433992 +0000
2276+++ binutils-2.25/ld/scripttempl/elf32sh-symbian.sc 2014-12-24 10:47:07.401656890 +0000
2277@@ -88,7 +88,7 @@ fi
2278 PLT=".plt : { *(.plt) } :dynamic :dyn"
2279 DYNAMIC=".dynamic : { *(.dynamic) } :dynamic :dyn"
2280 RODATA=".rodata ALIGN(4) : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
2281-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.directive) *(.gnu.lto_*) }"
2282+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.directive) *(.gnu.lto_*) *(.gnu_object_only) }"
2283 test -z "$GOT" && GOT=".got ${RELOCATING-0} : { *(.got.plt) *(.got) } :dynamic :dyn"
2284 INIT_ARRAY=".init_array ${RELOCATING-0} :
2285 {
2286Only in binutils-2.25/ld/scripttempl: elf32sh-symbian.sc.orig
2287diff -rup binutils-2.25.orig/ld/scripttempl/elf64hppa.sc binutils-2.25/ld/scripttempl/elf64hppa.sc
2288--- binutils-2.25.orig/ld/scripttempl/elf64hppa.sc 2014-12-24 10:46:27.711434003 +0000
2289+++ binutils-2.25/ld/scripttempl/elf64hppa.sc 2014-12-24 10:47:07.401656890 +0000
2290@@ -132,7 +132,7 @@ fi
2291 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
2292 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
2293 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
2294-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
2295+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
2296 if test -z "${NO_SMALL_DATA}"; then
2297 SBSS=".sbss ${RELOCATING-0} :
2298 {
2299Only in binutils-2.25/ld/scripttempl: elf64hppa.sc.orig
2300diff -rup binutils-2.25.orig/ld/scripttempl/elf.sc binutils-2.25/ld/scripttempl/elf.sc
2301--- binutils-2.25.orig/ld/scripttempl/elf.sc 2014-12-24 10:46:27.709433992 +0000
2302+++ binutils-2.25/ld/scripttempl/elf.sc 2014-12-24 10:47:07.402656895 +0000
2303@@ -165,7 +165,7 @@ RELA_IPLT=".rela.iplt ${RELOCATING-0}
2304 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
2305 RODATA=".${RODATA_NAME} ${RELOCATING-0} : { *(.${RODATA_NAME}${RELOCATING+ .${RODATA_NAME}.* .gnu.linkonce.r.*}) }"
2306 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
2307-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
2308+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
2309 if test -z "${NO_SMALL_DATA}"; then
2310 SBSS=".${SBSS_NAME} ${RELOCATING-0} :
2311 {
2312Only in binutils-2.25/ld/scripttempl: elf.sc.orig
2313diff -rup binutils-2.25.orig/ld/scripttempl/elfxtensa.sc binutils-2.25/ld/scripttempl/elfxtensa.sc
2314--- binutils-2.25.orig/ld/scripttempl/elfxtensa.sc 2014-12-24 10:46:27.710433998 +0000
2315+++ binutils-2.25/ld/scripttempl/elfxtensa.sc 2014-12-24 10:47:07.402656895 +0000
2316@@ -145,7 +145,7 @@ fi
2317 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
2318 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
2319 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
2320-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
2321+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
2322 INIT_LIT=".init.literal 0 : { *(.init.literal) }"
2323 INIT=".init 0 : { *(.init) }"
2324 FINI_LIT=".fini.literal 0 : { *(.fini.literal) }"
2325Only in binutils-2.25/ld/scripttempl: elfxtensa.sc.orig
2326diff -rup binutils-2.25.orig/ld/scripttempl/mep.sc binutils-2.25/ld/scripttempl/mep.sc
2327--- binutils-2.25.orig/ld/scripttempl/mep.sc 2014-12-24 10:46:27.711434003 +0000
2328+++ binutils-2.25/ld/scripttempl/mep.sc 2014-12-24 10:47:07.403656901 +0000
2329@@ -119,7 +119,7 @@ fi
2330 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
2331 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
2332 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro .data.rel.ro.*) }"
2333-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
2334+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
2335 if test -z "${NO_SMALL_DATA}"; then
2336 SBSS=".sbss ${RELOCATING-0} :
2337 {
2338Only in binutils-2.25/ld/scripttempl: mep.sc.orig
2339diff -rup binutils-2.25.orig/ld/scripttempl/pep.sc binutils-2.25/ld/scripttempl/pep.sc
2340--- binutils-2.25.orig/ld/scripttempl/pep.sc 2014-12-24 10:46:27.709433992 +0000
2341+++ binutils-2.25/ld/scripttempl/pep.sc 2014-12-24 10:47:07.403656901 +0000
2342@@ -170,6 +170,7 @@ SECTIONS
2343 *(.drectve)
2344 ${RELOCATING+ *(.note.GNU-stack)}
2345 ${RELOCATING+ *(.gnu.lto_*)}
2346+ ${RELOCATING+ *(.gnu_object_only)}
2347 }
2348
2349 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
2350Only in binutils-2.25/ld/scripttempl: pep.sc.orig
2351diff -rup binutils-2.25.orig/ld/scripttempl/pe.sc binutils-2.25/ld/scripttempl/pe.sc
2352--- binutils-2.25.orig/ld/scripttempl/pe.sc 2014-12-24 10:46:27.711434003 +0000
2353+++ binutils-2.25/ld/scripttempl/pe.sc 2014-12-24 10:47:07.404656906 +0000
2354@@ -165,6 +165,7 @@ SECTIONS
2355 *(.drectve)
2356 ${RELOCATING+ *(.note.GNU-stack)}
2357 ${RELOCATING+ *(.gnu.lto_*)}
2358+ ${RELOCATING+ *(.gnu_object_only)}
2359 }
2360
2361 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
2362Only in binutils-2.25/ld/scripttempl: pe.sc.orig
This page took 0.440834 seconds and 4 git commands to generate.