• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revision4cbe42ea236bce32da4262f6f12328b58bac8f0f (tree)
Zeit2016-04-22 21:25:25
AutorH.J. Lu <hjl.tools@gmai...>
CommiterH.J. Lu

Log Message

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.

Ändern Zusammenfassung

Diff

--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -198,31 +198,11 @@ _bfd_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
198198
199199 /* Create a strtab to hold the dynamic symbol names. */
200200 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)
202202 {
203203 struct elf_link_hash_table *hash_table;
204204
205205 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-
226206 if (hash_table->dynstr == NULL)
227207 {
228208 hash_table->dynstr = _bfd_elf_strtab_init ();
@@ -253,7 +233,7 @@ _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
253233 if (elf_hash_table (info)->dynamic_sections_created)
254234 return TRUE;
255235
256- if (!_bfd_elf_link_create_dynstrtab (abfd, info))
236+ if (!_bfd_elf_link_create_dynstrtab (info))
257237 return FALSE;
258238
259239 abfd = elf_hash_table (info)->dynobj;
@@ -3206,15 +3186,14 @@ _bfd_elf_add_dynamic_entry (struct bfd_link_info *info,
32063186 1 if a DT_NEEDED tag already exists, and 0 on success. */
32073187
32083188 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,
32113190 const char *soname,
32123191 bfd_boolean do_it)
32133192 {
32143193 struct elf_link_hash_table *hash_table;
32153194 bfd_size_type strindex;
32163195
3217- if (!_bfd_elf_link_create_dynstrtab (abfd, info))
3196+ if (!_bfd_elf_link_create_dynstrtab (info))
32183197 return -1;
32193198
32203199 hash_table = elf_hash_table (info);
@@ -3908,7 +3887,7 @@ error_free_dyn:
39083887 will need to know it. */
39093888 elf_dt_name (abfd) = soname;
39103889
3911- ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed);
3890+ ret = elf_add_dt_needed_tag (info, soname, add_needed);
39123891 if (ret < 0)
39133892 goto error_return;
39143893
@@ -4717,7 +4696,7 @@ error_free_dyn:
47174696 (elf_dyn_lib_class (abfd) & ~DYN_AS_NEEDED);
47184697
47194698 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);
47214700 if (ret < 0)
47224701 goto error_free_vers;
47234702
--- a/ld/emultempl/aarch64elf.em
+++ b/ld/emultempl/aarch64elf.em
@@ -322,6 +322,8 @@ aarch64_elf_create_output_section_statements (void)
322322
323323 stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
324324 ldlang_add_file (stub_file);
325+
326+ gld${EMULATION_NAME}_create_output_section_statements ();
325327 }
326328
327329 /* Avoid processing the fake stub_file in vercheck, stat_needed and
--- a/ld/emultempl/armelf.em
+++ b/ld/emultempl/armelf.em
@@ -514,6 +514,8 @@ arm_elf_create_output_section_statements (void)
514514 /* Also use the stub file for stubs placed in a single output section. */
515515 bfd_elf32_arm_add_glue_sections_to_bfd (stub_file->the_bfd, &link_info);
516516 bfd_elf32_arm_get_bfd_for_interworking (stub_file->the_bfd, &link_info);
517+
518+ gld${EMULATION_NAME}_create_output_section_statements ();
517519 }
518520
519521 /* Avoid processing the fake stub_file in vercheck, stat_needed and
--- a/ld/emultempl/avrelf.em
+++ b/ld/emultempl/avrelf.em
@@ -136,6 +136,7 @@ avr_elf_create_output_section_statements (void)
136136
137137 ldlang_add_file (stub_file);
138138
139+ gld${EMULATION_NAME}_create_output_section_statements ();
139140 return;
140141
141142 err_ret:
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -64,6 +64,7 @@ static void gld${EMULATION_NAME}_after_parse (void);
6464 static void gld${EMULATION_NAME}_after_open (void);
6565 static void gld${EMULATION_NAME}_before_allocation (void);
6666 static void gld${EMULATION_NAME}_after_allocation (void);
67+static void gld${EMULATION_NAME}_create_output_section_statements (void);
6768 static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan
6869 (asection *, const char *, int);
6970 EOF
@@ -263,6 +264,8 @@ gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
263264 return;
264265 if (s->the_bfd == NULL)
265266 return;
267+ if ((s->the_bfd->flags & BFD_LINKER_CREATED) != 0)
268+ return;
266269
267270 /* If this input file was an as-needed entry, and wasn't found to be
268271 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)
14001403
14011404 EOF
14021405
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+
14031446 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
14041447 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
14051448 ELF_INTERPRETER_SET_DEFAULT="
@@ -2515,7 +2558,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
25152558 "${EMULATION_NAME}",
25162559 "${OUTPUT_FORMAT}",
25172560 ${LDEMUL_FINISH-finish_default},
2518- ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2561+ ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-gld${EMULATION_NAME}_create_output_section_statements},
25192562 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
25202563 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
25212564 ${LDEMUL_SET_SYMBOLS-NULL},
--- a/ld/emultempl/hppaelf.em
+++ b/ld/emultempl/hppaelf.em
@@ -88,6 +88,8 @@ hppaelf_create_output_section_statements (void)
8888
8989 stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
9090 ldlang_add_file (stub_file);
91+
92+ gld${EMULATION_NAME}_create_output_section_statements ();
9193 }
9294
9395
--- a/ld/emultempl/m68hc1xelf.em
+++ b/ld/emultempl/m68hc1xelf.em
@@ -155,6 +155,8 @@ m68hc11elf_create_output_section_statements (void)
155155 }
156156
157157 ldlang_add_file (stub_file);
158+
159+ gld${EMULATION_NAME}_create_output_section_statements ();
158160 }
159161
160162
--- a/ld/emultempl/m68kelf.em
+++ b/ld/emultempl/m68kelf.em
@@ -208,6 +208,8 @@ static void
208208 elf_m68k_create_output_section_statements (void)
209209 {
210210 bfd_elf_m68k_set_target_options (&link_info, got_handling);
211+
212+ gld${EMULATION_NAME}_create_output_section_statements ();
211213 }
212214
213215 EOF
--- a/ld/emultempl/metagelf.em
+++ b/ld/emultempl/metagelf.em
@@ -65,6 +65,8 @@ metagelf_create_output_section_statements (void)
6565
6666 stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
6767 ldlang_add_file (stub_file);
68+
69+ gld${EMULATION_NAME}_create_output_section_statements ();
6870 }
6971
7072
--- a/ld/emultempl/mipself.em
+++ b/ld/emultempl/mipself.em
@@ -206,6 +206,8 @@ mips_create_output_section_statements (void)
206206
207207 if (is_mips_elf (link_info.output_bfd))
208208 _bfd_mips_elf_init_stubs (&link_info, mips_add_stub_section);
209+
210+ gld${EMULATION_NAME}_create_output_section_statements ();
209211 }
210212
211213 /* This is called after we have merged the private data of the input bfds. */
--- a/ld/emultempl/nds32elf.em
+++ b/ld/emultempl/nds32elf.em
@@ -65,6 +65,8 @@ nds32_elf_create_output_section_statements (void)
6565 ex9_export_file, ex9_import_file,
6666 update_ex9_table, ex9_limit,
6767 ex9_loop_aware, ifc_loop_aware);
68+
69+ gld${EMULATION_NAME}_create_output_section_statements ();
6870 }
6971
7072 static void
--- a/ld/emultempl/nios2elf.em
+++ b/ld/emultempl/nios2elf.em
@@ -70,6 +70,8 @@ nios2elf_create_output_section_statements (void)
7070
7171 stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
7272 ldlang_add_file (stub_file);
73+
74+ gld${EMULATION_NAME}_create_output_section_statements ();
7375 }
7476
7577
--- a/ld/emultempl/ppc32elf.em
+++ b/ld/emultempl/ppc32elf.em
@@ -53,6 +53,8 @@ ppc_after_open_output (void)
5353 pagesize = config.commonpagesize;
5454 params.pagesize_p2 = bfd_log2 (pagesize);
5555 ppc_elf_link_params (&link_info, &params);
56+
57+ gld${EMULATION_NAME}_create_output_section_statements ();
5658 }
5759
5860 EOF
--- a/ld/emultempl/ppc64elf.em
+++ b/ld/emultempl/ppc64elf.em
@@ -98,6 +98,8 @@ ppc_create_output_section_statements (void)
9898 params.save_restore_funcs = !bfd_link_relocatable (&link_info);
9999 if (!ppc64_elf_init_stub_bfd (&link_info, &params))
100100 einfo ("%F%P: can not init BFD: %E\n");
101+
102+ gld${EMULATION_NAME}_create_output_section_statements ();
101103 }
102104
103105 /* Called after opening files but before mapping sections. */
--- a/ld/emultempl/rxelf.em
+++ b/ld/emultempl/rxelf.em
@@ -38,6 +38,8 @@ rx_elf_create_output_section_statements (void)
3838 extern void bfd_elf32_rx_set_target_flags (bfd_boolean, bfd_boolean);
3939
4040 bfd_elf32_rx_set_target_flags (no_flag_mismatch_warnings, ignore_lma);
41+
42+ gld${EMULATION_NAME}_create_output_section_statements ();
4143 }
4244
4345 EOF