gold patch committed: Support for -fsplit-stack

Ian Lance Taylor iant@google.com
Tue Oct 6 23:07:00 GMT 2009


Over in gcc land, I've been working on implementing -fsplit-stack, in
which gcc permits a discontiguous stack.  That works requires linker
support for the case where a function compiled with -fsplit-stack
calls a function compiled without -fsplit-stack.  In that case, we
need to allocate a larger contiguous stack, so that the
non-split-stack function can work.

Code compiled with -fsplit-stack will have a magic section named
.note.GNU-split-stack.  I don't particularly want to continue using
magic sections, and originally I planned to use a note.
Unfortunately, notes will be accumulated by the GNU linker, and that
is undesirable here.  Using a magic section type would be preferable,
but unfortunately gas has no general mechanism for setting the section
type, so that would require a modified gas.  Using a magic section
name is consistent with the existing use of .note.GNU-stack.
Suggestions welcome.

There is another magic section name, .note.GNU-no-split-stack, which
is used in addition to .note.GNU-split-stack when code compiled with
-fsplit-stack includes functions with the "no_split_stack" attribute.
I originally tried using a section flag on .note.GNU-split-stack, but
then gas complained.  This additional information exists so that the
linker does not complain about being unable to adjust the function.

Anyhow, this patch changes the linker so that it when it sees a
function compiled with -fsplit-stack which calls a function compiled
without -fsplit-stack, it looks for the code emitted by gcc and frobs
it to allocate a larger stack.  Specifically this is done by 1)
changing the test so that the function proglogue requires more
contiguous stack space; and 2) changing the call to __morestack
inserted by gcc to call __morestack_non_split instead.

Because I can't assume the presence of a gcc which defines
-fsplit-stack, I've included a more comprehensive set of tests than
usual.

This patch only adds support for i386 and x86_64.  This requires some
additional work on the split branch in gcc, e.g., the definition of
__morestack_non_split, which I will commit presently.

I have committed this patch to binutils mainline.

Ian


2009-10-06  Ian Lance Taylor  <iant@google.com>

	* options.h (class General_options): Define
	split_stack_adjust_size parameter.
	* object.h (class Object): Add uses_split_stack_ and
	has_no_split_stack_ fields.  Add uses_split_stack and
	has_no_split_stack accessor functions.  Declare
	handle_split_stack_section.
	(class Reloc_symbol_changes): Define.
	(class Sized_relobj): Define Function_offsets.  Declare
	split_stack_adjust, split_stack_adjust_reltype, and
	find_functions.
	* object.cc (Object::handle_split_stack_section): New function.
	(Sized_relobj::do_layout): Call handle_split_stack_section.
	* dynobj.cc (Sized_dynobj::do_layout): Call
	handle_split_stack_section.
	* reloc.cc (Sized_relobj::relocate_sections): Call
	split_stack_adjust for executable sections in split_stack
	objects.  Pass reloc_map to relocate_section.
	(Sized_relobj::split_stack_adjust): New function.
	(Sized_relobj::split_stack_adjust_reltype): New function.
	(Sized_relobj::find_functions): New function.
	* target-reloc.h: Include "object.h".
	(relocate_section): Add reloc_symbol_changes parameter.  Change
	all callers.
	* target.h (class Target): Add calls_non_split method.  Declare
	do_calls_non_split virtual method.  Declare match_view and
	set_view_to_nop.
	* target.cc: Include "elfcpp.h".
	(Target::do_calls_non_split): New function.
	(Target::match_view): New function.
	(Target::set_view_to_nop): New function.
	* gold.cc (queue_middle_tasks): Give an error if mixing
	split-stack and non-split-stack objects with -r.
	* i386.cc (Target_i386::relocate_section): Add
	reloc_symbol_changes parameter.
	(Target_i386::do_calls_non_split): New function.
	* x86_64.cc (Target_x86_64::relocate_section): Add
	reloc_symbol_changes parameter.
	(Target_x86_64::do_calls_non_split): New function.
	* arm.cc (Target_arm::relocate_section): Add reloc_symbol_changes
	parameter.
	* powerpc.cc (Target_powerpc::relocate_section): Add
	reloc_symbol_changes parameter.
	* sparc.cc (Target_sparc::relocate_section): Add
	reloc_symbol_changes parameter.
	* configure.ac: Call AM_CONDITIONAL for the default target.
	* configure: Rebuild.
	* testsuite/Makefile.am (TEST_AS): New variable.
	(check_SCRIPTS): Add split_i386.sh and split_x86_64.sh.
	(check_DATA): Add split_i386 and split_x86_64 files.
	(SPLIT_DEFSYMS): Define.
	(split_i386_[1234n].o): New targets.
	(split_i386_[124]): New targets.
	(split_i386_[1234r].stdout): New targets.
	(split_x86_64_[1234n].o): New targets.
	(split_x86_64_[124]): New targets.
	(split_x86_64_[1234r].stdout): New targets.
	(MOSTLYCLEANFILES): Add new executables.
	* testsuite/split_i386.sh: New file.
	* testsuite/split_x86_64.sh: New file.
	* testsuite/split_i386_1.s: New file.
	* testsuite/split_i386_2.s: New file.
	* testsuite/split_i386_3.s: New file.
	* testsuite/split_i386_4.s: New file.
	* testsuite/split_i386_n.s: New file.
	* testsuite/split_x86_64_1.s: New file.
	* testsuite/split_x86_64_2.s: New file.
	* testsuite/split_x86_64_3.s: New file.
	* testsuite/split_x86_64_4.s: New file.
	* testsuite/split_x86_64_n.s: New file.
	* testsuite/testfile.cc (Target_test): Update relocation_section
	function.
	* testsuite/Makefile.in: Rebuild.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-diff
Size: 55328 bytes
Desc: split-stack
URL: <https://sourceware.org/pipermail/binutils/attachments/20091006/54d2f633/attachment.bin>


More information about the Binutils mailing list