aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorRoland McGrath <mcgrathr@google.com>2020-06-15 11:45:02 -0700
committerRoland McGrath <mcgrathr@google.com>2020-06-15 11:45:02 -0700
commitcae64165f47b64898c4f1982d294862cfae89a47 (patch)
treed51ade829ba19bebf17822647e08d49506d534b8 /gold
parent669203174311c5be76744a879563c697cd479853 (diff)
downloadbinutils-cae64165f47b64898c4f1982d294862cfae89a47.zip
binutils-cae64165f47b64898c4f1982d294862cfae89a47.tar.gz
binutils-cae64165f47b64898c4f1982d294862cfae89a47.tar.bz2
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.
Diffstat (limited to 'gold')
-rw-r--r--gold/ChangeLog12
-rw-r--r--gold/layout.cc5
-rw-r--r--gold/options.cc16
-rw-r--r--gold/options.h15
4 files changed, 45 insertions, 3 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index f3d3715..1f9c523 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,15 @@
+2020-06-15 Roland McGrath <mcgrathr@google.com>
+
+ 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.
+
2020-06-06 Alan Modra <amodra@gmail.com>
* powerpc.cc: Update throughout for reloc renaming.
diff --git a/gold/layout.cc b/gold/layout.cc
index be437f3..b3b0c57 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -2474,6 +2474,7 @@ Layout::create_initial_dynamic_sections(Symbol_table* symtab)
void
Layout::define_section_symbols(Symbol_table* symtab)
{
+ const elfcpp::STV visibility = parameters->options().start_stop_visibility_enum();
for (Section_list::const_iterator p = this->section_list_.begin();
p != this->section_list_.end();
++p)
@@ -2495,7 +2496,7 @@ Layout::define_section_symbols(Symbol_table* symtab)
0, // symsize
elfcpp::STT_NOTYPE,
elfcpp::STB_GLOBAL,
- elfcpp::STV_PROTECTED,
+ visibility,
0, // nonvis
false, // offset_is_from_end
true); // only_if_ref
@@ -2508,7 +2509,7 @@ Layout::define_section_symbols(Symbol_table* symtab)
0, // symsize
elfcpp::STT_NOTYPE,
elfcpp::STB_GLOBAL,
- elfcpp::STV_PROTECTED,
+ visibility,
0, // nonvis
true, // offset_is_from_end
true); // only_if_ref
diff --git a/gold/options.cc b/gold/options.cc
index 94867b3..b13ae71 100644
--- a/gold/options.cc
+++ b/gold/options.cc
@@ -997,7 +997,8 @@ General_options::General_options()
fix_v4bx_(FIX_V4BX_NONE),
endianness_(ENDIANNESS_NOT_SET),
discard_locals_(DISCARD_SEC_MERGE),
- orphan_handling_enum_(ORPHAN_PLACE)
+ orphan_handling_enum_(ORPHAN_PLACE),
+ start_stop_visibility_enum_(elfcpp::STV_PROTECTED)
{
// Turn off option registration once construction is complete.
gold::options::ready_to_register = false;
@@ -1169,6 +1170,19 @@ General_options::finalize()
this->set_orphan_handling_enum(ORPHAN_ERROR);
}
+ // Parse the -z start-stop-visibility argument.
+ if (this->user_set_start_stop_visibility())
+ {
+ if (strcmp(this->start_stop_visibility(), "default") == 0)
+ this->set_start_stop_visibility_enum(elfcpp::STV_DEFAULT);
+ else if (strcmp(this->start_stop_visibility(), "internal") == 0)
+ this->set_start_stop_visibility_enum(elfcpp::STV_INTERNAL);
+ else if (strcmp(this->start_stop_visibility(), "hidden") == 0)
+ this->set_start_stop_visibility_enum(elfcpp::STV_HIDDEN);
+ else if (strcmp(this->start_stop_visibility(), "protected") == 0)
+ this->set_start_stop_visibility_enum(elfcpp::STV_PROTECTED);
+ }
+
// -M is equivalent to "-Map -".
if (this->print_map() && !this->user_set_Map())
{
diff --git a/gold/options.h b/gold/options.h
index b2059d9..f0e9fbd 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -1500,6 +1500,11 @@ class General_options
N_("Don't mark variables read-only after relocation"));
DEFINE_uint64(stack_size, options::DASH_Z, '\0', 0,
N_("Set PT_GNU_STACK segment p_memsz to SIZE"), N_("SIZE"));
+ DEFINE_enum(start_stop_visibility, options::DASH_Z, '\0', "protected",
+ N_("ELF symbol visibility for synthesized "
+ "__start_* and __stop_* symbols"),
+ ("[default,internal,hidden,protected]"),
+ {"default", "internal", "hidden", "protected"});
DEFINE_bool(text, options::DASH_Z, '\0', false,
N_("Do not permit relocations in read-only segments"),
N_("Permit relocations in read-only segments"));
@@ -1750,6 +1755,10 @@ class General_options
orphan_handling_enum() const
{ return this->orphan_handling_enum_; }
+ elfcpp::STV
+ start_stop_visibility_enum() const
+ { return this->start_stop_visibility_enum_; }
+
private:
// Don't copy this structure.
General_options(const General_options&);
@@ -1809,6 +1818,10 @@ class General_options
set_orphan_handling_enum(Orphan_handling value)
{ this->orphan_handling_enum_ = value; }
+ void
+ set_start_stop_visibility_enum(elfcpp::STV value)
+ { this->start_stop_visibility_enum_ = value; }
+
// These are called by finalize() to set up the search-path correctly.
void
add_to_library_path_with_sysroot(const std::string& arg)
@@ -1876,6 +1889,8 @@ class General_options
std::vector<Position_dependent_options*> options_stack_;
// Orphan handling option, decoded to an enum value.
Orphan_handling orphan_handling_enum_;
+ // Symbol visibility for __start_* / __stop_* magic symbols.
+ elfcpp::STV start_stop_visibility_enum_;
};
// The position-dependent options. We use this to store the state of