[PATCH] [gold] Implement -z stack-size option
Roland McGrath
mcgrathr@google.com
Mon Aug 15 19:32:00 GMT 2016
This implementation doesn't seem particularly elegant, but the separation
of duties between Output_segment::set_offset and (its sole caller)
Layout::set_segment_offsets seems fairly arbitrary to me as it is and this
doesn't seem to make that any worse.
Ok for trunk and 2.27?
Thanks,
Roland
gold/
2016-08-15 Roland McGrath <roland@hack.frob.com>
* options.h (General_options): Grok -z stack-size.
* layout.cc (Layout::create_executable_stack_info): Always create
the segment if -z stack-size was used.
* output.cc (Output_segment::set_offset): If output_lists_[0] is
empty and type_ is PT_GNU_STACK, set memsz_ to -z stack-size value
and min_p_align_ to a constant 16.
diff --git a/gold/layout.cc b/gold/layout.cc
index 376051d..518b802 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -2985,10 +2985,12 @@ Layout::create_gold_note()
// executable. Otherwise, if at least one input file a
// .note.GNU-stack section, and some input file has no .note.GNU-stack
// section, we use the target default for whether the stack should be
-// executable. Otherwise, we don't generate a stack note. When
-// generating a object file, we create a .note.GNU-stack section with
-// the appropriate marking. When generating an executable or shared
-// library, we create a PT_GNU_STACK segment.
+// executable. If -z stack-size was used to set a p_memsz value for
+// PT_GNU_STACK, we generate the segment regardless. Otherwise, we
+// don't generate a stack note. When generating a object file, we
+// create a .note.GNU-stack section with the appropriate marking.
+// When generating an executable or shared library, we create a
+// PT_GNU_STACK segment.
void
Layout::create_executable_stack_info()
@@ -3003,7 +3005,9 @@ Layout::create_executable_stack_info()
gold_warning(_("one or more inputs require executable stack, "
"but -z noexecstack was given"));
}
- else if (!this->input_with_gnu_stack_note_)
+ else if (!this->input_with_gnu_stack_note_
+ && (!parameters->options().user_set_stack_size()
+ || parameters->options().relocatable()))
return;
else
{
diff --git a/gold/options.h b/gold/options.h
index 23c9658..4c5b2ae 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -1339,6 +1339,8 @@ class General_options
DEFINE_bool(relro, options::DASH_Z, '\0', DEFAULT_LD_Z_RELRO,
N_("Where possible mark variables read-only after relocation"),
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_bool(text, options::DASH_Z, '\0', false,
N_("Do not permit relocations in read-only segments"),
N_("Permit relocations in read-only segments (default)"));
diff --git a/gold/output.cc b/gold/output.cc
index 0a9e58f..433a09a 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -4660,6 +4660,13 @@ Output_segment::set_offset(unsigned int increase)
this->min_p_align_ = 0;
this->offset_ = 0;
this->filesz_ = 0;
+ if (this->type_ == elfcpp::PT_GNU_STACK)
+ {
+ this->memsz_ = parameters->options().stack_size();
+ // BFD lets targets override this default alignment, but the only
+ // targets that do so are ones that Gold does not support so far.
+ this->min_p_align_ = 16;
+ }
return;
}
More information about the Binutils
mailing list