GNU Binutils with patches for OS216
修訂 | cae64165f47b64898c4f1982d294862cfae89a47 (tree) |
---|---|
時間 | 2020-06-16 03:45:02 |
作者 | Roland McGrath <mcgrathr@goog...> |
Commiter | Roland McGrath |
gold, ld: Implement -z start-stop-visibility=... option.
gold/
Implement -z start-stop-visibility=... option.
* options.h (class General_options): Handle -z start-stop-visibility=.
(General_options::start_stop_visibility_enum): New public method.
(General_options::set_start_stop_visibility_enum): New private method.
(General_options::start_stop_visibility_enum_): New private member.
* options.cc (General_options::General_options): Add initializer.
(General_options::finalize): Set this->start_stop_visibility_enum_
from string value.
* layout.cc (Layout::define_section_symbols): Use option setting.
bfd/
* elflink.c (bfd_elf_define_start_stop): Use start_stop_visibility
field of bfd_link_info.
include/
* bfdlink.h (struct bfd_link_info): New field start_stop_visibility.
ld/
* NEWS: Mention -z start-stop-visibility=... option for ELF.
* ld.texi (Options): Document -z start-stop-visibility=... option.
* ldmain.c (main): Initialize link_info.start_stop_visibility.
* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
Parse -z start-stop-visibility=... option.
@@ -1,3 +1,8 @@ | ||
1 | +2020-06-15 Roland McGrath <mcgrathr@google.com> | |
2 | + | |
3 | + * elflink.c (bfd_elf_define_start_stop): Use start_stop_visibility | |
4 | + field of bfd_link_info. | |
5 | + | |
1 | 6 | 2020-06-15 Alan Modra <amodra@gmail.com> |
2 | 7 | |
3 | 8 | * config.bfd: Obsolete powerpcle-*-pe targets. |
@@ -346,7 +351,7 @@ | ||
346 | 351 | (aout_link_add_symbols): e517df3dbf7 PR 19629 - Check for out of |
347 | 352 | range string table offsets. |
348 | 353 | 531336e3a0b PR 20909 - Fix off-by-one error in check for an |
349 | - illegal string offset. | |
354 | + illegal string offset. | |
350 | 355 | (aout_link_includes_newfunc): Add comment. |
351 | 356 | (pdp11_aout_link_input_section): ad756e3f9e6 - Return with an error |
352 | 357 | on unexpected relocation type rather than ASSERT. |
@@ -14837,7 +14837,8 @@ bfd_elf_define_start_stop (struct bfd_link_info *info, | ||
14837 | 14837 | else |
14838 | 14838 | { |
14839 | 14839 | if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
14840 | - h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_PROTECTED; | |
14840 | + h->other = ((h->other & ~ELF_ST_VISIBILITY (-1)) | |
14841 | + | info->start_stop_visibility); | |
14841 | 14842 | if (was_dynamic) |
14842 | 14843 | bfd_elf_link_record_dynamic_symbol (info, h); |
14843 | 14844 | } |
@@ -1,3 +1,15 @@ | ||
1 | +2020-06-15 Roland McGrath <mcgrathr@google.com> | |
2 | + | |
3 | + Implement -z start-stop-visibility=... option. | |
4 | + * options.h (class General_options): Handle -z start-stop-visibility=. | |
5 | + (General_options::start_stop_visibility_enum): New public method. | |
6 | + (General_options::set_start_stop_visibility_enum): New private method. | |
7 | + (General_options::start_stop_visibility_enum_): New private member. | |
8 | + * options.cc (General_options::General_options): Add initializer. | |
9 | + (General_options::finalize): Set this->start_stop_visibility_enum_ | |
10 | + from string value. | |
11 | + * layout.cc (Layout::define_section_symbols): Use option setting. | |
12 | + | |
1 | 13 | 2020-06-06 Alan Modra <amodra@gmail.com> |
2 | 14 | |
3 | 15 | * powerpc.cc: Update throughout for reloc renaming. |
@@ -2474,6 +2474,7 @@ Layout::create_initial_dynamic_sections(Symbol_table* symtab) | ||
2474 | 2474 | void |
2475 | 2475 | Layout::define_section_symbols(Symbol_table* symtab) |
2476 | 2476 | { |
2477 | + const elfcpp::STV visibility = parameters->options().start_stop_visibility_enum(); | |
2477 | 2478 | for (Section_list::const_iterator p = this->section_list_.begin(); |
2478 | 2479 | p != this->section_list_.end(); |
2479 | 2480 | ++p) |
@@ -2495,7 +2496,7 @@ Layout::define_section_symbols(Symbol_table* symtab) | ||
2495 | 2496 | 0, // symsize |
2496 | 2497 | elfcpp::STT_NOTYPE, |
2497 | 2498 | elfcpp::STB_GLOBAL, |
2498 | - elfcpp::STV_PROTECTED, | |
2499 | + visibility, | |
2499 | 2500 | 0, // nonvis |
2500 | 2501 | false, // offset_is_from_end |
2501 | 2502 | true); // only_if_ref |
@@ -2508,7 +2509,7 @@ Layout::define_section_symbols(Symbol_table* symtab) | ||
2508 | 2509 | 0, // symsize |
2509 | 2510 | elfcpp::STT_NOTYPE, |
2510 | 2511 | elfcpp::STB_GLOBAL, |
2511 | - elfcpp::STV_PROTECTED, | |
2512 | + visibility, | |
2512 | 2513 | 0, // nonvis |
2513 | 2514 | true, // offset_is_from_end |
2514 | 2515 | true); // only_if_ref |
@@ -997,7 +997,8 @@ General_options::General_options() | ||
997 | 997 | fix_v4bx_(FIX_V4BX_NONE), |
998 | 998 | endianness_(ENDIANNESS_NOT_SET), |
999 | 999 | discard_locals_(DISCARD_SEC_MERGE), |
1000 | - orphan_handling_enum_(ORPHAN_PLACE) | |
1000 | + orphan_handling_enum_(ORPHAN_PLACE), | |
1001 | + start_stop_visibility_enum_(elfcpp::STV_PROTECTED) | |
1001 | 1002 | { |
1002 | 1003 | // Turn off option registration once construction is complete. |
1003 | 1004 | gold::options::ready_to_register = false; |
@@ -1169,6 +1170,19 @@ General_options::finalize() | ||
1169 | 1170 | this->set_orphan_handling_enum(ORPHAN_ERROR); |
1170 | 1171 | } |
1171 | 1172 | |
1173 | + // Parse the -z start-stop-visibility argument. | |
1174 | + if (this->user_set_start_stop_visibility()) | |
1175 | + { | |
1176 | + if (strcmp(this->start_stop_visibility(), "default") == 0) | |
1177 | + this->set_start_stop_visibility_enum(elfcpp::STV_DEFAULT); | |
1178 | + else if (strcmp(this->start_stop_visibility(), "internal") == 0) | |
1179 | + this->set_start_stop_visibility_enum(elfcpp::STV_INTERNAL); | |
1180 | + else if (strcmp(this->start_stop_visibility(), "hidden") == 0) | |
1181 | + this->set_start_stop_visibility_enum(elfcpp::STV_HIDDEN); | |
1182 | + else if (strcmp(this->start_stop_visibility(), "protected") == 0) | |
1183 | + this->set_start_stop_visibility_enum(elfcpp::STV_PROTECTED); | |
1184 | + } | |
1185 | + | |
1172 | 1186 | // -M is equivalent to "-Map -". |
1173 | 1187 | if (this->print_map() && !this->user_set_Map()) |
1174 | 1188 | { |
@@ -1500,6 +1500,11 @@ class General_options | ||
1500 | 1500 | N_("Don't mark variables read-only after relocation")); |
1501 | 1501 | DEFINE_uint64(stack_size, options::DASH_Z, '\0', 0, |
1502 | 1502 | N_("Set PT_GNU_STACK segment p_memsz to SIZE"), N_("SIZE")); |
1503 | + DEFINE_enum(start_stop_visibility, options::DASH_Z, '\0', "protected", | |
1504 | + N_("ELF symbol visibility for synthesized " | |
1505 | + "__start_* and __stop_* symbols"), | |
1506 | + ("[default,internal,hidden,protected]"), | |
1507 | + {"default", "internal", "hidden", "protected"}); | |
1503 | 1508 | DEFINE_bool(text, options::DASH_Z, '\0', false, |
1504 | 1509 | N_("Do not permit relocations in read-only segments"), |
1505 | 1510 | N_("Permit relocations in read-only segments")); |
@@ -1750,6 +1755,10 @@ class General_options | ||
1750 | 1755 | orphan_handling_enum() const |
1751 | 1756 | { return this->orphan_handling_enum_; } |
1752 | 1757 | |
1758 | + elfcpp::STV | |
1759 | + start_stop_visibility_enum() const | |
1760 | + { return this->start_stop_visibility_enum_; } | |
1761 | + | |
1753 | 1762 | private: |
1754 | 1763 | // Don't copy this structure. |
1755 | 1764 | General_options(const General_options&); |
@@ -1809,6 +1818,10 @@ class General_options | ||
1809 | 1818 | set_orphan_handling_enum(Orphan_handling value) |
1810 | 1819 | { this->orphan_handling_enum_ = value; } |
1811 | 1820 | |
1821 | + void | |
1822 | + set_start_stop_visibility_enum(elfcpp::STV value) | |
1823 | + { this->start_stop_visibility_enum_ = value; } | |
1824 | + | |
1812 | 1825 | // These are called by finalize() to set up the search-path correctly. |
1813 | 1826 | void |
1814 | 1827 | add_to_library_path_with_sysroot(const std::string& arg) |
@@ -1876,6 +1889,8 @@ class General_options | ||
1876 | 1889 | std::vector<Position_dependent_options*> options_stack_; |
1877 | 1890 | // Orphan handling option, decoded to an enum value. |
1878 | 1891 | Orphan_handling orphan_handling_enum_; |
1892 | + // Symbol visibility for __start_* / __stop_* magic symbols. | |
1893 | + elfcpp::STV start_stop_visibility_enum_; | |
1879 | 1894 | }; |
1880 | 1895 | |
1881 | 1896 | // The position-dependent options. We use this to store the state of |
@@ -1,3 +1,7 @@ | ||
1 | +2020-06-12 Roland McGrath <mcgrathr@google.com> | |
2 | + | |
3 | + * bfdlink.h (struct bfd_link_info): New field start_stop_visibility. | |
4 | + | |
1 | 5 | 2020-06-12 Nelson Chu <nelson.chu@sifive.com> |
2 | 6 | |
3 | 7 | * opcode/riscv-opc.h: Update the defined versions of CSR from |
@@ -542,10 +542,10 @@ struct bfd_link_info | ||
542 | 542 | Normally these optimizations are disabled by default but some targets |
543 | 543 | prefer to enable them by default. So this field is a tri-state variable. |
544 | 544 | The values are: |
545 | - | |
545 | + | |
546 | 546 | zero: Enable the optimizations (either from --relax being specified on |
547 | 547 | the command line or the backend's before_allocation emulation function. |
548 | - | |
548 | + | |
549 | 549 | positive: The user has requested that these optimizations be disabled. |
550 | 550 | (Via the --no-relax command line option). |
551 | 551 |
@@ -649,6 +649,9 @@ struct bfd_link_info | ||
649 | 649 | /* May be used to set DT_FLAGS_1 for ELF. */ |
650 | 650 | bfd_vma flags_1; |
651 | 651 | |
652 | + /* May be used to set ELF visibility for __start_* / __stop_. */ | |
653 | + unsigned int start_stop_visibility; | |
654 | + | |
652 | 655 | /* Start and end of RELRO region. */ |
653 | 656 | bfd_vma relro_start, relro_end; |
654 | 657 |
@@ -1,3 +1,11 @@ | ||
1 | +2020-06-15 Roland McGrath <mcgrathr@google.com> | |
2 | + | |
3 | + * NEWS: Mention -z start-stop-visibility=... option for ELF. | |
4 | + * ld.texi (Options): Document -z start-stop-visibility=... option. | |
5 | + * ldmain.c (main): Initialize link_info.start_stop_visibility. | |
6 | + * emultempl/elf.em (gld${EMULATION_NAME}_handle_option): | |
7 | + Parse -z start-stop-visibility=... option. | |
8 | + | |
1 | 9 | 2020-06-15 Alan Modra <amodra@gmail.com> |
2 | 10 | |
3 | 11 | * testsuite/ld-scripts/include.exp: Don't load ld-lib.exp. |
@@ -25,6 +25,9 @@ | ||
25 | 25 | searched relative to the directory of the linker script before other search |
26 | 26 | paths. |
27 | 27 | |
28 | +* Add ELF linker command-line option `-z start-stop-visibility=...' to control | |
29 | + the visibility of synthetic `__start_SECNAME` and `__stop_SECNAME` symbols. | |
30 | + | |
28 | 31 | Changes in 2.34: |
29 | 32 | |
30 | 33 | * The ld check for "PHDR segment not covered by LOAD segment" is more |
@@ -749,6 +749,21 @@ fragment <<EOF | ||
749 | 749 | { |
750 | 750 | link_info.flags_1 |= DF_1_GLOBAUDIT; |
751 | 751 | } |
752 | + else if (CONST_STRNEQ (optarg, "start-stop-visibility=")) | |
753 | + { | |
754 | + if (strcmp (optarg, "start-stop-visibility=default") == 0) | |
755 | + link_info.start_stop_visibility = STV_DEFAULT; | |
756 | + else if (strcmp (optarg, "start-stop-visibility=internal") == 0) | |
757 | + link_info.start_stop_visibility = STV_INTERNAL; | |
758 | + else if (strcmp (optarg, "start-stop-visibility=hidden") == 0) | |
759 | + link_info.start_stop_visibility = STV_HIDDEN; | |
760 | + else if (strcmp (optarg, "start-stop-visibility=protected") == 0) | |
761 | + link_info.start_stop_visibility = STV_PROTECTED; | |
762 | + else | |
763 | + einfo (_("%F%P: invalid visibility in \`-z %s'; " | |
764 | + "must be default, internal, hidden, or protected"), | |
765 | + optarg); | |
766 | + } | |
752 | 767 | EOF |
753 | 768 | |
754 | 769 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then |
@@ -1373,6 +1373,19 @@ Specify a stack size for an ELF @code{PT_GNU_STACK} segment. | ||
1373 | 1373 | Specifying zero will override any default non-zero sized |
1374 | 1374 | @code{PT_GNU_STACK} segment creation. |
1375 | 1375 | |
1376 | +@item start-stop-visibility=@var{value} | |
1377 | +@cindex visibility | |
1378 | +@cindex ELF symbol visibility | |
1379 | +Specify the ELF symbol visibility for synthesized | |
1380 | +@code{__start_SECNAME} and @code{__stop_SECNAME} symbols (@pxref{Input | |
1381 | +Section Example}). @var{value} must be exactly @samp{default}, | |
1382 | +@samp{internal}, @samp{hidden}, or @samp{protected}. If no @samp{-z | |
1383 | +start-stop-visibility} option is given, @samp{protected} is used for | |
1384 | +compatibility with historical practice. However, it's highly | |
1385 | +recommended to use @samp{-z start-stop-visibility=hidden} in new | |
1386 | +programs and shared libraries so that these symbols are not exported | |
1387 | +between shared objects, which is not usually what's intended. | |
1388 | + | |
1376 | 1389 | @item text |
1377 | 1390 | @itemx notext |
1378 | 1391 | @itemx textoff |
@@ -27,6 +27,7 @@ | ||
27 | 27 | #include "bfdlink.h" |
28 | 28 | #include "ctf-api.h" |
29 | 29 | #include "filenames.h" |
30 | +#include "elf/common.h" | |
30 | 31 | |
31 | 32 | #include "ld.h" |
32 | 33 | #include "ldmain.h" |
@@ -307,6 +308,7 @@ main (int argc, char **argv) | ||
307 | 308 | #ifdef DEFAULT_NEW_DTAGS |
308 | 309 | link_info.new_dtags = DEFAULT_NEW_DTAGS; |
309 | 310 | #endif |
311 | + link_info.start_stop_visibility = STV_PROTECTED; | |
310 | 312 | |
311 | 313 | ldfile_add_arch (""); |
312 | 314 | emulation = get_emulation (argc, argv); |