Rev 5199 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5199 | Rev 6324 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* Linker command language support. |
1 | /* Linker command language support. |
2 | Copyright 1991-2013 Free Software Foundation, Inc. |
2 | Copyright (C) 1991-2015 Free Software Foundation, Inc. |
Line 3... | Line 3... | ||
3 | 3 | ||
Line 4... | Line 4... | ||
4 | This file is part of the GNU Binutils. |
4 | This file is part of the GNU Binutils. |
5 | 5 | ||
Line 38... | Line 38... | ||
38 | #include "ldemul.h" |
38 | #include "ldemul.h" |
39 | #include "fnmatch.h" |
39 | #include "fnmatch.h" |
40 | #include "demangle.h" |
40 | #include "demangle.h" |
41 | #include "hashtab.h" |
41 | #include "hashtab.h" |
42 | #include "libbfd.h" |
42 | #include "libbfd.h" |
- | 43 | #include "elf-bfd.h" |
|
43 | #ifdef ENABLE_PLUGINS |
44 | #ifdef ENABLE_PLUGINS |
44 | #include "plugin.h" |
45 | #include "plugin.h" |
45 | #endif /* ENABLE_PLUGINS */ |
46 | #endif /* ENABLE_PLUGINS */ |
Line 46... | Line -... | ||
46 | - | ||
47 | #include |
- | |
48 | - | ||
49 | 47 | ||
50 | #ifndef offsetof |
48 | #ifndef offsetof |
51 | #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER)) |
49 | #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER)) |
Line 52... | Line 50... | ||
52 | #endif |
50 | #endif |
Line 57... | Line 55... | ||
57 | 55 | ||
58 | #define obstack_chunk_alloc xmalloc |
56 | #define obstack_chunk_alloc xmalloc |
59 | #define obstack_chunk_free free |
57 | #define obstack_chunk_free free |
60 | static const char *entry_symbol_default = "start"; |
58 | static const char *entry_symbol_default = "start"; |
61 | static bfd_boolean placed_commons = FALSE; |
59 | static bfd_boolean placed_commons = FALSE; |
62 | static bfd_boolean stripped_excluded_sections = FALSE; |
60 | static bfd_boolean map_head_is_link_order = FALSE; |
63 | static lang_output_section_statement_type *default_common_section; |
61 | static lang_output_section_statement_type *default_common_section; |
64 | static bfd_boolean map_option_f; |
62 | static bfd_boolean map_option_f; |
65 | static bfd_vma print_dot; |
63 | static bfd_vma print_dot; |
66 | static lang_input_statement_type *first_file; |
64 | static lang_input_statement_type *first_file; |
67 | static const char *current_target; |
65 | static const char *current_target; |
68 | static lang_statement_list_type statement_list; |
- | |
69 | static struct bfd_hash_table lang_definedness_table; |
66 | static lang_statement_list_type statement_list; |
70 | static lang_statement_list_type *stat_save[10]; |
67 | static lang_statement_list_type *stat_save[10]; |
71 | static lang_statement_list_type **stat_save_ptr = &stat_save[0]; |
68 | static lang_statement_list_type **stat_save_ptr = &stat_save[0]; |
- | 69 | static struct unique_sections *unique_section_list; |
|
Line 72... | Line 70... | ||
72 | static struct unique_sections *unique_section_list; |
70 | static struct asneeded_minfo *asneeded_list_head; |
73 | 71 | ||
74 | /* Forward declarations. */ |
- | |
75 | static void exp_init_os (etree_type *); |
72 | /* Forward declarations. */ |
76 | static void init_map_userdata (bfd *, asection *, void *); |
- | |
77 | static lang_input_statement_type *lookup_name (const char *); |
- | |
78 | static struct bfd_hash_entry *lang_definedness_newfunc |
73 | static void exp_init_os (etree_type *); |
79 | (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); |
74 | static lang_input_statement_type *lookup_name (const char *); |
80 | static void insert_undefined (const char *); |
75 | static void insert_undefined (const char *); |
81 | static bfd_boolean sort_def_symbol (struct bfd_link_hash_entry *, void *); |
76 | static bfd_boolean sort_def_symbol (struct bfd_link_hash_entry *, void *); |
82 | static void print_statement (lang_statement_union_type *, |
77 | static void print_statement (lang_statement_union_type *, |
Line 88... | Line 83... | ||
88 | static bfd_boolean lang_one_common (struct bfd_link_hash_entry *, void *); |
83 | static bfd_boolean lang_one_common (struct bfd_link_hash_entry *, void *); |
89 | static void lang_record_phdrs (void); |
84 | static void lang_record_phdrs (void); |
90 | static void lang_do_version_exports_section (void); |
85 | static void lang_do_version_exports_section (void); |
91 | static void lang_finalize_version_expr_head |
86 | static void lang_finalize_version_expr_head |
92 | (struct bfd_elf_version_expr_head *); |
87 | (struct bfd_elf_version_expr_head *); |
- | 88 | static void lang_do_memory_regions (void); |
|
Line 93... | Line 89... | ||
93 | 89 | ||
94 | /* Exported variables. */ |
90 | /* Exported variables. */ |
95 | const char *output_target; |
91 | const char *output_target; |
96 | lang_output_section_statement_type *abs_output_section; |
92 | lang_output_section_statement_type *abs_output_section; |
Line 107... | Line 103... | ||
107 | bfd_boolean had_output_filename = FALSE; |
103 | bfd_boolean had_output_filename = FALSE; |
108 | bfd_boolean lang_float_flag = FALSE; |
104 | bfd_boolean lang_float_flag = FALSE; |
109 | bfd_boolean delete_output_file_on_failure = FALSE; |
105 | bfd_boolean delete_output_file_on_failure = FALSE; |
110 | struct lang_phdr *lang_phdr_list; |
106 | struct lang_phdr *lang_phdr_list; |
111 | struct lang_nocrossrefs *nocrossref_list; |
107 | struct lang_nocrossrefs *nocrossref_list; |
- | 108 | struct asneeded_minfo **asneeded_list_tail; |
|
Line 112... | Line 109... | ||
112 | 109 | ||
113 | /* Functions that traverse the linker script and might evaluate |
110 | /* Functions that traverse the linker script and might evaluate |
114 | DEFINED() need to increment this. */ |
111 | DEFINED() need to increment this at the start of the traversal. */ |
Line 115... | Line -... | ||
115 | int lang_statement_iteration = 0; |
- | |
116 | - | ||
117 | etree_type *base; /* Relocation base - or null */ |
112 | int lang_statement_iteration = 0; |
118 | 113 | ||
119 | /* Return TRUE if the PATTERN argument is a wildcard pattern. |
114 | /* Return TRUE if the PATTERN argument is a wildcard pattern. |
120 | Although backslashes are treated specially if a pattern contains |
115 | Although backslashes are treated specially if a pattern contains |
121 | wildcards, we do not consider the mere presence of a backslash to |
116 | wildcards, we do not consider the mere presence of a backslash to |
Line 204... | Line 199... | ||
204 | const lang_output_section_statement_type *os) |
199 | const lang_output_section_statement_type *os) |
205 | { |
200 | { |
206 | struct unique_sections *unam; |
201 | struct unique_sections *unam; |
207 | const char *secnam; |
202 | const char *secnam; |
Line 208... | Line 203... | ||
208 | 203 | ||
209 | if (link_info.relocatable |
204 | if (bfd_link_relocatable (&link_info) |
210 | && sec->owner != NULL |
205 | && sec->owner != NULL |
211 | && bfd_is_group_section (sec->owner, sec)) |
206 | && bfd_is_group_section (sec->owner, sec)) |
212 | return !(os != NULL |
207 | return !(os != NULL |
Line 1063... | Line 1058... | ||
1063 | p->flags.add_DT_NEEDED_for_dynamic = input_flags.add_DT_NEEDED_for_dynamic; |
1058 | p->flags.add_DT_NEEDED_for_dynamic = input_flags.add_DT_NEEDED_for_dynamic; |
1064 | p->flags.add_DT_NEEDED_for_regular = input_flags.add_DT_NEEDED_for_regular; |
1059 | p->flags.add_DT_NEEDED_for_regular = input_flags.add_DT_NEEDED_for_regular; |
1065 | p->flags.whole_archive = input_flags.whole_archive; |
1060 | p->flags.whole_archive = input_flags.whole_archive; |
1066 | p->flags.sysrooted = input_flags.sysrooted; |
1061 | p->flags.sysrooted = input_flags.sysrooted; |
Line 1067... | Line -... | ||
1067 | - | ||
1068 | if (file_type == lang_input_file_is_l_enum |
- | |
1069 | && name[0] == ':' && name[1] != '\0') |
- | |
1070 | { |
- | |
1071 | file_type = lang_input_file_is_search_file_enum; |
- | |
1072 | name = name + 1; |
- | |
1073 | } |
- | |
1074 | 1062 | ||
1075 | switch (file_type) |
1063 | switch (file_type) |
1076 | { |
1064 | { |
1077 | case lang_input_file_is_symbols_only_enum: |
1065 | case lang_input_file_is_symbols_only_enum: |
1078 | p->filename = name; |
1066 | p->filename = name; |
Line 1083... | Line 1071... | ||
1083 | case lang_input_file_is_fake_enum: |
1071 | case lang_input_file_is_fake_enum: |
1084 | p->filename = name; |
1072 | p->filename = name; |
1085 | p->local_sym_name = name; |
1073 | p->local_sym_name = name; |
1086 | break; |
1074 | break; |
1087 | case lang_input_file_is_l_enum: |
1075 | case lang_input_file_is_l_enum: |
- | 1076 | if (name[0] == ':' && name[1] != '\0') |
|
- | 1077 | { |
|
- | 1078 | p->filename = name + 1; |
|
- | 1079 | p->flags.full_name_provided = TRUE; |
|
- | 1080 | } |
|
- | 1081 | else |
|
1088 | p->filename = name; |
1082 | p->filename = name; |
1089 | p->local_sym_name = concat ("-l", name, (const char *) NULL); |
1083 | p->local_sym_name = concat ("-l", name, (const char *) NULL); |
1090 | p->flags.maybe_archive = TRUE; |
1084 | p->flags.maybe_archive = TRUE; |
1091 | p->flags.real = TRUE; |
1085 | p->flags.real = TRUE; |
1092 | p->flags.search_dirs = TRUE; |
1086 | p->flags.search_dirs = TRUE; |
Line 1120... | Line 1114... | ||
1120 | lang_input_statement_type * |
1114 | lang_input_statement_type * |
1121 | lang_add_input_file (const char *name, |
1115 | lang_add_input_file (const char *name, |
1122 | lang_input_file_enum_type file_type, |
1116 | lang_input_file_enum_type file_type, |
1123 | const char *target) |
1117 | const char *target) |
1124 | { |
1118 | { |
- | 1119 | if (name != NULL && *name == '=') |
|
- | 1120 | { |
|
- | 1121 | lang_input_statement_type *ret; |
|
- | 1122 | char *sysrooted_name |
|
- | 1123 | = concat (ld_sysroot, name + 1, (const char *) NULL); |
|
- | 1124 | ||
- | 1125 | /* We've now forcibly prepended the sysroot, making the input |
|
- | 1126 | file independent of the context. Therefore, temporarily |
|
- | 1127 | force a non-sysrooted context for this statement, so it won't |
|
- | 1128 | get the sysroot prepended again when opened. (N.B. if it's a |
|
- | 1129 | script, any child nodes with input files starting with "/" |
|
- | 1130 | will be handled as "sysrooted" as they'll be found to be |
|
- | 1131 | within the sysroot subdirectory.) */ |
|
- | 1132 | unsigned int outer_sysrooted = input_flags.sysrooted; |
|
- | 1133 | input_flags.sysrooted = 0; |
|
- | 1134 | ret = new_afile (sysrooted_name, file_type, target, TRUE); |
|
- | 1135 | input_flags.sysrooted = outer_sysrooted; |
|
- | 1136 | return ret; |
|
- | 1137 | } |
|
- | 1138 | ||
1125 | return new_afile (name, file_type, target, TRUE); |
1139 | return new_afile (name, file_type, target, TRUE); |
1126 | } |
1140 | } |
Line 1127... | Line 1141... | ||
1127 | 1141 | ||
1128 | struct out_section_hash_entry |
1142 | struct out_section_hash_entry |
Line 1223... | Line 1237... | ||
1223 | abs_output_section = |
1237 | abs_output_section = |
1224 | lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME, 0, TRUE); |
1238 | lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME, 0, TRUE); |
Line 1225... | Line 1239... | ||
1225 | 1239 | ||
Line 1226... | Line -... | ||
1226 | abs_output_section->bfd_section = bfd_abs_section_ptr; |
- | |
1227 | - | ||
1228 | /* The value "3" is ad-hoc, somewhat related to the expected number of |
- | |
1229 | DEFINED expressions in a linker script. For most default linker |
- | |
1230 | scripts, there are none. Why a hash table then? Well, it's somewhat |
- | |
1231 | simpler to re-use working machinery than using a linked list in terms |
1240 | abs_output_section->bfd_section = bfd_abs_section_ptr; |
1232 | of code-complexity here in ld, besides the initialization which just |
1241 | |
1233 | looks like other code here. */ |
- | |
1234 | if (!bfd_hash_table_init_n (&lang_definedness_table, |
- | |
1235 | lang_definedness_newfunc, |
- | |
1236 | sizeof (struct lang_definedness_hash_entry), |
- | |
1237 | 3)) |
1242 | asneeded_list_head = NULL; |
Line 1238... | Line 1243... | ||
1238 | einfo (_("%P%F: can not create hash table: %E\n")); |
1243 | asneeded_list_tail = &asneeded_list_head; |
1239 | } |
1244 | } |
1240 | 1245 | ||
1241 | void |
- | |
1242 | lang_finish (void) |
- | |
1243 | { |
1246 | void |
1244 | bfd_link_hash_table_free (link_info.output_bfd, link_info.hash); |
1247 | lang_finish (void) |
Line 1245... | Line 1248... | ||
1245 | bfd_hash_table_free (&lang_definedness_table); |
1248 | { |
1246 | output_section_statement_table_free (); |
1249 | output_section_statement_table_free (); |
Line 1301... | Line 1304... | ||
1301 | stat_alloc (sizeof (lang_memory_region_type)); |
1304 | stat_alloc (sizeof (lang_memory_region_type)); |
Line 1302... | Line 1305... | ||
1302 | 1305 | ||
1303 | new_region->name_list.name = xstrdup (name); |
1306 | new_region->name_list.name = xstrdup (name); |
1304 | new_region->name_list.next = NULL; |
1307 | new_region->name_list.next = NULL; |
- | 1308 | new_region->next = NULL; |
|
1305 | new_region->next = NULL; |
1309 | new_region->origin_exp = NULL; |
- | 1310 | new_region->origin = 0; |
|
1306 | new_region->origin = 0; |
1311 | new_region->length_exp = NULL; |
1307 | new_region->length = ~(bfd_size_type) 0; |
1312 | new_region->length = ~(bfd_size_type) 0; |
1308 | new_region->current = 0; |
1313 | new_region->current = 0; |
1309 | new_region->last_os = NULL; |
1314 | new_region->last_os = NULL; |
1310 | new_region->flags = 0; |
1315 | new_region->flags = 0; |
Line 1378... | Line 1383... | ||
1378 | } |
1383 | } |
1379 | } |
1384 | } |
1380 | return lang_memory_region_lookup (DEFAULT_MEMORY_REGION, FALSE); |
1385 | return lang_memory_region_lookup (DEFAULT_MEMORY_REGION, FALSE); |
1381 | } |
1386 | } |
Line -... | Line 1387... | ||
- | 1387 | ||
- | 1388 | /* Get the output section statement directly from the userdata. */ |
|
- | 1389 | ||
- | 1390 | lang_output_section_statement_type * |
|
- | 1391 | lang_output_section_get (const asection *output_section) |
|
- | 1392 | { |
|
- | 1393 | return get_userdata (output_section); |
|
- | 1394 | } |
|
1382 | 1395 | ||
1383 | /* Find or create an output_section_statement with the given NAME. |
1396 | /* Find or create an output_section_statement with the given NAME. |
1384 | If CONSTRAINT is non-zero match one with that constraint, otherwise |
1397 | If CONSTRAINT is non-zero match one with that constraint, otherwise |
1385 | match any non-negative constraint. If CREATE, always make a |
1398 | match any non-negative constraint. If CREATE, always make a |
Line 1484... | Line 1497... | ||
1484 | statement for SEC. If an exact match is found on certain flags, |
1497 | statement for SEC. If an exact match is found on certain flags, |
1485 | sets *EXACT too. */ |
1498 | sets *EXACT too. */ |
Line 1486... | Line 1499... | ||
1486 | 1499 | ||
1487 | lang_output_section_statement_type * |
1500 | lang_output_section_statement_type * |
- | 1501 | lang_output_section_find_by_flags (const asection *sec, |
|
1488 | lang_output_section_find_by_flags (const asection *sec, |
1502 | flagword sec_flags, |
1489 | lang_output_section_statement_type **exact, |
1503 | lang_output_section_statement_type **exact, |
1490 | lang_match_sec_type_func match_type) |
1504 | lang_match_sec_type_func match_type) |
1491 | { |
1505 | { |
1492 | lang_output_section_statement_type *first, *look, *found; |
1506 | lang_output_section_statement_type *first, *look, *found; |
Line 1493... | Line 1507... | ||
1493 | flagword flags; |
1507 | flagword look_flags, differ; |
1494 | 1508 | ||
1495 | /* We know the first statement on this list is *ABS*. May as well |
1509 | /* We know the first statement on this list is *ABS*. May as well |
1496 | skip it. */ |
1510 | skip it. */ |
Line 1497... | Line 1511... | ||
1497 | first = &lang_output_section_statement.head->output_section_statement; |
1511 | first = &lang_output_section_statement.head->output_section_statement; |
1498 | first = first->next; |
1512 | first = first->next; |
1499 | 1513 | ||
1500 | /* First try for an exact match. */ |
1514 | /* First try for an exact match. */ |
1501 | found = NULL; |
1515 | found = NULL; |
1502 | for (look = first; look; look = look->next) |
1516 | for (look = first; look; look = look->next) |
1503 | { |
1517 | { |
1504 | flags = look->flags; |
1518 | look_flags = look->flags; |
1505 | if (look->bfd_section != NULL) |
1519 | if (look->bfd_section != NULL) |
1506 | { |
1520 | { |
1507 | flags = look->bfd_section->flags; |
1521 | look_flags = look->bfd_section->flags; |
1508 | if (match_type && !match_type (link_info.output_bfd, |
1522 | if (match_type && !match_type (link_info.output_bfd, |
1509 | look->bfd_section, |
1523 | look->bfd_section, |
1510 | sec->owner, sec)) |
1524 | sec->owner, sec)) |
1511 | continue; |
1525 | continue; |
1512 | } |
1526 | } |
1513 | flags ^= sec->flags; |
1527 | differ = look_flags ^ sec_flags; |
1514 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY |
1528 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY |
1515 | | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1529 | | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1516 | found = look; |
1530 | found = look; |
1517 | } |
1531 | } |
1518 | if (found != NULL) |
1532 | if (found != NULL) |
1519 | { |
1533 | { |
1520 | if (exact != NULL) |
1534 | if (exact != NULL) |
Line 1521... | Line 1535... | ||
1521 | *exact = found; |
1535 | *exact = found; |
1522 | return found; |
1536 | return found; |
1523 | } |
1537 | } |
1524 | 1538 | ||
1525 | if ((sec->flags & SEC_CODE) != 0 |
1539 | if ((sec_flags & SEC_CODE) != 0 |
1526 | && (sec->flags & SEC_ALLOC) != 0) |
1540 | && (sec_flags & SEC_ALLOC) != 0) |
1527 | { |
1541 | { |
1528 | /* Try for a rw code section. */ |
1542 | /* Try for a rw code section. */ |
1529 | for (look = first; look; look = look->next) |
1543 | for (look = first; look; look = look->next) |
1530 | { |
1544 | { |
1531 | flags = look->flags; |
1545 | look_flags = look->flags; |
1532 | if (look->bfd_section != NULL) |
1546 | if (look->bfd_section != NULL) |
1533 | { |
1547 | { |
1534 | flags = look->bfd_section->flags; |
1548 | look_flags = look->bfd_section->flags; |
1535 | if (match_type && !match_type (link_info.output_bfd, |
1549 | if (match_type && !match_type (link_info.output_bfd, |
1536 | look->bfd_section, |
1550 | look->bfd_section, |
1537 | sec->owner, sec)) |
1551 | sec->owner, sec)) |
1538 | continue; |
1552 | continue; |
1539 | } |
1553 | } |
1540 | flags ^= sec->flags; |
1554 | differ = look_flags ^ sec_flags; |
1541 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1555 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1542 | | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1556 | | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1543 | found = look; |
1557 | found = look; |
1544 | } |
1558 | } |
1545 | } |
1559 | } |
1546 | else if ((sec->flags & (SEC_READONLY | SEC_THREAD_LOCAL)) != 0 |
1560 | else if ((sec_flags & SEC_READONLY) != 0 |
1547 | && (sec->flags & SEC_ALLOC) != 0) |
1561 | && (sec_flags & SEC_ALLOC) != 0) |
1548 | { |
1562 | { |
1549 | /* .rodata can go after .text, .sdata2 after .rodata. */ |
1563 | /* .rodata can go after .text, .sdata2 after .rodata. */ |
1550 | for (look = first; look; look = look->next) |
1564 | for (look = first; look; look = look->next) |
1551 | { |
1565 | { |
1552 | flags = look->flags; |
1566 | look_flags = look->flags; |
1553 | if (look->bfd_section != NULL) |
1567 | if (look->bfd_section != NULL) |
1554 | { |
1568 | { |
1555 | flags = look->bfd_section->flags; |
1569 | look_flags = look->bfd_section->flags; |
1556 | if (match_type && !match_type (link_info.output_bfd, |
1570 | if (match_type && !match_type (link_info.output_bfd, |
1557 | look->bfd_section, |
1571 | look->bfd_section, |
1558 | sec->owner, sec)) |
1572 | sec->owner, sec)) |
1559 | continue; |
1573 | continue; |
1560 | } |
1574 | } |
1561 | flags ^= sec->flags; |
1575 | differ = look_flags ^ sec_flags; |
1562 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1576 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
- | 1577 | | SEC_READONLY | SEC_SMALL_DATA)) |
|
- | 1578 | || (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
|
- | 1579 | | SEC_READONLY)) |
|
- | 1580 | && !(look_flags & SEC_SMALL_DATA))) |
|
- | 1581 | found = look; |
|
- | 1582 | } |
|
- | 1583 | } |
|
- | 1584 | else if ((sec_flags & SEC_THREAD_LOCAL) != 0 |
|
- | 1585 | && (sec_flags & SEC_ALLOC) != 0) |
|
- | 1586 | { |
|
- | 1587 | /* .tdata can go after .data, .tbss after .tdata. Treat .tbss |
|
- | 1588 | as if it were a loaded section, and don't use match_type. */ |
|
- | 1589 | bfd_boolean seen_thread_local = FALSE; |
|
- | 1590 | ||
- | 1591 | match_type = NULL; |
|
- | 1592 | for (look = first; look; look = look->next) |
|
- | 1593 | { |
|
- | 1594 | look_flags = look->flags; |
|
1563 | | SEC_READONLY | SEC_SMALL_DATA)) |
1595 | if (look->bfd_section != NULL) |
- | 1596 | look_flags = look->bfd_section->flags; |
|
- | 1597 | ||
1564 | || (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1598 | differ = look_flags ^ (sec_flags | SEC_LOAD | SEC_HAS_CONTENTS); |
1565 | | SEC_READONLY)) |
1599 | if (!(differ & (SEC_THREAD_LOCAL | SEC_ALLOC))) |
- | 1600 | { |
|
- | 1601 | /* .tdata and .tbss must be adjacent and in that order. */ |
|
- | 1602 | if (!(look_flags & SEC_LOAD) |
|
- | 1603 | && (sec_flags & SEC_LOAD)) |
|
- | 1604 | /* ..so if we're at a .tbss section and we're placing |
|
1566 | && !(look->flags & SEC_SMALL_DATA)) |
1605 | a .tdata section stop looking and return the |
- | 1606 | previous section. */ |
|
- | 1607 | break; |
|
- | 1608 | found = look; |
|
- | 1609 | seen_thread_local = TRUE; |
|
1567 | || (!(flags & (SEC_THREAD_LOCAL | SEC_ALLOC)) |
1610 | } |
1568 | && (look->flags & SEC_THREAD_LOCAL) |
1611 | else if (seen_thread_local) |
1569 | && (!(flags & SEC_LOAD) |
1612 | break; |
1570 | || (look->flags & SEC_LOAD)))) |
1613 | else if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD))) |
1571 | found = look; |
1614 | found = look; |
1572 | } |
1615 | } |
1573 | } |
1616 | } |
1574 | else if ((sec->flags & SEC_SMALL_DATA) != 0 |
1617 | else if ((sec_flags & SEC_SMALL_DATA) != 0 |
1575 | && (sec->flags & SEC_ALLOC) != 0) |
1618 | && (sec_flags & SEC_ALLOC) != 0) |
1576 | { |
1619 | { |
1577 | /* .sdata goes after .data, .sbss after .sdata. */ |
1620 | /* .sdata goes after .data, .sbss after .sdata. */ |
1578 | for (look = first; look; look = look->next) |
1621 | for (look = first; look; look = look->next) |
1579 | { |
1622 | { |
1580 | flags = look->flags; |
1623 | look_flags = look->flags; |
1581 | if (look->bfd_section != NULL) |
1624 | if (look->bfd_section != NULL) |
1582 | { |
1625 | { |
1583 | flags = look->bfd_section->flags; |
1626 | look_flags = look->bfd_section->flags; |
1584 | if (match_type && !match_type (link_info.output_bfd, |
1627 | if (match_type && !match_type (link_info.output_bfd, |
1585 | look->bfd_section, |
1628 | look->bfd_section, |
1586 | sec->owner, sec)) |
1629 | sec->owner, sec)) |
1587 | continue; |
1630 | continue; |
1588 | } |
1631 | } |
1589 | flags ^= sec->flags; |
1632 | differ = look_flags ^ sec_flags; |
1590 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1633 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1591 | | SEC_THREAD_LOCAL)) |
1634 | | SEC_THREAD_LOCAL)) |
1592 | || ((look->flags & SEC_SMALL_DATA) |
1635 | || ((look_flags & SEC_SMALL_DATA) |
1593 | && !(sec->flags & SEC_HAS_CONTENTS))) |
1636 | && !(sec_flags & SEC_HAS_CONTENTS))) |
1594 | found = look; |
1637 | found = look; |
1595 | } |
1638 | } |
1596 | } |
1639 | } |
1597 | else if ((sec->flags & SEC_HAS_CONTENTS) != 0 |
1640 | else if ((sec_flags & SEC_HAS_CONTENTS) != 0 |
1598 | && (sec->flags & SEC_ALLOC) != 0) |
1641 | && (sec_flags & SEC_ALLOC) != 0) |
1599 | { |
1642 | { |
1600 | /* .data goes after .rodata. */ |
1643 | /* .data goes after .rodata. */ |
1601 | for (look = first; look; look = look->next) |
1644 | for (look = first; look; look = look->next) |
1602 | { |
1645 | { |
1603 | flags = look->flags; |
1646 | look_flags = look->flags; |
1604 | if (look->bfd_section != NULL) |
1647 | if (look->bfd_section != NULL) |
1605 | { |
1648 | { |
1606 | flags = look->bfd_section->flags; |
1649 | look_flags = look->bfd_section->flags; |
1607 | if (match_type && !match_type (link_info.output_bfd, |
1650 | if (match_type && !match_type (link_info.output_bfd, |
1608 | look->bfd_section, |
1651 | look->bfd_section, |
1609 | sec->owner, sec)) |
1652 | sec->owner, sec)) |
1610 | continue; |
1653 | continue; |
1611 | } |
1654 | } |
1612 | flags ^= sec->flags; |
1655 | differ = look_flags ^ sec_flags; |
1613 | if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1656 | if (!(differ & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD |
1614 | | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1657 | | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) |
1615 | found = look; |
1658 | found = look; |
1616 | } |
1659 | } |
1617 | } |
1660 | } |
1618 | else if ((sec->flags & SEC_ALLOC) != 0) |
1661 | else if ((sec_flags & SEC_ALLOC) != 0) |
1619 | { |
1662 | { |
1620 | /* .bss goes after any other alloc section. */ |
1663 | /* .bss goes after any other alloc section. */ |
1621 | for (look = first; look; look = look->next) |
1664 | for (look = first; look; look = look->next) |
1622 | { |
1665 | { |
1623 | flags = look->flags; |
1666 | look_flags = look->flags; |
1624 | if (look->bfd_section != NULL) |
1667 | if (look->bfd_section != NULL) |
1625 | { |
1668 | { |
1626 | flags = look->bfd_section->flags; |
1669 | look_flags = look->bfd_section->flags; |
1627 | if (match_type && !match_type (link_info.output_bfd, |
1670 | if (match_type && !match_type (link_info.output_bfd, |
1628 | look->bfd_section, |
1671 | look->bfd_section, |
1629 | sec->owner, sec)) |
1672 | sec->owner, sec)) |
1630 | continue; |
1673 | continue; |
1631 | } |
1674 | } |
1632 | flags ^= sec->flags; |
1675 | differ = look_flags ^ sec_flags; |
1633 | if (!(flags & SEC_ALLOC)) |
1676 | if (!(differ & SEC_ALLOC)) |
1634 | found = look; |
1677 | found = look; |
1635 | } |
1678 | } |
1636 | } |
1679 | } |
1637 | else |
1680 | else |
1638 | { |
1681 | { |
1639 | /* non-alloc go last. */ |
1682 | /* non-alloc go last. */ |
1640 | for (look = first; look; look = look->next) |
1683 | for (look = first; look; look = look->next) |
1641 | { |
1684 | { |
1642 | flags = look->flags; |
1685 | look_flags = look->flags; |
1643 | if (look->bfd_section != NULL) |
1686 | if (look->bfd_section != NULL) |
1644 | flags = look->bfd_section->flags; |
1687 | look_flags = look->bfd_section->flags; |
1645 | flags ^= sec->flags; |
1688 | differ = look_flags ^ sec_flags; |
1646 | if (!(flags & SEC_DEBUGGING)) |
1689 | if (!(differ & SEC_DEBUGGING)) |
Line 1647... | Line 1690... | ||
1647 | found = look; |
1690 | found = look; |
1648 | } |
1691 | } |
Line 1649... | Line 1692... | ||
1649 | return found; |
1692 | return found; |
1650 | } |
1693 | } |
Line 1651... | Line 1694... | ||
1651 | 1694 | ||
1652 | if (found || !match_type) |
1695 | if (found || !match_type) |
Line 1760... | Line 1803... | ||
1760 | etree_type *address, |
1803 | etree_type *address, |
1761 | lang_statement_list_type *add_child) |
1804 | lang_statement_list_type *add_child) |
1762 | { |
1805 | { |
1763 | lang_statement_list_type add; |
1806 | lang_statement_list_type add; |
1764 | const char *ps; |
1807 | const char *ps; |
- | 1808 | lang_assignment_statement_type *start_assign; |
|
1765 | lang_output_section_statement_type *os; |
1809 | lang_output_section_statement_type *os; |
1766 | lang_output_section_statement_type **os_tail; |
1810 | lang_output_section_statement_type **os_tail; |
Line 1767... | Line 1811... | ||
1767 | 1811 | ||
1768 | /* If we have found an appropriate place for the output section |
1812 | /* If we have found an appropriate place for the output section |
Line 1772... | Line 1816... | ||
1772 | { |
1816 | { |
1773 | lang_list_init (&add); |
1817 | lang_list_init (&add); |
1774 | push_stat_ptr (&add); |
1818 | push_stat_ptr (&add); |
1775 | } |
1819 | } |
Line -... | Line 1820... | ||
- | 1820 | ||
1776 | 1821 | if (bfd_link_relocatable (&link_info) |
|
1777 | if (link_info.relocatable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) |
1822 | || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) |
Line 1778... | Line 1823... | ||
1778 | address = exp_intop (0); |
1823 | address = exp_intop (0); |
1779 | 1824 | ||
1780 | os_tail = ((lang_output_section_statement_type **) |
1825 | os_tail = ((lang_output_section_statement_type **) |
1781 | lang_output_section_statement.tail); |
1826 | lang_output_section_statement.tail); |
Line 1782... | Line 1827... | ||
1782 | os = lang_enter_output_section_statement (secname, address, normal_section, |
1827 | os = lang_enter_output_section_statement (secname, address, normal_section, |
- | 1828 | NULL, NULL, NULL, constraint, 0); |
|
1783 | NULL, NULL, NULL, constraint, 0); |
1829 | |
1784 | 1830 | ps = NULL; |
|
1785 | ps = NULL; |
1831 | start_assign = NULL; |
1786 | if (config.build_constructors && *os_tail == os) |
1832 | if (config.build_constructors && *os_tail == os) |
1787 | { |
1833 | { |
Line 1795... | Line 1841... | ||
1795 | char *symname; |
1841 | char *symname; |
Line 1796... | Line 1842... | ||
1796 | 1842 | ||
1797 | symname = (char *) xmalloc (ps - secname + sizeof "__start_" + 1); |
1843 | symname = (char *) xmalloc (ps - secname + sizeof "__start_" + 1); |
1798 | symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); |
1844 | symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); |
- | 1845 | sprintf (symname + (symname[0] != 0), "__start_%s", secname); |
|
1799 | sprintf (symname + (symname[0] != 0), "__start_%s", secname); |
1846 | start_assign |
1800 | lang_add_assignment (exp_provide (symname, |
1847 | = lang_add_assignment (exp_provide (symname, |
1801 | exp_nameop (NAME, "."), |
1848 | exp_nameop (NAME, "."), |
1802 | FALSE)); |
1849 | FALSE)); |
1803 | } |
1850 | } |
Line 1820... | Line 1867... | ||
1820 | } |
1867 | } |
1821 | else |
1868 | else |
1822 | lang_leave_output_section_statement (NULL, DEFAULT_MEMORY_REGION, NULL, |
1869 | lang_leave_output_section_statement (NULL, DEFAULT_MEMORY_REGION, NULL, |
1823 | NULL); |
1870 | NULL); |
Line 1824... | Line 1871... | ||
1824 | 1871 | ||
1825 | if (ps != NULL && *ps == '\0') |
1872 | if (start_assign != NULL) |
1826 | { |
1873 | { |
- | 1874 | char *symname; |
|
- | 1875 | lang_assignment_statement_type *stop_assign; |
|
Line 1827... | Line 1876... | ||
1827 | char *symname; |
1876 | bfd_vma dot; |
1828 | 1877 | ||
1829 | symname = (char *) xmalloc (ps - secname + sizeof "__stop_" + 1); |
1878 | symname = (char *) xmalloc (ps - secname + sizeof "__stop_" + 1); |
- | 1879 | symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); |
|
1830 | symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd); |
1880 | sprintf (symname + (symname[0] != 0), "__stop_%s", secname); |
1831 | sprintf (symname + (symname[0] != 0), "__stop_%s", secname); |
1881 | stop_assign |
1832 | lang_add_assignment (exp_provide (symname, |
1882 | = lang_add_assignment (exp_provide (symname, |
- | 1883 | exp_nameop (NAME, "."), |
|
- | 1884 | FALSE)); |
|
- | 1885 | /* Evaluate the expression to define the symbol if referenced, |
|
- | 1886 | before sizing dynamic sections. */ |
|
- | 1887 | dot = os->bfd_section->vma; |
|
- | 1888 | exp_fold_tree (start_assign->exp, os->bfd_section, &dot); |
|
1833 | exp_nameop (NAME, "."), |
1889 | dot += s->size; |
Line 1834... | Line 1890... | ||
1834 | FALSE)); |
1890 | exp_fold_tree (stop_assign->exp, os->bfd_section, &dot); |
1835 | } |
1891 | } |
1836 | 1892 | ||
Line 1952... | Line 2008... | ||
1952 | } |
2008 | } |
1953 | return os; |
2009 | return os; |
1954 | } |
2010 | } |
Line 1955... | Line 2011... | ||
1955 | 2011 | ||
- | 2012 | static void |
|
- | 2013 | lang_print_asneeded (void) |
|
- | 2014 | { |
|
- | 2015 | struct asneeded_minfo *m; |
|
- | 2016 | char buf[100]; |
|
- | 2017 | ||
- | 2018 | if (asneeded_list_head == NULL) |
|
- | 2019 | return; |
|
- | 2020 | ||
- | 2021 | sprintf (buf, _("\nAs-needed library included " |
|
- | 2022 | "to satisfy reference by file (symbol)\n\n")); |
|
- | 2023 | minfo ("%s", buf); |
|
- | 2024 | ||
- | 2025 | for (m = asneeded_list_head; m != NULL; m = m->next) |
|
- | 2026 | { |
|
- | 2027 | size_t len; |
|
- | 2028 | ||
- | 2029 | minfo ("%s", m->soname); |
|
- | 2030 | len = strlen (m->soname); |
|
- | 2031 | ||
- | 2032 | if (len >= 29) |
|
- | 2033 | { |
|
- | 2034 | print_nl (); |
|
- | 2035 | len = 0; |
|
- | 2036 | } |
|
- | 2037 | while (len < 30) |
|
- | 2038 | { |
|
- | 2039 | print_space (); |
|
- | 2040 | ++len; |
|
- | 2041 | } |
|
- | 2042 | ||
- | 2043 | if (m->ref != NULL) |
|
- | 2044 | minfo ("%B ", m->ref); |
|
- | 2045 | minfo ("(%T)\n", m->name); |
|
- | 2046 | } |
|
- | 2047 | } |
|
- | 2048 | ||
1956 | static void |
2049 | static void |
1957 | lang_map_flags (flagword flag) |
2050 | lang_map_flags (flagword flag) |
1958 | { |
2051 | { |
1959 | if (flag & SEC_ALLOC) |
2052 | if (flag & SEC_ALLOC) |
Line 1975... | Line 2068... | ||
1975 | void |
2068 | void |
1976 | lang_map (void) |
2069 | lang_map (void) |
1977 | { |
2070 | { |
1978 | lang_memory_region_type *m; |
2071 | lang_memory_region_type *m; |
1979 | bfd_boolean dis_header_printed = FALSE; |
2072 | bfd_boolean dis_header_printed = FALSE; |
1980 | bfd *p; |
- | |
Line 1981... | Line 2073... | ||
1981 | 2073 | ||
1982 | LANG_FOR_EACH_INPUT_STATEMENT (file) |
2074 | LANG_FOR_EACH_INPUT_STATEMENT (file) |
1983 | { |
2075 | { |
Line 2047... | Line 2139... | ||
2047 | fprintf (config.map_file, _("\nLinker script and memory map\n\n")); |
2139 | fprintf (config.map_file, _("\nLinker script and memory map\n\n")); |
Line 2048... | Line 2140... | ||
2048 | 2140 | ||
2049 | if (! link_info.reduce_memory_overheads) |
2141 | if (! link_info.reduce_memory_overheads) |
2050 | { |
2142 | { |
2051 | obstack_begin (&map_obstack, 1000); |
- | |
2052 | for (p = link_info.input_bfds; p != (bfd *) NULL; p = p->link_next) |
- | |
2053 | bfd_map_over_sections (p, init_map_userdata, 0); |
2143 | obstack_begin (&map_obstack, 1000); |
2054 | bfd_link_hash_traverse (link_info.hash, sort_def_symbol, 0); |
2144 | bfd_link_hash_traverse (link_info.hash, sort_def_symbol, 0); |
2055 | } |
2145 | } |
2056 | lang_statement_iteration ++; |
2146 | lang_statement_iteration++; |
2057 | print_statements (); |
- | |
Line 2058... | Line -... | ||
2058 | } |
- | |
2059 | - | ||
2060 | static void |
- | |
2061 | init_map_userdata (bfd *abfd ATTRIBUTE_UNUSED, |
- | |
2062 | asection *sec, |
- | |
2063 | void *data ATTRIBUTE_UNUSED) |
- | |
2064 | { |
- | |
2065 | fat_section_userdata_type *new_data |
- | |
2066 | = ((fat_section_userdata_type *) (stat_alloc |
- | |
2067 | (sizeof (fat_section_userdata_type)))); |
- | |
2068 | - | ||
2069 | ASSERT (get_userdata (sec) == NULL); |
2147 | print_statements (); |
2070 | get_userdata (sec) = new_data; |
- | |
2071 | new_data->map_symbol_def_tail = &new_data->map_symbol_def_head; |
2148 | |
Line 2072... | Line 2149... | ||
2072 | new_data->map_symbol_def_count = 0; |
2149 | ldemul_extra_map_file_text (link_info.output_bfd, &link_info, config.map_file); |
2073 | } |
2150 | } |
2074 | 2151 | ||
2075 | static bfd_boolean |
2152 | static bfd_boolean |
2076 | sort_def_symbol (struct bfd_link_hash_entry *hash_entry, |
2153 | sort_def_symbol (struct bfd_link_hash_entry *hash_entry, |
2077 | void *info ATTRIBUTE_UNUSED) |
2154 | void *info ATTRIBUTE_UNUSED) |
- | 2155 | { |
|
- | 2156 | if ((hash_entry->type == bfd_link_hash_defined |
|
2078 | { |
2157 | || hash_entry->type == bfd_link_hash_defweak) |
2079 | if (hash_entry->type == bfd_link_hash_defined |
2158 | && hash_entry->u.def.section->owner != link_info.output_bfd |
2080 | || hash_entry->type == bfd_link_hash_defweak) |
2159 | && hash_entry->u.def.section->owner != NULL) |
Line 2081... | Line 2160... | ||
2081 | { |
2160 | { |
2082 | struct fat_user_section_struct *ud; |
2161 | input_section_userdata_type *ud; |
2083 | struct map_symbol_def *def; |
2162 | struct map_symbol_def *def; |
2084 | 2163 | ||
2085 | ud = (struct fat_user_section_struct *) |
2164 | ud = ((input_section_userdata_type *) |
2086 | get_userdata (hash_entry->u.def.section); |
- | |
2087 | if (! ud) |
2165 | get_userdata (hash_entry->u.def.section)); |
2088 | { |
2166 | if (!ud) |
2089 | /* ??? What do we have to do to initialize this beforehand? */ |
2167 | { |
2090 | /* The first time we get here is bfd_abs_section... */ |
2168 | ud = (input_section_userdata_type *) stat_alloc (sizeof (*ud)); |
2091 | init_map_userdata (0, hash_entry->u.def.section, 0); |
2169 | get_userdata (hash_entry->u.def.section) = ud; |
2092 | ud = (struct fat_user_section_struct *) |
2170 | ud->map_symbol_def_tail = &ud->map_symbol_def_head; |
Line 2093... | Line 2171... | ||
2093 | get_userdata (hash_entry->u.def.section); |
2171 | ud->map_symbol_def_count = 0; |
Line 2123... | Line 2201... | ||
2123 | link_info.output_bfd->xvec->name, s->name); |
2201 | link_info.output_bfd->xvec->name, s->name); |
2124 | } |
2202 | } |
2125 | s->bfd_section->output_section = s->bfd_section; |
2203 | s->bfd_section->output_section = s->bfd_section; |
2126 | s->bfd_section->output_offset = 0; |
2204 | s->bfd_section->output_offset = 0; |
Line 2127... | Line -... | ||
2127 | - | ||
2128 | if (!link_info.reduce_memory_overheads) |
- | |
2129 | { |
2205 | |
2130 | fat_section_userdata_type *new_userdata = (fat_section_userdata_type *) |
2206 | /* Set the userdata of the output section to the output section |
2131 | stat_alloc (sizeof (fat_section_userdata_type)); |
- | |
2132 | memset (new_userdata, 0, sizeof (fat_section_userdata_type)); |
2207 | statement to avoid lookup. */ |
2133 | get_userdata (s->bfd_section) = new_userdata; |
- | |
Line 2134... | Line 2208... | ||
2134 | } |
2208 | get_userdata (s->bfd_section) = s; |
2135 | 2209 | ||
2136 | /* If there is a base address, make sure that any sections it might |
2210 | /* If there is a base address, make sure that any sections it might |
2137 | mention are initialized. */ |
2211 | mention are initialized. */ |
Line 2284... | Line 2358... | ||
2284 | /* If final link, don't copy the SEC_LINK_ONCE flags, they've |
2358 | /* If final link, don't copy the SEC_LINK_ONCE flags, they've |
2285 | already been processed. One reason to do this is that on pe |
2359 | already been processed. One reason to do this is that on pe |
2286 | format targets, .text$foo sections go into .text and it's odd |
2360 | format targets, .text$foo sections go into .text and it's odd |
2287 | to see .text with SEC_LINK_ONCE set. */ |
2361 | to see .text with SEC_LINK_ONCE set. */ |
Line 2288... | Line 2362... | ||
2288 | 2362 | ||
2289 | if (!link_info.relocatable) |
2363 | if (!bfd_link_relocatable (&link_info)) |
Line 2290... | Line 2364... | ||
2290 | flags &= ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC); |
2364 | flags &= ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC); |
2291 | 2365 | ||
2292 | switch (output->sectype) |
2366 | switch (output->sectype) |
Line 2359... | Line 2433... | ||
2359 | if (section->alignment_power > output->bfd_section->alignment_power) |
2433 | if (section->alignment_power > output->bfd_section->alignment_power) |
2360 | output->bfd_section->alignment_power = section->alignment_power; |
2434 | output->bfd_section->alignment_power = section->alignment_power; |
Line 2361... | Line 2435... | ||
2361 | 2435 | ||
Line 2362... | Line 2436... | ||
2362 | section->output_section = output->bfd_section; |
2436 | section->output_section = output->bfd_section; |
2363 | - | ||
2364 | if (!link_info.relocatable |
2437 | |
2365 | && !stripped_excluded_sections) |
2438 | if (!map_head_is_link_order) |
2366 | { |
2439 | { |
2367 | asection *s = output->bfd_section->map_tail.s; |
2440 | asection *s = output->bfd_section->map_tail.s; |
2368 | output->bfd_section->map_tail.s = section; |
2441 | output->bfd_section->map_tail.s = section; |
Line 2739... | Line 2812... | ||
2739 | { |
2812 | { |
2740 | default: |
2813 | default: |
2741 | break; |
2814 | break; |
Line 2742... | Line 2815... | ||
2742 | 2815 | ||
2743 | case bfd_object: |
- | |
2744 | #ifdef ENABLE_PLUGINS |
2816 | case bfd_object: |
2745 | if (!entry->flags.reload) |
- | |
2746 | #endif |
2817 | if (!entry->flags.reload) |
2747 | ldlang_add_file (entry); |
2818 | ldlang_add_file (entry); |
2748 | if (trace_files || verbose) |
2819 | if (trace_files || verbose) |
2749 | info_msg ("%I\n", entry); |
2820 | info_msg ("%I\n", entry); |
Line 3112... | Line 3183... | ||
3112 | { |
3183 | { |
3113 | case lang_output_statement_enum: |
3184 | case lang_output_statement_enum: |
3114 | ASSERT (link_info.output_bfd == NULL); |
3185 | ASSERT (link_info.output_bfd == NULL); |
3115 | open_output (statement->output_statement.name); |
3186 | open_output (statement->output_statement.name); |
3116 | ldemul_set_output_arch (); |
3187 | ldemul_set_output_arch (); |
3117 | if (config.magic_demand_paged && !link_info.relocatable) |
3188 | if (config.magic_demand_paged |
- | 3189 | && !bfd_link_relocatable (&link_info)) |
|
3118 | link_info.output_bfd->flags |= D_PAGED; |
3190 | link_info.output_bfd->flags |= D_PAGED; |
3119 | else |
3191 | else |
3120 | link_info.output_bfd->flags &= ~D_PAGED; |
3192 | link_info.output_bfd->flags &= ~D_PAGED; |
3121 | if (config.text_read_only) |
3193 | if (config.text_read_only) |
3122 | link_info.output_bfd->flags |= WP_TEXT; |
3194 | link_info.output_bfd->flags |= WP_TEXT; |
Line 3217... | Line 3289... | ||
3217 | case lang_input_statement_enum: |
3289 | case lang_input_statement_enum: |
3218 | if (s->input_statement.flags.real) |
3290 | if (s->input_statement.flags.real) |
3219 | { |
3291 | { |
3220 | lang_statement_union_type **os_tail; |
3292 | lang_statement_union_type **os_tail; |
3221 | lang_statement_list_type add; |
3293 | lang_statement_list_type add; |
- | 3294 | bfd *abfd; |
|
Line 3222... | Line 3295... | ||
3222 | 3295 | ||
Line 3223... | Line 3296... | ||
3223 | s->input_statement.target = current_target; |
3296 | s->input_statement.target = current_target; |
3224 | 3297 | ||
3225 | /* If we are being called from within a group, and this |
3298 | /* If we are being called from within a group, and this |
3226 | is an archive which has already been searched, then |
3299 | is an archive which has already been searched, then |
- | 3300 | force it to be researched unless the whole archive |
|
3227 | force it to be researched unless the whole archive |
3301 | has been loaded already. Do the same for a rescan. |
3228 | has been loaded already. Do the same for a rescan. */ |
3302 | Likewise reload --as-needed shared libs. */ |
3229 | if (mode != OPEN_BFD_NORMAL |
3303 | if (mode != OPEN_BFD_NORMAL |
3230 | #ifdef ENABLE_PLUGINS |
3304 | #ifdef ENABLE_PLUGINS |
3231 | && ((mode & OPEN_BFD_RESCAN) == 0 |
3305 | && ((mode & OPEN_BFD_RESCAN) == 0 |
3232 | || plugin_insert == NULL) |
- | |
3233 | #endif |
- | |
3234 | && !s->input_statement.flags.whole_archive |
- | |
3235 | && s->input_statement.flags.loaded |
- | |
3236 | && s->input_statement.the_bfd != NULL |
- | |
3237 | && bfd_check_format (s->input_statement.the_bfd, |
- | |
3238 | bfd_archive)) |
- | |
3239 | s->input_statement.flags.loaded = FALSE; |
- | |
3240 | #ifdef ENABLE_PLUGINS |
- | |
3241 | /* When rescanning, reload --as-needed shared libs. */ |
- | |
3242 | else if ((mode & OPEN_BFD_RESCAN) != 0 |
3306 | || plugin_insert == NULL) |
- | 3307 | #endif |
|
- | 3308 | && s->input_statement.flags.loaded |
|
- | 3309 | && (abfd = s->input_statement.the_bfd) != NULL |
|
- | 3310 | && ((bfd_get_format (abfd) == bfd_archive |
|
- | 3311 | && !s->input_statement.flags.whole_archive) |
|
3243 | && plugin_insert == NULL |
3312 | || (bfd_get_format (abfd) == bfd_object |
3244 | && s->input_statement.flags.loaded |
3313 | && ((abfd->flags) & DYNAMIC) != 0 |
3245 | && s->input_statement.flags.add_DT_NEEDED_for_regular |
3314 | && s->input_statement.flags.add_DT_NEEDED_for_regular |
3246 | && s->input_statement.the_bfd != NULL |
- | |
3247 | && ((s->input_statement.the_bfd->flags) & DYNAMIC) != 0 |
3315 | && bfd_get_flavour (abfd) == bfd_target_elf_flavour |
3248 | && plugin_should_reload (s->input_statement.the_bfd)) |
3316 | && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0))) |
3249 | { |
3317 | { |
3250 | s->input_statement.flags.loaded = FALSE; |
3318 | s->input_statement.flags.loaded = FALSE; |
3251 | s->input_statement.flags.reload = TRUE; |
- | |
Line 3252... | Line 3319... | ||
3252 | } |
3319 | s->input_statement.flags.reload = TRUE; |
3253 | #endif |
3320 | } |
Line 3254... | Line 3321... | ||
3254 | 3321 | ||
Line 3301... | Line 3368... | ||
3301 | /* Exit if any of the files were missing. */ |
3368 | /* Exit if any of the files were missing. */ |
3302 | if (input_flags.missing_file) |
3369 | if (input_flags.missing_file) |
3303 | einfo ("%F"); |
3370 | einfo ("%F"); |
3304 | } |
3371 | } |
Line 3305... | Line -... | ||
3305 | - | ||
3306 | /* Add a symbol to a hash of symbols used in DEFINED (NAME) expressions. */ |
- | |
3307 | - | ||
3308 | void |
- | |
3309 | lang_track_definedness (const char *name) |
- | |
3310 | { |
- | |
3311 | if (bfd_hash_lookup (&lang_definedness_table, name, TRUE, FALSE) == NULL) |
- | |
3312 | einfo (_("%P%F: bfd_hash_lookup failed creating symbol %s\n"), name); |
- | |
3313 | } |
- | |
3314 | - | ||
3315 | /* New-function for the definedness hash table. */ |
- | |
3316 | - | ||
3317 | static struct bfd_hash_entry * |
- | |
3318 | lang_definedness_newfunc (struct bfd_hash_entry *entry, |
- | |
3319 | struct bfd_hash_table *table ATTRIBUTE_UNUSED, |
- | |
3320 | const char *name ATTRIBUTE_UNUSED) |
- | |
3321 | { |
- | |
3322 | struct lang_definedness_hash_entry *ret |
- | |
3323 | = (struct lang_definedness_hash_entry *) entry; |
- | |
3324 | - | ||
3325 | if (ret == NULL) |
- | |
3326 | ret = (struct lang_definedness_hash_entry *) |
- | |
3327 | bfd_hash_allocate (table, sizeof (struct lang_definedness_hash_entry)); |
- | |
3328 | - | ||
3329 | if (ret == NULL) |
- | |
3330 | einfo (_("%P%F: bfd_hash_allocate failed creating symbol %s\n"), name); |
- | |
3331 | - | ||
3332 | ret->iteration = -1; |
- | |
3333 | return &ret->root; |
- | |
3334 | } |
- | |
3335 | - | ||
3336 | /* Return the iteration when the definition of NAME was last updated. A |
- | |
3337 | value of -1 means that the symbol is not defined in the linker script |
- | |
3338 | or the command line, but may be defined in the linker symbol table. */ |
- | |
3339 | - | ||
3340 | int |
- | |
3341 | lang_symbol_definition_iteration (const char *name) |
- | |
3342 | { |
- | |
3343 | struct lang_definedness_hash_entry *defentry |
- | |
3344 | = (struct lang_definedness_hash_entry *) |
- | |
3345 | bfd_hash_lookup (&lang_definedness_table, name, FALSE, FALSE); |
- | |
3346 | - | ||
3347 | /* We've already created this one on the presence of DEFINED in the |
- | |
3348 | script, so it can't be NULL unless something is borked elsewhere in |
- | |
3349 | the code. */ |
- | |
3350 | if (defentry == NULL) |
- | |
3351 | FAIL (); |
- | |
3352 | - | ||
3353 | return defentry->iteration; |
- | |
3354 | } |
- | |
3355 | - | ||
3356 | /* Update the definedness state of NAME. */ |
- | |
3357 | - | ||
3358 | void |
- | |
3359 | lang_update_definedness (const char *name, struct bfd_link_hash_entry *h) |
- | |
3360 | { |
- | |
3361 | struct lang_definedness_hash_entry *defentry |
- | |
3362 | = (struct lang_definedness_hash_entry *) |
- | |
3363 | bfd_hash_lookup (&lang_definedness_table, name, FALSE, FALSE); |
- | |
3364 | - | ||
3365 | /* We don't keep track of symbols not tested with DEFINED. */ |
- | |
3366 | if (defentry == NULL) |
- | |
3367 | return; |
- | |
3368 | - | ||
3369 | /* If the symbol was already defined, and not from an earlier statement |
- | |
3370 | iteration, don't update the definedness iteration, because that'd |
- | |
3371 | make the symbol seem defined in the linker script at this point, and |
- | |
3372 | it wasn't; it was defined in some object. If we do anyway, DEFINED |
- | |
3373 | would start to yield false before this point and the construct "sym = |
- | |
3374 | DEFINED (sym) ? sym : X;" would change sym to X despite being defined |
- | |
3375 | in an object. */ |
- | |
3376 | if (h->type != bfd_link_hash_undefined |
- | |
3377 | && h->type != bfd_link_hash_common |
- | |
3378 | && h->type != bfd_link_hash_new |
- | |
3379 | && defentry->iteration == -1) |
- | |
3380 | return; |
- | |
3381 | - | ||
3382 | defentry->iteration = lang_statement_iteration; |
- | |
3383 | } |
- | |
3384 | 3372 | ||
3385 | /* Add the supplied name to the symbol table as an undefined reference. |
3373 | /* Add the supplied name to the symbol table as an undefined reference. |
3386 | This is a two step process as the symbol table doesn't even exist at |
3374 | This is a two step process as the symbol table doesn't even exist at |
3387 | the time the ld command line is processed. First we put the name |
3375 | the time the ld command line is processed. First we put the name |
3388 | on a list, then, once the output file has been opened, transfer the |
3376 | on a list, then, once the output file has been opened, transfer the |
Line 3437... | Line 3425... | ||
3437 | 3425 | ||
3438 | for (ptr = ldlang_undef_chain_list_head; ptr != NULL; ptr = ptr->next) |
3426 | for (ptr = ldlang_undef_chain_list_head; ptr != NULL; ptr = ptr->next) |
3439 | insert_undefined (ptr->name); |
3427 | insert_undefined (ptr->name); |
Line -... | Line 3428... | ||
- | 3428 | } |
|
- | 3429 | ||
- | 3430 | /* Structure used to build the list of symbols that the user has required |
|
- | 3431 | be defined. */ |
|
- | 3432 | ||
- | 3433 | struct require_defined_symbol |
|
- | 3434 | { |
|
- | 3435 | const char *name; |
|
- | 3436 | struct require_defined_symbol *next; |
|
- | 3437 | }; |
|
- | 3438 | ||
- | 3439 | /* The list of symbols that the user has required be defined. */ |
|
- | 3440 | ||
- | 3441 | static struct require_defined_symbol *require_defined_symbol_list; |
|
- | 3442 | ||
- | 3443 | /* Add a new symbol NAME to the list of symbols that are required to be |
|
- | 3444 | defined. */ |
|
- | 3445 | ||
- | 3446 | void |
|
- | 3447 | ldlang_add_require_defined (const char * const name) |
|
- | 3448 | { |
|
- | 3449 | struct require_defined_symbol *ptr; |
|
- | 3450 | ||
- | 3451 | ldlang_add_undef (name, TRUE); |
|
- | 3452 | ptr = (struct require_defined_symbol *) stat_alloc (sizeof (*ptr)); |
|
- | 3453 | ptr->next = require_defined_symbol_list; |
|
- | 3454 | ptr->name = strdup (name); |
|
- | 3455 | require_defined_symbol_list = ptr; |
|
- | 3456 | } |
|
- | 3457 | ||
- | 3458 | /* Check that all symbols the user required to be defined, are defined, |
|
- | 3459 | raise an error if we find a symbol that is not defined. */ |
|
- | 3460 | ||
- | 3461 | static void |
|
- | 3462 | ldlang_check_require_defined_symbols (void) |
|
- | 3463 | { |
|
- | 3464 | struct require_defined_symbol *ptr; |
|
- | 3465 | ||
- | 3466 | for (ptr = require_defined_symbol_list; ptr != NULL; ptr = ptr->next) |
|
- | 3467 | { |
|
- | 3468 | struct bfd_link_hash_entry *h; |
|
- | 3469 | ||
- | 3470 | h = bfd_link_hash_lookup (link_info.hash, ptr->name, |
|
- | 3471 | FALSE, FALSE, TRUE); |
|
- | 3472 | if (h == NULL |
|
- | 3473 | || (h->type != bfd_link_hash_defined |
|
- | 3474 | && h->type != bfd_link_hash_defweak)) |
|
- | 3475 | einfo(_("%P%X: required symbol `%s' not defined\n"), ptr->name); |
|
- | 3476 | } |
|
3440 | } |
3477 | } |
Line 3441... | Line 3478... | ||
3441 | 3478 | ||
3442 | /* Check for all readonly or some readwrite sections. */ |
3479 | /* Check for all readonly or some readwrite sections. */ |
3443 | 3480 | ||
Line 3887... | Line 3924... | ||
3887 | exclude = FALSE; |
3924 | exclude = FALSE; |
3888 | break; |
3925 | break; |
3889 | } |
3926 | } |
3890 | } |
3927 | } |
Line 3891... | Line -... | ||
3891 | - | ||
3892 | /* TODO: Don't just junk map_head.s, turn them into link_orders. */ |
- | |
3893 | output_section->map_head.link_order = NULL; |
- | |
3894 | output_section->map_tail.link_order = NULL; |
- | |
3895 | 3928 | ||
3896 | if (exclude) |
3929 | if (exclude) |
3897 | { |
3930 | { |
3898 | /* We don't set bfd_section to NULL since bfd_section of the |
3931 | /* We don't set bfd_section to NULL since bfd_section of the |
3899 | removed output section statement may still be used. */ |
3932 | removed output section statement may still be used. */ |
Line 3902... | Line 3935... | ||
3902 | output_section->flags |= SEC_EXCLUDE; |
3935 | output_section->flags |= SEC_EXCLUDE; |
3903 | bfd_section_list_remove (link_info.output_bfd, output_section); |
3936 | bfd_section_list_remove (link_info.output_bfd, output_section); |
3904 | link_info.output_bfd->section_count--; |
3937 | link_info.output_bfd->section_count--; |
3905 | } |
3938 | } |
3906 | } |
3939 | } |
- | 3940 | } |
|
- | 3941 | ||
- | 3942 | /* Called from ldwrite to clear out asection.map_head and |
|
- | 3943 | asection.map_tail for use as link_orders in ldwrite. |
|
- | 3944 | FIXME: Except for sh64elf.em which starts creating link_orders in |
|
- | 3945 | its after_allocation routine so needs to call it early. */ |
|
- | 3946 | ||
- | 3947 | void |
|
- | 3948 | lang_clear_os_map (void) |
|
- | 3949 | { |
|
- | 3950 | lang_output_section_statement_type *os; |
|
- | 3951 | ||
- | 3952 | if (map_head_is_link_order) |
|
- | 3953 | return; |
|
- | 3954 | ||
- | 3955 | for (os = &lang_output_section_statement.head->output_section_statement; |
|
- | 3956 | os != NULL; |
|
- | 3957 | os = os->next) |
|
- | 3958 | { |
|
- | 3959 | asection *output_section; |
|
- | 3960 | ||
- | 3961 | if (os->constraint < 0) |
|
- | 3962 | continue; |
|
- | 3963 | ||
- | 3964 | output_section = os->bfd_section; |
|
- | 3965 | if (output_section == NULL) |
|
- | 3966 | continue; |
|
- | 3967 | ||
- | 3968 | /* TODO: Don't just junk map_head.s, turn them into link_orders. */ |
|
- | 3969 | output_section->map_head.link_order = NULL; |
|
- | 3970 | output_section->map_tail.link_order = NULL; |
|
- | 3971 | } |
|
Line 3907... | Line 3972... | ||
3907 | 3972 | ||
3908 | /* Stop future calls to lang_add_section from messing with map_head |
3973 | /* Stop future calls to lang_add_section from messing with map_head |
3909 | and map_tail link_order fields. */ |
3974 | and map_tail link_order fields. */ |
3910 | stripped_excluded_sections = TRUE; |
3975 | map_head_is_link_order = TRUE; |
Line 3911... | Line 3976... | ||
3911 | } |
3976 | } |
3912 | 3977 | ||
3913 | static void |
3978 | static void |
Line 3974... | Line 4039... | ||
3974 | else |
4039 | else |
3975 | { |
4040 | { |
3976 | const char *dst = assignment->exp->assign.dst; |
4041 | const char *dst = assignment->exp->assign.dst; |
Line 3977... | Line 4042... | ||
3977 | 4042 | ||
- | 4043 | is_dot = (dst[0] == '.' && dst[1] == 0); |
|
3978 | is_dot = (dst[0] == '.' && dst[1] == 0); |
4044 | if (!is_dot) |
3979 | expld.assign_name = dst; |
4045 | expld.assign_name = dst; |
3980 | tree = assignment->exp->assign.src; |
4046 | tree = assignment->exp->assign.src; |
Line 3981... | Line 4047... | ||
3981 | } |
4047 | } |
3982 | 4048 | ||
3983 | osec = output_section->bfd_section; |
4049 | osec = output_section->bfd_section; |
- | 4050 | if (osec == NULL) |
|
- | 4051 | osec = bfd_abs_section_ptr; |
|
3984 | if (osec == NULL) |
4052 | |
- | 4053 | if (assignment->exp->type.node_class != etree_provide) |
|
- | 4054 | exp_fold_tree (tree, osec, &print_dot); |
|
- | 4055 | else |
|
3985 | osec = bfd_abs_section_ptr; |
4056 | expld.result.valid_p = FALSE; |
3986 | exp_fold_tree (tree, osec, &print_dot); |
4057 | |
3987 | if (expld.result.valid_p) |
4058 | if (expld.result.valid_p) |
Line 3988... | Line 4059... | ||
3988 | { |
4059 | { |
Line 4019... | Line 4090... | ||
4019 | minfo ("[unresolved]"); |
4090 | minfo ("[unresolved]"); |
4020 | } |
4091 | } |
4021 | } |
4092 | } |
4022 | else |
4093 | else |
4023 | { |
4094 | { |
- | 4095 | if (assignment->exp->type.node_class == etree_provide) |
|
- | 4096 | minfo ("[!provide]"); |
|
- | 4097 | else |
|
4024 | minfo ("*undef* "); |
4098 | minfo ("*undef* "); |
4025 | #ifdef BFD64 |
4099 | #ifdef BFD64 |
4026 | minfo (" "); |
4100 | minfo (" "); |
4027 | #endif |
4101 | #endif |
4028 | } |
4102 | } |
Line 4084... | Line 4158... | ||
4084 | } |
4158 | } |
Line 4085... | Line 4159... | ||
4085 | 4159 | ||
4086 | static void |
4160 | static void |
4087 | print_all_symbols (asection *sec) |
4161 | print_all_symbols (asection *sec) |
4088 | { |
4162 | { |
4089 | struct fat_user_section_struct *ud = |
4163 | input_section_userdata_type *ud |
4090 | (struct fat_user_section_struct *) get_userdata (sec); |
4164 | = (input_section_userdata_type *) get_userdata (sec); |
4091 | struct map_symbol_def *def; |
4165 | struct map_symbol_def *def; |
4092 | struct bfd_link_hash_entry **entries; |
4166 | struct bfd_link_hash_entry **entries; |
Line 4093... | Line 4167... | ||
4093 | unsigned int i; |
4167 | unsigned int i; |
Line 4561... | Line 4635... | ||
4561 | fill_type *fill, |
4635 | fill_type *fill, |
4562 | bfd_vma dot) |
4636 | bfd_vma dot) |
4563 | { |
4637 | { |
4564 | lang_input_section_type *is = &((*this_ptr)->input_section); |
4638 | lang_input_section_type *is = &((*this_ptr)->input_section); |
4565 | asection *i = is->section; |
4639 | asection *i = is->section; |
- | 4640 | asection *o = output_section_statement->bfd_section; |
|
Line 4566... | Line 4641... | ||
4566 | 4641 | ||
- | 4642 | if (i->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) |
|
4567 | if (i->sec_info_type != SEC_INFO_TYPE_JUST_SYMS |
4643 | i->output_offset = i->vma - o->vma; |
- | 4644 | else if ((i->flags & SEC_EXCLUDE) != 0) |
|
- | 4645 | i->output_offset = dot - o->vma; |
|
4568 | && (i->flags & SEC_EXCLUDE) == 0) |
4646 | else |
4569 | { |
4647 | { |
4570 | bfd_size_type alignment_needed; |
- | |
Line 4571... | Line 4648... | ||
4571 | asection *o; |
4648 | bfd_size_type alignment_needed; |
4572 | 4649 | ||
4573 | /* Align this section first to the input sections requirement, |
4650 | /* Align this section first to the input sections requirement, |
4574 | then to the output section's requirement. If this alignment |
4651 | then to the output section's requirement. If this alignment |
Line 4575... | Line 4652... | ||
4575 | is greater than any seen before, then record it too. Perform |
4652 | is greater than any seen before, then record it too. Perform |
4576 | the alignment by inserting a magic 'padding' statement. */ |
4653 | the alignment by inserting a magic 'padding' statement. */ |
Line 4577... | Line -... | ||
4577 | - | ||
4578 | if (output_section_statement->subsection_alignment != -1) |
4654 | |
4579 | i->alignment_power = output_section_statement->subsection_alignment; |
4655 | if (output_section_statement->subsection_alignment != -1) |
Line 4580... | Line 4656... | ||
4580 | 4656 | i->alignment_power = output_section_statement->subsection_alignment; |
|
Line 4589... | Line 4665... | ||
4589 | insert_pad (this_ptr, fill, TO_SIZE (alignment_needed), o, dot); |
4665 | insert_pad (this_ptr, fill, TO_SIZE (alignment_needed), o, dot); |
4590 | dot += alignment_needed; |
4666 | dot += alignment_needed; |
4591 | } |
4667 | } |
Line 4592... | Line 4668... | ||
4592 | 4668 | ||
4593 | /* Remember where in the output section this input section goes. */ |
- | |
4594 | 4669 | /* Remember where in the output section this input section goes. */ |
|
Line 4595... | Line 4670... | ||
4595 | i->output_offset = dot - o->vma; |
4670 | i->output_offset = dot - o->vma; |
4596 | 4671 | ||
4597 | /* Mark how big the output section must be to contain this now. */ |
4672 | /* Mark how big the output section must be to contain this now. */ |
4598 | dot += TO_ADDR (i->size); |
4673 | dot += TO_ADDR (i->size); |
4599 | o->size = TO_SIZE (dot - o->vma); |
- | |
4600 | } |
- | |
4601 | else |
- | |
4602 | { |
- | |
Line 4603... | Line 4674... | ||
4603 | i->output_offset = i->vma - output_section_statement->bfd_section->vma; |
4674 | o->size = TO_SIZE (dot - o->vma); |
4604 | } |
4675 | } |
Line 4605... | Line 4676... | ||
4605 | 4676 | ||
Line 4774... | Line 4845... | ||
4774 | { |
4845 | { |
4775 | switch (s->header.type) |
4846 | switch (s->header.type) |
4776 | { |
4847 | { |
4777 | case lang_output_section_statement_enum: |
4848 | case lang_output_section_statement_enum: |
4778 | { |
4849 | { |
4779 | bfd_vma newdot, after; |
4850 | bfd_vma newdot, after, dotdelta; |
4780 | lang_output_section_statement_type *os; |
4851 | lang_output_section_statement_type *os; |
4781 | lang_memory_region_type *r; |
4852 | lang_memory_region_type *r; |
4782 | int section_alignment = 0; |
4853 | int section_alignment = 0; |
Line 4783... | Line 4854... | ||
4783 | 4854 | ||
Line 4787... | Line 4858... | ||
4787 | 4858 | ||
4788 | /* FIXME: We shouldn't need to zero section vmas for ld -r |
4859 | /* FIXME: We shouldn't need to zero section vmas for ld -r |
4789 | here, in lang_insert_orphan, or in the default linker scripts. |
4860 | here, in lang_insert_orphan, or in the default linker scripts. |
4790 | This is covering for coff backend linker bugs. See PR6945. */ |
4861 | This is covering for coff backend linker bugs. See PR6945. */ |
4791 | if (os->addr_tree == NULL |
4862 | if (os->addr_tree == NULL |
4792 | && link_info.relocatable |
4863 | && bfd_link_relocatable (&link_info) |
4793 | && (bfd_get_flavour (link_info.output_bfd) |
4864 | && (bfd_get_flavour (link_info.output_bfd) |
4794 | == bfd_target_coff_flavour)) |
4865 | == bfd_target_coff_flavour)) |
4795 | os->addr_tree = exp_intop (0); |
4866 | os->addr_tree = exp_intop (0); |
4796 | if (os->addr_tree != NULL) |
4867 | if (os->addr_tree != NULL) |
Line 4840... | Line 4911... | ||
4840 | os->bfd_section->size = input->size; |
4911 | os->bfd_section->size = input->size; |
4841 | break; |
4912 | break; |
4842 | } |
4913 | } |
Line 4843... | Line 4914... | ||
4843 | 4914 | ||
- | 4915 | newdot = dot; |
|
4844 | newdot = dot; |
4916 | dotdelta = 0; |
4845 | if (bfd_is_abs_section (os->bfd_section)) |
4917 | if (bfd_is_abs_section (os->bfd_section)) |
4846 | { |
4918 | { |
4847 | /* No matter what happens, an abs section starts at zero. */ |
4919 | /* No matter what happens, an abs section starts at zero. */ |
4848 | ASSERT (os->bfd_section->vma == 0); |
4920 | ASSERT (os->bfd_section->vma == 0); |
Line 4865... | Line 4937... | ||
4865 | /* If a loadable section is using the default memory |
4937 | /* If a loadable section is using the default memory |
4866 | region, and some non default memory regions were |
4938 | region, and some non default memory regions were |
4867 | defined, issue an error message. */ |
4939 | defined, issue an error message. */ |
4868 | if (!os->ignored |
4940 | if (!os->ignored |
4869 | && !IGNORE_SECTION (os->bfd_section) |
4941 | && !IGNORE_SECTION (os->bfd_section) |
4870 | && ! link_info.relocatable |
4942 | && !bfd_link_relocatable (&link_info) |
4871 | && check_regions |
4943 | && check_regions |
4872 | && strcmp (os->region->name_list.name, |
4944 | && strcmp (os->region->name_list.name, |
4873 | DEFAULT_MEMORY_REGION) == 0 |
4945 | DEFAULT_MEMORY_REGION) == 0 |
4874 | && lang_memory_region_list != NULL |
4946 | && lang_memory_region_list != NULL |
4875 | && (strcmp (lang_memory_region_list->name_list.name, |
4947 | && (strcmp (lang_memory_region_list->name_list.name, |
Line 4908... | Line 4980... | ||
4908 | if (section_alignment > 0) |
4980 | if (section_alignment > 0) |
4909 | { |
4981 | { |
4910 | bfd_vma savedot = newdot; |
4982 | bfd_vma savedot = newdot; |
4911 | newdot = align_power (newdot, section_alignment); |
4983 | newdot = align_power (newdot, section_alignment); |
Line 4912... | Line 4984... | ||
4912 | 4984 | ||
- | 4985 | dotdelta = newdot - savedot; |
|
4913 | if (newdot != savedot |
4986 | if (dotdelta != 0 |
4914 | && (config.warn_section_align |
4987 | && (config.warn_section_align |
4915 | || os->addr_tree != NULL) |
4988 | || os->addr_tree != NULL) |
4916 | && expld.phase != lang_mark_phase_enum) |
4989 | && expld.phase != lang_mark_phase_enum) |
4917 | einfo (_("%P: warning: changing start of section" |
4990 | einfo (_("%P: warning: changing start of section" |
4918 | " %s by %lu bytes\n"), |
4991 | " %s by %lu bytes\n"), |
4919 | os->name, (unsigned long) (newdot - savedot)); |
4992 | os->name, (unsigned long) dotdelta); |
Line 4920... | Line 4993... | ||
4920 | } |
4993 | } |
Line 4921... | Line 4994... | ||
4921 | 4994 | ||
Line 4962... | Line 5035... | ||
4962 | } |
5035 | } |
4963 | else if (os->lma_region != NULL) |
5036 | else if (os->lma_region != NULL) |
4964 | { |
5037 | { |
4965 | bfd_vma lma = os->lma_region->current; |
5038 | bfd_vma lma = os->lma_region->current; |
Line -... | Line 5039... | ||
- | 5039 | ||
- | 5040 | if (os->align_lma_with_input) |
|
- | 5041 | lma += dotdelta; |
|
- | 5042 | else |
|
4966 | 5043 | { |
|
4967 | /* When LMA_REGION is the same as REGION, align the LMA |
5044 | /* When LMA_REGION is the same as REGION, align the LMA |
4968 | as we did for the VMA, possibly including alignment |
5045 | as we did for the VMA, possibly including alignment |
4969 | from the bfd section. If a different region, then |
5046 | from the bfd section. If a different region, then |
4970 | only align according to the value in the output |
5047 | only align according to the value in the output |
4971 | statement unless specified otherwise. */ |
5048 | statement. */ |
4972 | if (os->lma_region != os->region && !os->align_lma_with_input) |
5049 | if (os->lma_region != os->region) |
4973 | section_alignment = os->section_alignment; |
5050 | section_alignment = os->section_alignment; |
4974 | if (section_alignment > 0) |
5051 | if (section_alignment > 0) |
- | 5052 | lma = align_power (lma, section_alignment); |
|
4975 | lma = align_power (lma, section_alignment); |
5053 | } |
4976 | os->bfd_section->lma = lma; |
5054 | os->bfd_section->lma = lma; |
4977 | } |
5055 | } |
4978 | else if (r->last_os != NULL |
5056 | else if (r->last_os != NULL |
4979 | && (os->bfd_section->flags & SEC_ALLOC) != 0) |
5057 | && (os->bfd_section->flags & SEC_ALLOC) != 0) |
Line 5039... | Line 5117... | ||
5039 | && os->bfd_section->vma != os->bfd_section->lma) |
5117 | && os->bfd_section->vma != os->bfd_section->lma) |
5040 | || (r->last_os != NULL |
5118 | || (r->last_os != NULL |
5041 | && dot >= (r->last_os->output_section_statement |
5119 | && dot >= (r->last_os->output_section_statement |
5042 | .bfd_section->vma))) |
5120 | .bfd_section->vma))) |
5043 | && os->lma_region == NULL |
5121 | && os->lma_region == NULL |
5044 | && !link_info.relocatable) |
5122 | && !bfd_link_relocatable (&link_info)) |
5045 | r->last_os = s; |
5123 | r->last_os = s; |
Line 5046... | Line 5124... | ||
5046 | 5124 | ||
5047 | /* .tbss sections effectively have zero size. */ |
5125 | /* .tbss sections effectively have zero size. */ |
5048 | if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5126 | if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5049 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0 |
5127 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0 |
5050 | || link_info.relocatable) |
5128 | || bfd_link_relocatable (&link_info)) |
- | 5129 | dotdelta = TO_ADDR (os->bfd_section->size); |
|
- | 5130 | else |
|
- | 5131 | dotdelta = 0; |
|
Line 5051... | Line 5132... | ||
5051 | dot += TO_ADDR (os->bfd_section->size); |
5132 | dot += dotdelta; |
5052 | 5133 | ||
Line 5053... | Line 5134... | ||
5053 | if (os->update_dot_tree != 0) |
5134 | if (os->update_dot_tree != 0) |
Line 5066... | Line 5147... | ||
5066 | /* Make sure the new address is within the region. */ |
5147 | /* Make sure the new address is within the region. */ |
5067 | os_region_check (os, os->region, os->addr_tree, |
5148 | os_region_check (os, os->region, os->addr_tree, |
5068 | os->bfd_section->vma); |
5149 | os->bfd_section->vma); |
Line 5069... | Line 5150... | ||
5069 | 5150 | ||
5070 | if (os->lma_region != NULL && os->lma_region != os->region |
5151 | if (os->lma_region != NULL && os->lma_region != os->region |
- | 5152 | && ((os->bfd_section->flags & SEC_LOAD) |
|
5071 | && (os->bfd_section->flags & SEC_LOAD)) |
5153 | || os->align_lma_with_input)) |
5072 | { |
- | |
5073 | os->lma_region->current |
5154 | { |
Line 5074... | Line 5155... | ||
5074 | = os->bfd_section->lma + TO_ADDR (os->bfd_section->size); |
5155 | os->lma_region->current = os->bfd_section->lma + dotdelta; |
5075 | 5156 | ||
5076 | if (check_regions) |
5157 | if (check_regions) |
5077 | os_region_check (os, os->lma_region, NULL, |
5158 | os_region_check (os, os->lma_region, NULL, |
Line 5170... | Line 5251... | ||
5170 | einfo (_("%P%F: can't relax section: %E\n")); |
5251 | einfo (_("%P%F: can't relax section: %E\n")); |
5171 | if (again) |
5252 | if (again) |
5172 | *relax = TRUE; |
5253 | *relax = TRUE; |
5173 | } |
5254 | } |
5174 | dot = size_input_section (prev, output_section_statement, |
5255 | dot = size_input_section (prev, output_section_statement, |
5175 | output_section_statement->fill, dot); |
5256 | fill, dot); |
5176 | } |
5257 | } |
5177 | break; |
5258 | break; |
Line 5178... | Line 5259... | ||
5178 | 5259 | ||
5179 | case lang_input_statement_enum: |
5260 | case lang_input_statement_enum: |
Line 5362... | Line 5443... | ||
5362 | 5443 | ||
5363 | one_lang_size_sections_pass (relax, check_regions); |
5444 | one_lang_size_sections_pass (relax, check_regions); |
5364 | if (expld.dataseg.phase == exp_dataseg_end_seen |
5445 | if (expld.dataseg.phase == exp_dataseg_end_seen |
5365 | && link_info.relro && expld.dataseg.relro_end) |
5446 | && link_info.relro && expld.dataseg.relro_end) |
5366 | { |
- | |
5367 | /* If DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END pair was seen, try |
5447 | { |
5368 | to put expld.dataseg.relro on a (common) page boundary. */ |
5448 | bfd_vma initial_base, relro_end, desired_end; |
Line 5369... | Line -... | ||
5369 | bfd_vma min_base, old_base, relro_end, maxpage; |
- | |
5370 | - | ||
5371 | expld.dataseg.phase = exp_dataseg_relro_adjust; |
- | |
5372 | maxpage = expld.dataseg.maxpagesize; |
- | |
5373 | /* MIN_BASE is the absolute minimum address we are allowed to start the |
- | |
5374 | read-write segment (byte before will be mapped read-only). */ |
- | |
5375 | min_base = (expld.dataseg.min_base + maxpage - 1) & ~(maxpage - 1); |
- | |
5376 | /* OLD_BASE is the address for a feasible minimum address which will |
- | |
5377 | still not cause a data overlap inside MAXPAGE causing file offset skip |
- | |
5378 | by MAXPAGE. */ |
- | |
5379 | old_base = expld.dataseg.base; |
- | |
5380 | expld.dataseg.base += (-expld.dataseg.relro_end |
5449 | asection *sec; |
5381 | & (expld.dataseg.pagesize - 1)); |
5450 | |
5382 | /* Compute the expected PT_GNU_RELRO segment end. */ |
5451 | /* Compute the expected PT_GNU_RELRO segment end. */ |
- | 5452 | relro_end = ((expld.dataseg.relro_end + expld.dataseg.pagesize - 1) |
|
- | 5453 | & ~(expld.dataseg.pagesize - 1)); |
|
- | 5454 | ||
- | 5455 | /* Adjust by the offset arg of DATA_SEGMENT_RELRO_END. */ |
|
- | 5456 | desired_end = relro_end - expld.dataseg.relro_offset; |
|
- | 5457 | ||
- | 5458 | /* For sections in the relro segment.. */ |
|
5383 | relro_end = ((expld.dataseg.relro_end + expld.dataseg.pagesize - 1) |
5459 | for (sec = link_info.output_bfd->section_last; sec; sec = sec->prev) |
- | 5460 | if ((sec->flags & SEC_ALLOC) != 0 |
|
5384 | & ~(expld.dataseg.pagesize - 1)); |
5461 | && sec->vma >= expld.dataseg.base |
- | 5462 | && sec->vma < expld.dataseg.relro_end - expld.dataseg.relro_offset) |
|
- | 5463 | { |
|
- | 5464 | /* Where do we want to put this section so that it ends as |
|
- | 5465 | desired? */ |
|
5385 | if (min_base + maxpage < expld.dataseg.base) |
5466 | bfd_vma start, end, bump; |
- | 5467 | ||
- | 5468 | end = start = sec->vma; |
|
- | 5469 | if ((sec->flags & SEC_HAS_CONTENTS) != 0 |
|
- | 5470 | || (sec->flags & SEC_THREAD_LOCAL) == 0) |
|
- | 5471 | end += sec->size; |
|
- | 5472 | bump = desired_end - end; |
|
- | 5473 | /* We'd like to increase START by BUMP, but we must heed |
|
- | 5474 | alignment so the increase might be less than optimum. */ |
|
- | 5475 | start += bump; |
|
5386 | { |
5476 | start &= ~(((bfd_vma) 1 << sec->alignment_power) - 1); |
5387 | expld.dataseg.base -= maxpage; |
5477 | /* This is now the desired end for the previous section. */ |
- | 5478 | desired_end = start; |
|
- | 5479 | } |
|
- | 5480 | ||
- | 5481 | expld.dataseg.phase = exp_dataseg_relro_adjust; |
|
- | 5482 | ASSERT (desired_end >= expld.dataseg.base); |
|
5388 | relro_end -= maxpage; |
5483 | initial_base = expld.dataseg.base; |
5389 | } |
5484 | expld.dataseg.base = desired_end; |
- | 5485 | lang_reset_memory_regions (); |
|
5390 | lang_reset_memory_regions (); |
5486 | one_lang_size_sections_pass (relax, check_regions); |
5391 | one_lang_size_sections_pass (relax, check_regions); |
5487 | |
5392 | if (expld.dataseg.relro_end > relro_end) |
5488 | if (expld.dataseg.relro_end > relro_end) |
5393 | { |
- | |
5394 | /* The alignment of sections between DATA_SEGMENT_ALIGN |
- | |
5395 | and DATA_SEGMENT_RELRO_END caused huge padding to be |
5489 | { |
5396 | inserted at DATA_SEGMENT_RELRO_END. Try to start a bit lower so |
5490 | /* Assignments to dot, or to output section address in a |
5397 | that the section alignments will fit in. */ |
- | |
5398 | asection *sec; |
- | |
5399 | unsigned int max_alignment_power = 0; |
- | |
5400 | - | ||
5401 | /* Find maximum alignment power of sections between |
- | |
5402 | DATA_SEGMENT_ALIGN and DATA_SEGMENT_RELRO_END. */ |
- | |
5403 | for (sec = link_info.output_bfd->sections; sec; sec = sec->next) |
- | |
5404 | if (sec->vma >= expld.dataseg.base |
- | |
5405 | && sec->vma < expld.dataseg.relro_end |
- | |
5406 | && sec->alignment_power > max_alignment_power) |
- | |
5407 | max_alignment_power = sec->alignment_power; |
- | |
5408 | - | ||
5409 | if (((bfd_vma) 1 << max_alignment_power) < expld.dataseg.pagesize) |
- | |
5410 | { |
5491 | user script have increased padding over the original. |
5411 | if (expld.dataseg.base - (1 << max_alignment_power) < old_base) |
- | |
5412 | expld.dataseg.base += expld.dataseg.pagesize; |
5492 | Revert. */ |
5413 | expld.dataseg.base -= (1 << max_alignment_power); |
5493 | expld.dataseg.base = initial_base; |
5414 | lang_reset_memory_regions (); |
5494 | lang_reset_memory_regions (); |
5415 | one_lang_size_sections_pass (relax, check_regions); |
5495 | one_lang_size_sections_pass (relax, check_regions); |
5416 | } |
5496 | } |
5417 | } |
5497 | |
5418 | link_info.relro_start = expld.dataseg.base; |
5498 | link_info.relro_start = expld.dataseg.base; |
5419 | link_info.relro_end = expld.dataseg.relro_end; |
5499 | link_info.relro_end = expld.dataseg.relro_end; |
5420 | } |
5500 | } |
Line 5483... | Line 5563... | ||
5483 | os, os->fill, dot, found_end); |
5563 | os, os->fill, dot, found_end); |
Line 5484... | Line 5564... | ||
5484 | 5564 | ||
5485 | /* .tbss sections effectively have zero size. */ |
5565 | /* .tbss sections effectively have zero size. */ |
5486 | if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5566 | if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0 |
5487 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0 |
5567 | || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0 |
5488 | || link_info.relocatable) |
5568 | || bfd_link_relocatable (&link_info)) |
Line 5489... | Line 5569... | ||
5489 | dot += TO_ADDR (os->bfd_section->size); |
5569 | dot += TO_ADDR (os->bfd_section->size); |
5490 | 5570 | ||
5491 | if (os->update_dot_tree != NULL) |
5571 | if (os->update_dot_tree != NULL) |
Line 5707... | Line 5787... | ||
5707 | static void |
5787 | static void |
5708 | lang_set_startof (void) |
5788 | lang_set_startof (void) |
5709 | { |
5789 | { |
5710 | asection *s; |
5790 | asection *s; |
Line 5711... | Line 5791... | ||
5711 | 5791 | ||
5712 | if (link_info.relocatable) |
5792 | if (bfd_link_relocatable (&link_info)) |
Line 5713... | Line 5793... | ||
5713 | return; |
5793 | return; |
5714 | 5794 | ||
5715 | for (s = link_info.output_bfd->sections; s != NULL; s = s->next) |
5795 | for (s = link_info.output_bfd->sections; s != NULL; s = s->next) |
Line 5747... | Line 5827... | ||
5747 | lang_end (void) |
5827 | lang_end (void) |
5748 | { |
5828 | { |
5749 | struct bfd_link_hash_entry *h; |
5829 | struct bfd_link_hash_entry *h; |
5750 | bfd_boolean warn; |
5830 | bfd_boolean warn; |
Line 5751... | Line 5831... | ||
5751 | 5831 | ||
5752 | if ((link_info.relocatable && !link_info.gc_sections) |
5832 | if ((bfd_link_relocatable (&link_info) && !link_info.gc_sections) |
5753 | || (link_info.shared && !link_info.executable)) |
5833 | || bfd_link_dll (&link_info)) |
5754 | warn = entry_from_cmdline; |
5834 | warn = entry_from_cmdline; |
5755 | else |
5835 | else |
Line 5756... | Line 5836... | ||
5756 | warn = TRUE; |
5836 | warn = TRUE; |
5757 | 5837 | ||
5758 | /* Force the user to specify a root when generating a relocatable with |
5838 | /* Force the user to specify a root when generating a relocatable with |
5759 | --gc-sections. */ |
5839 | --gc-sections. */ |
5760 | if (link_info.gc_sections && link_info.relocatable |
5840 | if (link_info.gc_sections && bfd_link_relocatable (&link_info) |
5761 | && !(entry_from_cmdline || undef_from_cmdline)) |
5841 | && !(entry_from_cmdline || undef_from_cmdline)) |
Line 5762... | Line 5842... | ||
5762 | einfo (_("%P%F: gc-sections requires either an entry or " |
5842 | einfo (_("%P%F: gc-sections requires either an entry or " |
Line 5865... | Line 5945... | ||
5865 | link between differing object formats when the input |
5945 | link between differing object formats when the input |
5866 | file has relocations, because the relocations in the |
5946 | file has relocations, because the relocations in the |
5867 | input format may not have equivalent representations in |
5947 | input format may not have equivalent representations in |
5868 | the output format (and besides BFD does not translate |
5948 | the output format (and besides BFD does not translate |
5869 | relocs for other link purposes than a final link). */ |
5949 | relocs for other link purposes than a final link). */ |
5870 | if ((link_info.relocatable || link_info.emitrelocations) |
5950 | if ((bfd_link_relocatable (&link_info) |
- | 5951 | || link_info.emitrelocations) |
|
5871 | && (compatible == NULL |
5952 | && (compatible == NULL |
5872 | || (bfd_get_flavour (input_bfd) |
5953 | || (bfd_get_flavour (input_bfd) |
5873 | != bfd_get_flavour (link_info.output_bfd))) |
5954 | != bfd_get_flavour (link_info.output_bfd))) |
5874 | && (bfd_get_file_flags (input_bfd) & HAS_RELOC) != 0) |
5955 | && (bfd_get_file_flags (input_bfd) & HAS_RELOC) != 0) |
5875 | { |
5956 | { |
Line 5921... | Line 6002... | ||
5921 | static void |
6002 | static void |
5922 | lang_common (void) |
6003 | lang_common (void) |
5923 | { |
6004 | { |
5924 | if (command_line.inhibit_common_definition) |
6005 | if (command_line.inhibit_common_definition) |
5925 | return; |
6006 | return; |
5926 | if (link_info.relocatable |
6007 | if (bfd_link_relocatable (&link_info) |
5927 | && ! command_line.force_common_definition) |
6008 | && ! command_line.force_common_definition) |
5928 | return; |
6009 | return; |
Line 5929... | Line 6010... | ||
5929 | 6010 | ||
5930 | if (! config.sort_common) |
6011 | if (! config.sort_common) |
Line 5944... | Line 6025... | ||
5944 | else |
6025 | else |
5945 | { |
6026 | { |
5946 | for (power = 0; power <= 4; power++) |
6027 | for (power = 0; power <= 4; power++) |
5947 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
6028 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
Line 5948... | Line 6029... | ||
5948 | 6029 | ||
5949 | power = UINT_MAX; |
6030 | power = (unsigned int) -1; |
5950 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
6031 | bfd_link_hash_traverse (link_info.hash, lang_one_common, &power); |
5951 | } |
6032 | } |
5952 | } |
6033 | } |
Line 6036... | Line 6117... | ||
6036 | } |
6117 | } |
Line 6037... | Line 6118... | ||
6037 | 6118 | ||
6038 | return TRUE; |
6119 | return TRUE; |
Line -... | Line 6120... | ||
- | 6120 | } |
|
- | 6121 | ||
- | 6122 | /* Handle a single orphan section S, placing the orphan into an appropriate |
|
- | 6123 | output section. The effects of the --orphan-handling command line |
|
- | 6124 | option are handled here. */ |
|
- | 6125 | ||
- | 6126 | static void |
|
- | 6127 | ldlang_place_orphan (asection *s) |
|
- | 6128 | { |
|
- | 6129 | if (config.orphan_handling == orphan_handling_discard) |
|
- | 6130 | { |
|
- | 6131 | lang_output_section_statement_type *os; |
|
- | 6132 | os = lang_output_section_statement_lookup (DISCARD_SECTION_NAME, 0, |
|
- | 6133 | TRUE); |
|
- | 6134 | if (os->addr_tree == NULL |
|
- | 6135 | && (bfd_link_relocatable (&link_info) |
|
- | 6136 | || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) |
|
- | 6137 | os->addr_tree = exp_intop (0); |
|
- | 6138 | lang_add_section (&os->children, s, NULL, os); |
|
- | 6139 | } |
|
- | 6140 | else |
|
- | 6141 | { |
|
- | 6142 | lang_output_section_statement_type *os; |
|
- | 6143 | const char *name = s->name; |
|
- | 6144 | int constraint = 0; |
|
- | 6145 | ||
- | 6146 | if (config.orphan_handling == orphan_handling_error) |
|
- | 6147 | einfo ("%X%P: error: unplaced orphan section `%A' from `%B'.\n", |
|
- | 6148 | s, s->owner); |
|
- | 6149 | ||
- | 6150 | if (config.unique_orphan_sections || unique_section_p (s, NULL)) |
|
- | 6151 | constraint = SPECIAL; |
|
- | 6152 | ||
- | 6153 | os = ldemul_place_orphan (s, name, constraint); |
|
- | 6154 | if (os == NULL) |
|
- | 6155 | { |
|
- | 6156 | os = lang_output_section_statement_lookup (name, constraint, TRUE); |
|
- | 6157 | if (os->addr_tree == NULL |
|
- | 6158 | && (bfd_link_relocatable (&link_info) |
|
- | 6159 | || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) |
|
- | 6160 | os->addr_tree = exp_intop (0); |
|
- | 6161 | lang_add_section (&os->children, s, NULL, os); |
|
- | 6162 | } |
|
- | 6163 | ||
- | 6164 | if (config.orphan_handling == orphan_handling_warn) |
|
- | 6165 | einfo ("%P: warning: orphan section `%A' from `%B' being " |
|
- | 6166 | "placed in section `%s'.\n", |
|
- | 6167 | s, s->owner, os->name); |
|
- | 6168 | } |
|
6039 | } |
6169 | } |
6040 | 6170 | ||
6041 | /* Run through the input files and ensure that every input section has |
6171 | /* Run through the input files and ensure that every input section has |
Line 6042... | Line 6172... | ||
6042 | somewhere to go. If one is found without a destination then create |
6172 | somewhere to go. If one is found without a destination then create |
Line 6063... | Line 6193... | ||
6063 | else if (strcmp (s->name, "COMMON") == 0) |
6193 | else if (strcmp (s->name, "COMMON") == 0) |
6064 | { |
6194 | { |
6065 | /* This is a lonely common section which must have |
6195 | /* This is a lonely common section which must have |
6066 | come from an archive. We attach to the section |
6196 | come from an archive. We attach to the section |
6067 | with the wildcard. */ |
6197 | with the wildcard. */ |
6068 | if (! link_info.relocatable |
6198 | if (!bfd_link_relocatable (&link_info) |
6069 | || command_line.force_common_definition) |
6199 | || command_line.force_common_definition) |
6070 | { |
6200 | { |
6071 | if (default_common_section == NULL) |
6201 | if (default_common_section == NULL) |
6072 | default_common_section |
6202 | default_common_section |
6073 | = lang_output_section_statement_lookup (".bss", 0, |
6203 | = lang_output_section_statement_lookup (".bss", 0, |
Line 6075... | Line 6205... | ||
6075 | lang_add_section (&default_common_section->children, s, |
6205 | lang_add_section (&default_common_section->children, s, |
6076 | NULL, default_common_section); |
6206 | NULL, default_common_section); |
6077 | } |
6207 | } |
6078 | } |
6208 | } |
6079 | else |
6209 | else |
6080 | { |
- | |
6081 | const char *name = s->name; |
- | |
6082 | int constraint = 0; |
- | |
6083 | - | ||
6084 | if (config.unique_orphan_sections |
- | |
6085 | || unique_section_p (s, NULL)) |
- | |
6086 | constraint = SPECIAL; |
- | |
6087 | - | ||
6088 | if (!ldemul_place_orphan (s, name, constraint)) |
- | |
6089 | { |
- | |
6090 | lang_output_section_statement_type *os; |
- | |
6091 | os = lang_output_section_statement_lookup (name, |
- | |
6092 | constraint, |
- | |
6093 | TRUE); |
- | |
6094 | if (os->addr_tree == NULL |
- | |
6095 | && (link_info.relocatable |
- | |
6096 | || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) |
- | |
6097 | os->addr_tree = exp_intop (0); |
6210 | ldlang_place_orphan (s); |
6098 | lang_add_section (&os->children, s, NULL, os); |
- | |
6099 | } |
- | |
6100 | } |
- | |
6101 | } |
6211 | } |
6102 | } |
6212 | } |
6103 | } |
6213 | } |
6104 | } |
6214 | } |
Line 6107... | Line 6217... | ||
6107 | lang_set_flags (lang_memory_region_type *ptr, const char *flags, int invert) |
6217 | lang_set_flags (lang_memory_region_type *ptr, const char *flags, int invert) |
6108 | { |
6218 | { |
6109 | flagword *ptr_flags; |
6219 | flagword *ptr_flags; |
Line 6110... | Line 6220... | ||
6110 | 6220 | ||
- | 6221 | ptr_flags = invert ? &ptr->not_flags : &ptr->flags; |
|
6111 | ptr_flags = invert ? &ptr->not_flags : &ptr->flags; |
6222 | |
6112 | while (*flags) |
6223 | while (*flags) |
6113 | { |
6224 | { |
6114 | switch (*flags) |
6225 | switch (*flags) |
- | 6226 | { |
|
- | 6227 | /* PR 17900: An exclamation mark in the attributes reverses |
|
- | 6228 | the sense of any of the attributes that follow. */ |
|
- | 6229 | case '!': |
|
- | 6230 | invert = ! invert; |
|
- | 6231 | ptr_flags = invert ? &ptr->not_flags : &ptr->flags; |
|
- | 6232 | break; |
|
6115 | { |
6233 | |
6116 | case 'A': case 'a': |
6234 | case 'A': case 'a': |
6117 | *ptr_flags |= SEC_ALLOC; |
6235 | *ptr_flags |= SEC_ALLOC; |
Line 6118... | Line 6236... | ||
6118 | break; |
6236 | break; |
Line 6133... | Line 6251... | ||
6133 | case 'I': case 'i': |
6251 | case 'I': case 'i': |
6134 | *ptr_flags |= SEC_LOAD; |
6252 | *ptr_flags |= SEC_LOAD; |
6135 | break; |
6253 | break; |
Line 6136... | Line 6254... | ||
6136 | 6254 | ||
6137 | default: |
6255 | default: |
6138 | einfo (_("%P%F: invalid syntax in flags\n")); |
6256 | einfo (_("%P%F: invalid character %c (%d) in flags\n"), * flags, * flags); |
6139 | break; |
6257 | break; |
6140 | } |
6258 | } |
6141 | flags++; |
6259 | flags++; |
6142 | } |
6260 | } |
Line 6176... | Line 6294... | ||
6176 | (lang_statement_union_type *) entry, |
6294 | (lang_statement_union_type *) entry, |
6177 | &entry->next); |
6295 | &entry->next); |
Line 6178... | Line 6296... | ||
6178 | 6296 | ||
6179 | /* The BFD linker needs to have a list of all input BFDs involved in |
6297 | /* The BFD linker needs to have a list of all input BFDs involved in |
6180 | a link. */ |
6298 | a link. */ |
6181 | ASSERT (entry->the_bfd->link_next == NULL); |
6299 | ASSERT (entry->the_bfd->link.next == NULL); |
Line 6182... | Line 6300... | ||
6182 | ASSERT (entry->the_bfd != link_info.output_bfd); |
6300 | ASSERT (entry->the_bfd != link_info.output_bfd); |
6183 | 6301 | ||
6184 | *link_info.input_bfds_tail = entry->the_bfd; |
6302 | *link_info.input_bfds_tail = entry->the_bfd; |
6185 | link_info.input_bfds_tail = &entry->the_bfd->link_next; |
6303 | link_info.input_bfds_tail = &entry->the_bfd->link.next; |
Line 6186... | Line 6304... | ||
6186 | entry->the_bfd->usrdata = entry; |
6304 | entry->the_bfd->usrdata = entry; |
6187 | bfd_set_gp_size (entry->the_bfd, g_switch_value); |
6305 | bfd_set_gp_size (entry->the_bfd, g_switch_value); |
Line 6277... | Line 6395... | ||
6277 | { |
6395 | { |
6278 | lang_output_statement_type *new_stmt; |
6396 | lang_output_statement_type *new_stmt; |
Line 6279... | Line 6397... | ||
6279 | 6397 | ||
6280 | new_stmt = new_stat (lang_output_statement, stat_ptr); |
6398 | new_stmt = new_stat (lang_output_statement, stat_ptr); |
6281 | new_stmt->name = output_filename; |
- | |
6282 | 6399 | new_stmt->name = output_filename; |
|
Line 6283... | Line 6400... | ||
6283 | } |
6400 | } |
Line 6284... | Line 6401... | ||
6284 | 6401 | ||
Line 6364... | Line 6481... | ||
6364 | lang_gc_sections_1 (statement_list.head); |
6481 | lang_gc_sections_1 (statement_list.head); |
Line 6365... | Line 6482... | ||
6365 | 6482 | ||
6366 | /* SEC_EXCLUDE is ignored when doing a relocatable link, except in |
6483 | /* SEC_EXCLUDE is ignored when doing a relocatable link, except in |
6367 | the special case of debug info. (See bfd/stabs.c) |
6484 | the special case of debug info. (See bfd/stabs.c) |
6368 | Twiddle the flag here, to simplify later linker code. */ |
6485 | Twiddle the flag here, to simplify later linker code. */ |
6369 | if (link_info.relocatable) |
6486 | if (bfd_link_relocatable (&link_info)) |
6370 | { |
6487 | { |
6371 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
6488 | LANG_FOR_EACH_INPUT_STATEMENT (f) |
6372 | { |
6489 | { |
6373 | asection *sec; |
6490 | asection *sec; |
Line 6607... | Line 6724... | ||
6607 | /* Create a bfd for each input file. */ |
6724 | /* Create a bfd for each input file. */ |
6608 | current_target = default_target; |
6725 | current_target = default_target; |
6609 | open_input_bfds (statement_list.head, OPEN_BFD_NORMAL); |
6726 | open_input_bfds (statement_list.head, OPEN_BFD_NORMAL); |
Line 6610... | Line 6727... | ||
6610 | 6727 | ||
6611 | #ifdef ENABLE_PLUGINS |
6728 | #ifdef ENABLE_PLUGINS |
6612 | if (plugin_active_plugins_p ()) |
6729 | if (link_info.lto_plugin_active) |
6613 | { |
6730 | { |
6614 | lang_statement_list_type added; |
6731 | lang_statement_list_type added; |
Line 6615... | Line 6732... | ||
6615 | lang_statement_list_type files, inputfiles; |
6732 | lang_statement_list_type files, inputfiles; |
Line 6626... | Line 6743... | ||
6626 | inputfiles = input_file_chain; |
6743 | inputfiles = input_file_chain; |
6627 | if (plugin_call_all_symbols_read ()) |
6744 | if (plugin_call_all_symbols_read ()) |
6628 | einfo (_("%P%F: %s: plugin reported error after all symbols read\n"), |
6745 | einfo (_("%P%F: %s: plugin reported error after all symbols read\n"), |
6629 | plugin_error_plugin ()); |
6746 | plugin_error_plugin ()); |
6630 | /* Open any newly added files, updating the file chains. */ |
6747 | /* Open any newly added files, updating the file chains. */ |
6631 | link_info.loading_lto_outputs = TRUE; |
- | |
6632 | open_input_bfds (*added.tail, OPEN_BFD_NORMAL); |
6748 | open_input_bfds (*added.tail, OPEN_BFD_NORMAL); |
6633 | /* Restore the global list pointer now they have all been added. */ |
6749 | /* Restore the global list pointer now they have all been added. */ |
6634 | lang_list_remove_tail (stat_ptr, &added); |
6750 | lang_list_remove_tail (stat_ptr, &added); |
6635 | /* And detach the fresh ends of the file lists. */ |
6751 | /* And detach the fresh ends of the file lists. */ |
6636 | lang_list_remove_tail (&file_chain, &files); |
6752 | lang_list_remove_tail (&file_chain, &files); |
Line 6667... | Line 6783... | ||
6667 | #endif /* ENABLE_PLUGINS */ |
6783 | #endif /* ENABLE_PLUGINS */ |
Line 6668... | Line 6784... | ||
6668 | 6784 | ||
6669 | link_info.gc_sym_list = &entry_symbol; |
6785 | link_info.gc_sym_list = &entry_symbol; |
6670 | if (entry_symbol.name == NULL) |
6786 | if (entry_symbol.name == NULL) |
- | 6787 | link_info.gc_sym_list = ldlang_undef_chain_list_head; |
|
- | 6788 | if (link_info.init_function != NULL) |
|
- | 6789 | { |
|
- | 6790 | struct bfd_sym_chain *sym |
|
- | 6791 | = (struct bfd_sym_chain *) stat_alloc (sizeof (*sym)); |
|
- | 6792 | sym->next = link_info.gc_sym_list; |
|
- | 6793 | sym->name = link_info.init_function; |
|
- | 6794 | link_info.gc_sym_list = sym; |
|
- | 6795 | } |
|
- | 6796 | if (link_info.fini_function != NULL) |
|
- | 6797 | { |
|
- | 6798 | struct bfd_sym_chain *sym |
|
- | 6799 | = (struct bfd_sym_chain *) stat_alloc (sizeof (*sym)); |
|
- | 6800 | sym->next = link_info.gc_sym_list; |
|
- | 6801 | sym->name = link_info.fini_function; |
|
- | 6802 | link_info.gc_sym_list = sym; |
|
Line 6671... | Line 6803... | ||
6671 | link_info.gc_sym_list = ldlang_undef_chain_list_head; |
6803 | } |
- | 6804 | ||
- | 6805 | ldemul_after_open (); |
|
Line 6672... | Line 6806... | ||
6672 | 6806 | if (config.map_file != NULL) |
|
Line 6673... | Line 6807... | ||
6673 | ldemul_after_open (); |
6807 | lang_print_asneeded (); |
6674 | 6808 | ||
Line 6690... | Line 6824... | ||
6690 | ldctor_build_sets (); |
6824 | ldctor_build_sets (); |
Line 6691... | Line 6825... | ||
6691 | 6825 | ||
6692 | /* PR 13683: We must rerun the assignments prior to running garbage |
6826 | /* PR 13683: We must rerun the assignments prior to running garbage |
6693 | collection in order to make sure that all symbol aliases are resolved. */ |
6827 | collection in order to make sure that all symbol aliases are resolved. */ |
6694 | lang_do_assignments (lang_mark_phase_enum); |
- | |
Line 6695... | Line 6828... | ||
6695 | expld.phase = lang_first_phase_enum; |
6828 | lang_do_assignments (lang_mark_phase_enum); |
6696 | 6829 | ||
Line 6697... | Line 6830... | ||
6697 | /* Remove unreferenced sections if asked to. */ |
6830 | lang_do_memory_regions(); |
6698 | lang_gc_sections (); |
6831 | expld.phase = lang_first_phase_enum; |
Line -... | Line 6832... | ||
- | 6832 | ||
- | 6833 | /* Size up the common data. */ |
|
- | 6834 | lang_common (); |
|
6699 | 6835 | ||
6700 | /* Size up the common data. */ |
6836 | /* Remove unreferenced sections if asked to. */ |
Line 6701... | Line 6837... | ||
6701 | lang_common (); |
6837 | lang_gc_sections (); |
6702 | 6838 | ||
Line 6711... | Line 6847... | ||
6711 | process_insert_statements (); |
6847 | process_insert_statements (); |
Line 6712... | Line 6848... | ||
6712 | 6848 | ||
6713 | /* Find any sections not attached explicitly and handle them. */ |
6849 | /* Find any sections not attached explicitly and handle them. */ |
Line 6714... | Line 6850... | ||
6714 | lang_place_orphans (); |
6850 | lang_place_orphans (); |
6715 | 6851 | ||
6716 | if (! link_info.relocatable) |
6852 | if (!bfd_link_relocatable (&link_info)) |
Line 6717... | Line 6853... | ||
6717 | { |
6853 | { |
6718 | asection *found; |
6854 | asection *found; |
Line 6742... | Line 6878... | ||
6742 | /* We must record the program headers before we try to fix the |
6878 | /* We must record the program headers before we try to fix the |
6743 | section positions, since they will affect SIZEOF_HEADERS. */ |
6879 | section positions, since they will affect SIZEOF_HEADERS. */ |
6744 | lang_record_phdrs (); |
6880 | lang_record_phdrs (); |
Line 6745... | Line 6881... | ||
6745 | 6881 | ||
6746 | /* Check relro sections. */ |
6882 | /* Check relro sections. */ |
6747 | if (link_info.relro && ! link_info.relocatable) |
6883 | if (link_info.relro && !bfd_link_relocatable (&link_info)) |
Line 6748... | Line 6884... | ||
6748 | lang_find_relro_sections (); |
6884 | lang_find_relro_sections (); |
6749 | 6885 | ||
Line 6761... | Line 6897... | ||
6761 | of all the symbols. */ |
6897 | of all the symbols. */ |
6762 | lang_do_assignments (lang_final_phase_enum); |
6898 | lang_do_assignments (lang_final_phase_enum); |
Line 6763... | Line 6899... | ||
6763 | 6899 | ||
Line -... | Line 6900... | ||
- | 6900 | ldemul_finish (); |
|
- | 6901 | ||
- | 6902 | /* Convert absolute symbols to section relative. */ |
|
6764 | ldemul_finish (); |
6903 | ldexp_finalize_syms (); |
6765 | 6904 | ||
6766 | /* Make sure that the section addresses make sense. */ |
6905 | /* Make sure that the section addresses make sense. */ |
Line -... | Line 6906... | ||
- | 6906 | if (command_line.check_section_addresses) |
|
- | 6907 | lang_check_section_addresses (); |
|
- | 6908 | ||
6767 | if (command_line.check_section_addresses) |
6909 | /* Check any required symbols are known. */ |
6768 | lang_check_section_addresses (); |
6910 | ldlang_check_require_defined_symbols (); |
Line 6769... | Line 6911... | ||
6769 | 6911 | ||
Line 7953... | Line 8095... | ||
7953 | lreg = lang_new_vers_pattern (NULL, "*", NULL, FALSE); |
8095 | lreg = lang_new_vers_pattern (NULL, "*", NULL, FALSE); |
7954 | lang_register_vers_node (command_line.version_exports_section, |
8096 | lang_register_vers_node (command_line.version_exports_section, |
7955 | lang_new_vers_node (greg, lreg), NULL); |
8097 | lang_new_vers_node (greg, lreg), NULL); |
7956 | } |
8098 | } |
Line -... | Line 8099... | ||
- | 8099 | ||
- | 8100 | /* Evaluate LENGTH and ORIGIN parts of MEMORY spec */ |
|
- | 8101 | ||
- | 8102 | static void |
|
- | 8103 | lang_do_memory_regions (void) |
|
- | 8104 | { |
|
- | 8105 | lang_memory_region_type *r = lang_memory_region_list; |
|
- | 8106 | ||
- | 8107 | for (; r != NULL; r = r->next) |
|
- | 8108 | { |
|
- | 8109 | if (r->origin_exp) |
|
- | 8110 | { |
|
- | 8111 | exp_fold_tree_no_dot (r->origin_exp); |
|
- | 8112 | if (expld.result.valid_p) |
|
- | 8113 | { |
|
- | 8114 | r->origin = expld.result.value; |
|
- | 8115 | r->current = r->origin; |
|
- | 8116 | } |
|
- | 8117 | else |
|
- | 8118 | einfo (_("%F%P: invalid origin for memory region %s\n"), r->name_list.name); |
|
- | 8119 | } |
|
- | 8120 | if (r->length_exp) |
|
- | 8121 | { |
|
- | 8122 | exp_fold_tree_no_dot (r->length_exp); |
|
- | 8123 | if (expld.result.valid_p) |
|
- | 8124 | r->length = expld.result.value; |
|
- | 8125 | else |
|
- | 8126 | einfo (_("%F%P: invalid length for memory region %s\n"), r->name_list.name); |
|
- | 8127 | } |
|
- | 8128 | } |
|
- | 8129 | } |
|
7957 | 8130 | ||
7958 | void |
8131 | void |
7959 | lang_add_unique (const char *name) |
8132 | lang_add_unique (const char *name) |
7960 | { |
8133 | { |
Line 8062... | Line 8235... | ||
8062 | einfo (_("%X%P: unknown feature `%s'\n"), p); |
8235 | einfo (_("%X%P: unknown feature `%s'\n"), p); |
8063 | *q = sep; |
8236 | *q = sep; |
8064 | p = q; |
8237 | p = q; |
8065 | } |
8238 | } |
8066 | }>>>>>=><=>>>>=>>>=>>=>><>>><>>><>>>>=>>>>=>=>=>>>>>>>>>>>>>>>>>><>>>>>>>=>><>>> |
8239 | } |
- | 8240 | ||
- | 8241 | /* Pretty print memory amount. */ |
|
- | 8242 | ||
- | 8243 | static void |
|
- | 8244 | lang_print_memory_size (bfd_vma sz) |
|
- | 8245 | { |
|
- | 8246 | if ((sz & 0x3fffffff) == 0) |
|
- | 8247 | printf ("%10" BFD_VMA_FMT "u GB", sz >> 30); |
|
- | 8248 | else if ((sz & 0xfffff) == 0) |
|
- | 8249 | printf ("%10" BFD_VMA_FMT "u MB", sz >> 20); |
|
- | 8250 | else if ((sz & 0x3ff) == 0) |
|
- | 8251 | printf ("%10" BFD_VMA_FMT "u KB", sz >> 10); |
|
- | 8252 | else |
|
- | 8253 | printf (" %10" BFD_VMA_FMT "u B", sz); |
|
- | 8254 | } |
|
- | 8255 | ||
- | 8256 | /* Implement --print-memory-usage: disply per region memory usage. */ |
|
- | 8257 | ||
- | 8258 | void |
|
- | 8259 | lang_print_memory_usage (void) |
|
- | 8260 | { |
|
- | 8261 | lang_memory_region_type *r; |
|
- | 8262 | ||
- | 8263 | printf ("Memory region Used Size Region Size %%age Used\n"); |
|
- | 8264 | for (r = lang_memory_region_list; r->next != NULL; r = r->next) |
|
- | 8265 | { |
|
- | 8266 | bfd_vma used_length = r->current - r->origin; |
|
- | 8267 | double percent; |
|
- | 8268 | ||
- | 8269 | printf ("%16s: ",r->name_list.name); |
|
- | 8270 | lang_print_memory_size (used_length); |
|
- | 8271 | lang_print_memory_size ((bfd_vma) r->length); |
|
- | 8272 | ||
- | 8273 | percent = used_length * 100.0 / r->length; |
|
- | 8274 | ||
- | 8275 | printf (" %6.2f%%\n", percent); |
|
- | 8276 | } |
|
- | 8277 | }>>>>>=><=>>>>=>>>=>>=>><>>>=>>>>=>=>=>>>>>>>>>>>>>>>>>>><>>>>>>>>=>><>>> |