• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

GNU Binutils with patches for OS216


Commit MetaInfo

修訂cae64165f47b64898c4f1982d294862cfae89a47 (tree)
時間2020-06-16 03:45:02
作者Roland McGrath <mcgrathr@goog...>
CommiterRoland McGrath

Log Message

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.

Change Summary

差異

--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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+
16 2020-06-15 Alan Modra <amodra@gmail.com>
27
38 * config.bfd: Obsolete powerpcle-*-pe targets.
@@ -346,7 +351,7 @@
346351 (aout_link_add_symbols): e517df3dbf7 PR 19629 - Check for out of
347352 range string table offsets.
348353 531336e3a0b PR 20909 - Fix off-by-one error in check for an
349- illegal string offset.
354+ illegal string offset.
350355 (aout_link_includes_newfunc): Add comment.
351356 (pdp11_aout_link_input_section): ad756e3f9e6 - Return with an error
352357 on unexpected relocation type rather than ASSERT.
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -14837,7 +14837,8 @@ bfd_elf_define_start_stop (struct bfd_link_info *info,
1483714837 else
1483814838 {
1483914839 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);
1484114842 if (was_dynamic)
1484214843 bfd_elf_link_record_dynamic_symbol (info, h);
1484314844 }
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -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+
113 2020-06-06 Alan Modra <amodra@gmail.com>
214
315 * powerpc.cc: Update throughout for reloc renaming.
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -2474,6 +2474,7 @@ Layout::create_initial_dynamic_sections(Symbol_table* symtab)
24742474 void
24752475 Layout::define_section_symbols(Symbol_table* symtab)
24762476 {
2477+ const elfcpp::STV visibility = parameters->options().start_stop_visibility_enum();
24772478 for (Section_list::const_iterator p = this->section_list_.begin();
24782479 p != this->section_list_.end();
24792480 ++p)
@@ -2495,7 +2496,7 @@ Layout::define_section_symbols(Symbol_table* symtab)
24952496 0, // symsize
24962497 elfcpp::STT_NOTYPE,
24972498 elfcpp::STB_GLOBAL,
2498- elfcpp::STV_PROTECTED,
2499+ visibility,
24992500 0, // nonvis
25002501 false, // offset_is_from_end
25012502 true); // only_if_ref
@@ -2508,7 +2509,7 @@ Layout::define_section_symbols(Symbol_table* symtab)
25082509 0, // symsize
25092510 elfcpp::STT_NOTYPE,
25102511 elfcpp::STB_GLOBAL,
2511- elfcpp::STV_PROTECTED,
2512+ visibility,
25122513 0, // nonvis
25132514 true, // offset_is_from_end
25142515 true); // only_if_ref
--- a/gold/options.cc
+++ b/gold/options.cc
@@ -997,7 +997,8 @@ General_options::General_options()
997997 fix_v4bx_(FIX_V4BX_NONE),
998998 endianness_(ENDIANNESS_NOT_SET),
999999 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)
10011002 {
10021003 // Turn off option registration once construction is complete.
10031004 gold::options::ready_to_register = false;
@@ -1169,6 +1170,19 @@ General_options::finalize()
11691170 this->set_orphan_handling_enum(ORPHAN_ERROR);
11701171 }
11711172
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+
11721186 // -M is equivalent to "-Map -".
11731187 if (this->print_map() && !this->user_set_Map())
11741188 {
--- a/gold/options.h
+++ b/gold/options.h
@@ -1500,6 +1500,11 @@ class General_options
15001500 N_("Don't mark variables read-only after relocation"));
15011501 DEFINE_uint64(stack_size, options::DASH_Z, '\0', 0,
15021502 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"});
15031508 DEFINE_bool(text, options::DASH_Z, '\0', false,
15041509 N_("Do not permit relocations in read-only segments"),
15051510 N_("Permit relocations in read-only segments"));
@@ -1750,6 +1755,10 @@ class General_options
17501755 orphan_handling_enum() const
17511756 { return this->orphan_handling_enum_; }
17521757
1758+ elfcpp::STV
1759+ start_stop_visibility_enum() const
1760+ { return this->start_stop_visibility_enum_; }
1761+
17531762 private:
17541763 // Don't copy this structure.
17551764 General_options(const General_options&);
@@ -1809,6 +1818,10 @@ class General_options
18091818 set_orphan_handling_enum(Orphan_handling value)
18101819 { this->orphan_handling_enum_ = value; }
18111820
1821+ void
1822+ set_start_stop_visibility_enum(elfcpp::STV value)
1823+ { this->start_stop_visibility_enum_ = value; }
1824+
18121825 // These are called by finalize() to set up the search-path correctly.
18131826 void
18141827 add_to_library_path_with_sysroot(const std::string& arg)
@@ -1876,6 +1889,8 @@ class General_options
18761889 std::vector<Position_dependent_options*> options_stack_;
18771890 // Orphan handling option, decoded to an enum value.
18781891 Orphan_handling orphan_handling_enum_;
1892+ // Symbol visibility for __start_* / __stop_* magic symbols.
1893+ elfcpp::STV start_stop_visibility_enum_;
18791894 };
18801895
18811896 // The position-dependent options. We use this to store the state of
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -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+
15 2020-06-12 Nelson Chu <nelson.chu@sifive.com>
26
37 * opcode/riscv-opc.h: Update the defined versions of CSR from
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -542,10 +542,10 @@ struct bfd_link_info
542542 Normally these optimizations are disabled by default but some targets
543543 prefer to enable them by default. So this field is a tri-state variable.
544544 The values are:
545-
545+
546546 zero: Enable the optimizations (either from --relax being specified on
547547 the command line or the backend's before_allocation emulation function.
548-
548+
549549 positive: The user has requested that these optimizations be disabled.
550550 (Via the --no-relax command line option).
551551
@@ -649,6 +649,9 @@ struct bfd_link_info
649649 /* May be used to set DT_FLAGS_1 for ELF. */
650650 bfd_vma flags_1;
651651
652+ /* May be used to set ELF visibility for __start_* / __stop_. */
653+ unsigned int start_stop_visibility;
654+
652655 /* Start and end of RELRO region. */
653656 bfd_vma relro_start, relro_end;
654657
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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+
19 2020-06-15 Alan Modra <amodra@gmail.com>
210
311 * testsuite/ld-scripts/include.exp: Don't load ld-lib.exp.
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -25,6 +25,9 @@
2525 searched relative to the directory of the linker script before other search
2626 paths.
2727
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+
2831 Changes in 2.34:
2932
3033 * The ld check for "PHDR segment not covered by LOAD segment" is more
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -749,6 +749,21 @@ fragment <<EOF
749749 {
750750 link_info.flags_1 |= DF_1_GLOBAUDIT;
751751 }
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+ }
752767 EOF
753768
754769 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1373,6 +1373,19 @@ Specify a stack size for an ELF @code{PT_GNU_STACK} segment.
13731373 Specifying zero will override any default non-zero sized
13741374 @code{PT_GNU_STACK} segment creation.
13751375
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+
13761389 @item text
13771390 @itemx notext
13781391 @itemx textoff
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -27,6 +27,7 @@
2727 #include "bfdlink.h"
2828 #include "ctf-api.h"
2929 #include "filenames.h"
30+#include "elf/common.h"
3031
3132 #include "ld.h"
3233 #include "ldmain.h"
@@ -307,6 +308,7 @@ main (int argc, char **argv)
307308 #ifdef DEFAULT_NEW_DTAGS
308309 link_info.new_dtags = DEFAULT_NEW_DTAGS;
309310 #endif
311+ link_info.start_stop_visibility = STV_PROTECTED;
310312
311313 ldfile_add_arch ("");
312314 emulation = get_emulation (argc, argv);