GNU Binutils with patches for OS216
Revision | 4cbe42ea236bce32da4262f6f12328b58bac8f0f (tree) |
---|---|
Zeit | 2016-04-22 21:25:25 |
Autor | H.J. Lu <hjl.tools@gmai...> |
Commiter | H.J. Lu |
Add a fake bfd to hold linker created dynamic sections
Currently, we hold linker created dynamic sections in an input shared
object, which has its own dynamic sections, when the first input file
from linker is a shared object. It may lead to conflicts between
linker created dynamic sections and shared object's dynamic sections.
We can use a a fake bfd to hold linker created dynamic sections.
Unfortunately, it doesn't work due to BFD_LINKER_CREATED. Dynamic
sections in bfd with BFD_LINKER_CREATED may be ignored.
@@ -198,31 +198,11 @@ _bfd_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) | ||
198 | 198 | |
199 | 199 | /* Create a strtab to hold the dynamic symbol names. */ |
200 | 200 | static bfd_boolean |
201 | -_bfd_elf_link_create_dynstrtab (bfd *abfd, struct bfd_link_info *info) | |
201 | +_bfd_elf_link_create_dynstrtab (struct bfd_link_info *info) | |
202 | 202 | { |
203 | 203 | struct elf_link_hash_table *hash_table; |
204 | 204 | |
205 | 205 | hash_table = elf_hash_table (info); |
206 | - if (hash_table->dynobj == NULL) | |
207 | - { | |
208 | - /* We may not set dynobj, an input file holding linker created | |
209 | - dynamic sections to abfd, which may be a dynamic object with | |
210 | - its own dynamic sections. We need to find a normal input file | |
211 | - to hold linker created sections if possible. */ | |
212 | - if ((abfd->flags & (DYNAMIC | BFD_PLUGIN)) != 0) | |
213 | - { | |
214 | - bfd *ibfd; | |
215 | - for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next) | |
216 | - if ((ibfd->flags | |
217 | - & (DYNAMIC | BFD_LINKER_CREATED | BFD_PLUGIN)) == 0) | |
218 | - { | |
219 | - abfd = ibfd; | |
220 | - break; | |
221 | - } | |
222 | - } | |
223 | - hash_table->dynobj = abfd; | |
224 | - } | |
225 | - | |
226 | 206 | if (hash_table->dynstr == NULL) |
227 | 207 | { |
228 | 208 | hash_table->dynstr = _bfd_elf_strtab_init (); |
@@ -253,7 +233,7 @@ _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | ||
253 | 233 | if (elf_hash_table (info)->dynamic_sections_created) |
254 | 234 | return TRUE; |
255 | 235 | |
256 | - if (!_bfd_elf_link_create_dynstrtab (abfd, info)) | |
236 | + if (!_bfd_elf_link_create_dynstrtab (info)) | |
257 | 237 | return FALSE; |
258 | 238 | |
259 | 239 | abfd = elf_hash_table (info)->dynobj; |
@@ -3206,15 +3186,14 @@ _bfd_elf_add_dynamic_entry (struct bfd_link_info *info, | ||
3206 | 3186 | 1 if a DT_NEEDED tag already exists, and 0 on success. */ |
3207 | 3187 | |
3208 | 3188 | static int |
3209 | -elf_add_dt_needed_tag (bfd *abfd, | |
3210 | - struct bfd_link_info *info, | |
3189 | +elf_add_dt_needed_tag (struct bfd_link_info *info, | |
3211 | 3190 | const char *soname, |
3212 | 3191 | bfd_boolean do_it) |
3213 | 3192 | { |
3214 | 3193 | struct elf_link_hash_table *hash_table; |
3215 | 3194 | bfd_size_type strindex; |
3216 | 3195 | |
3217 | - if (!_bfd_elf_link_create_dynstrtab (abfd, info)) | |
3196 | + if (!_bfd_elf_link_create_dynstrtab (info)) | |
3218 | 3197 | return -1; |
3219 | 3198 | |
3220 | 3199 | hash_table = elf_hash_table (info); |
@@ -3908,7 +3887,7 @@ error_free_dyn: | ||
3908 | 3887 | will need to know it. */ |
3909 | 3888 | elf_dt_name (abfd) = soname; |
3910 | 3889 | |
3911 | - ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed); | |
3890 | + ret = elf_add_dt_needed_tag (info, soname, add_needed); | |
3912 | 3891 | if (ret < 0) |
3913 | 3892 | goto error_return; |
3914 | 3893 |
@@ -4717,7 +4696,7 @@ error_free_dyn: | ||
4717 | 4696 | (elf_dyn_lib_class (abfd) & ~DYN_AS_NEEDED); |
4718 | 4697 | |
4719 | 4698 | add_needed = TRUE; |
4720 | - ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed); | |
4699 | + ret = elf_add_dt_needed_tag (info, soname, add_needed); | |
4721 | 4700 | if (ret < 0) |
4722 | 4701 | goto error_free_vers; |
4723 | 4702 |
@@ -322,6 +322,8 @@ aarch64_elf_create_output_section_statements (void) | ||
322 | 322 | |
323 | 323 | stub_file->the_bfd->flags |= BFD_LINKER_CREATED; |
324 | 324 | ldlang_add_file (stub_file); |
325 | + | |
326 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
325 | 327 | } |
326 | 328 | |
327 | 329 | /* Avoid processing the fake stub_file in vercheck, stat_needed and |
@@ -514,6 +514,8 @@ arm_elf_create_output_section_statements (void) | ||
514 | 514 | /* Also use the stub file for stubs placed in a single output section. */ |
515 | 515 | bfd_elf32_arm_add_glue_sections_to_bfd (stub_file->the_bfd, &link_info); |
516 | 516 | bfd_elf32_arm_get_bfd_for_interworking (stub_file->the_bfd, &link_info); |
517 | + | |
518 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
517 | 519 | } |
518 | 520 | |
519 | 521 | /* Avoid processing the fake stub_file in vercheck, stat_needed and |
@@ -136,6 +136,7 @@ avr_elf_create_output_section_statements (void) | ||
136 | 136 | |
137 | 137 | ldlang_add_file (stub_file); |
138 | 138 | |
139 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
139 | 140 | return; |
140 | 141 | |
141 | 142 | err_ret: |
@@ -64,6 +64,7 @@ static void gld${EMULATION_NAME}_after_parse (void); | ||
64 | 64 | static void gld${EMULATION_NAME}_after_open (void); |
65 | 65 | static void gld${EMULATION_NAME}_before_allocation (void); |
66 | 66 | static void gld${EMULATION_NAME}_after_allocation (void); |
67 | +static void gld${EMULATION_NAME}_create_output_section_statements (void); | |
67 | 68 | static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan |
68 | 69 | (asection *, const char *, int); |
69 | 70 | EOF |
@@ -263,6 +264,8 @@ gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s) | ||
263 | 264 | return; |
264 | 265 | if (s->the_bfd == NULL) |
265 | 266 | return; |
267 | + if ((s->the_bfd->flags & BFD_LINKER_CREATED) != 0) | |
268 | + return; | |
266 | 269 | |
267 | 270 | /* If this input file was an as-needed entry, and wasn't found to be |
268 | 271 | needed at the stage it was linked, then don't say we have loaded it. */ |
@@ -1400,6 +1403,46 @@ gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s) | ||
1400 | 1403 | |
1401 | 1404 | EOF |
1402 | 1405 | |
1406 | +if test x"$LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS" != xgld"$EMULATION_NAME"create_output_section_statements; then | |
1407 | +fragment <<EOF | |
1408 | + | |
1409 | +/* Fake input file for dynamic sections. */ | |
1410 | +static lang_input_statement_type *dynobj; | |
1411 | + | |
1412 | +/* This is called before the input files are opened. We create a new | |
1413 | + fake input file to hold the dynamic sections. */ | |
1414 | + | |
1415 | +static void | |
1416 | +gld${EMULATION_NAME}_create_output_section_statements (void) | |
1417 | +{ | |
1418 | + if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour) | |
1419 | + return; | |
1420 | + | |
1421 | + dynobj = lang_add_input_file (" dynobj ", | |
1422 | + lang_input_file_is_fake_enum, | |
1423 | + NULL); | |
1424 | + dynobj->the_bfd = bfd_create (" dynobj ", link_info.output_bfd); | |
1425 | + if (dynobj->the_bfd == NULL | |
1426 | + || !bfd_set_arch_mach (dynobj->the_bfd, | |
1427 | + bfd_get_arch (link_info.output_bfd), | |
1428 | + bfd_get_mach (link_info.output_bfd))) | |
1429 | + { | |
1430 | + einfo ("%F%P: can not create BFD to hold dynamic sections: %E\n"); | |
1431 | + return; | |
1432 | + } | |
1433 | + | |
1434 | + dynobj->the_bfd->flags |= BFD_LINKER_CREATED; | |
1435 | + elf_elfheader (dynobj->the_bfd)->e_ident[EI_CLASS] | |
1436 | + = (get_elf_backend_data (link_info.output_bfd)->s->arch_size == 64 | |
1437 | + ? ELFCLASS64 : ELFCLASS32); | |
1438 | + elf_hash_table (&link_info)->dynobj = dynobj->the_bfd; | |
1439 | + | |
1440 | + ldlang_add_file (dynobj); | |
1441 | +} | |
1442 | + | |
1443 | +EOF | |
1444 | +fi | |
1445 | + | |
1403 | 1446 | if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then |
1404 | 1447 | if test x"${ELF_INTERPRETER_NAME+set}" = xset; then |
1405 | 1448 | ELF_INTERPRETER_SET_DEFAULT=" |
@@ -2515,7 +2558,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = | ||
2515 | 2558 | "${EMULATION_NAME}", |
2516 | 2559 | "${OUTPUT_FORMAT}", |
2517 | 2560 | ${LDEMUL_FINISH-finish_default}, |
2518 | - ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL}, | |
2561 | + ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-gld${EMULATION_NAME}_create_output_section_statements}, | |
2519 | 2562 | ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive}, |
2520 | 2563 | ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan}, |
2521 | 2564 | ${LDEMUL_SET_SYMBOLS-NULL}, |
@@ -88,6 +88,8 @@ hppaelf_create_output_section_statements (void) | ||
88 | 88 | |
89 | 89 | stub_file->the_bfd->flags |= BFD_LINKER_CREATED; |
90 | 90 | ldlang_add_file (stub_file); |
91 | + | |
92 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
91 | 93 | } |
92 | 94 | |
93 | 95 |
@@ -155,6 +155,8 @@ m68hc11elf_create_output_section_statements (void) | ||
155 | 155 | } |
156 | 156 | |
157 | 157 | ldlang_add_file (stub_file); |
158 | + | |
159 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
158 | 160 | } |
159 | 161 | |
160 | 162 |
@@ -208,6 +208,8 @@ static void | ||
208 | 208 | elf_m68k_create_output_section_statements (void) |
209 | 209 | { |
210 | 210 | bfd_elf_m68k_set_target_options (&link_info, got_handling); |
211 | + | |
212 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
211 | 213 | } |
212 | 214 | |
213 | 215 | EOF |
@@ -65,6 +65,8 @@ metagelf_create_output_section_statements (void) | ||
65 | 65 | |
66 | 66 | stub_file->the_bfd->flags |= BFD_LINKER_CREATED; |
67 | 67 | ldlang_add_file (stub_file); |
68 | + | |
69 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
68 | 70 | } |
69 | 71 | |
70 | 72 |
@@ -206,6 +206,8 @@ mips_create_output_section_statements (void) | ||
206 | 206 | |
207 | 207 | if (is_mips_elf (link_info.output_bfd)) |
208 | 208 | _bfd_mips_elf_init_stubs (&link_info, mips_add_stub_section); |
209 | + | |
210 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
209 | 211 | } |
210 | 212 | |
211 | 213 | /* This is called after we have merged the private data of the input bfds. */ |
@@ -65,6 +65,8 @@ nds32_elf_create_output_section_statements (void) | ||
65 | 65 | ex9_export_file, ex9_import_file, |
66 | 66 | update_ex9_table, ex9_limit, |
67 | 67 | ex9_loop_aware, ifc_loop_aware); |
68 | + | |
69 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
68 | 70 | } |
69 | 71 | |
70 | 72 | static void |
@@ -70,6 +70,8 @@ nios2elf_create_output_section_statements (void) | ||
70 | 70 | |
71 | 71 | stub_file->the_bfd->flags |= BFD_LINKER_CREATED; |
72 | 72 | ldlang_add_file (stub_file); |
73 | + | |
74 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
73 | 75 | } |
74 | 76 | |
75 | 77 |
@@ -53,6 +53,8 @@ ppc_after_open_output (void) | ||
53 | 53 | pagesize = config.commonpagesize; |
54 | 54 | params.pagesize_p2 = bfd_log2 (pagesize); |
55 | 55 | ppc_elf_link_params (&link_info, ¶ms); |
56 | + | |
57 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
56 | 58 | } |
57 | 59 | |
58 | 60 | EOF |
@@ -98,6 +98,8 @@ ppc_create_output_section_statements (void) | ||
98 | 98 | params.save_restore_funcs = !bfd_link_relocatable (&link_info); |
99 | 99 | if (!ppc64_elf_init_stub_bfd (&link_info, ¶ms)) |
100 | 100 | einfo ("%F%P: can not init BFD: %E\n"); |
101 | + | |
102 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
101 | 103 | } |
102 | 104 | |
103 | 105 | /* Called after opening files but before mapping sections. */ |
@@ -38,6 +38,8 @@ rx_elf_create_output_section_statements (void) | ||
38 | 38 | extern void bfd_elf32_rx_set_target_flags (bfd_boolean, bfd_boolean); |
39 | 39 | |
40 | 40 | bfd_elf32_rx_set_target_flags (no_flag_mismatch_warnings, ignore_lma); |
41 | + | |
42 | + gld${EMULATION_NAME}_create_output_section_statements (); | |
41 | 43 | } |
42 | 44 | |
43 | 45 | EOF |