diff options
author | Ian Lance Taylor <ian@airs.com> | 2009-10-06 22:58:27 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2009-10-06 22:58:27 +0000 |
commit | 364c7fa5c98a7e2d75fe33ecb1ec4f7260849731 (patch) | |
tree | 2cfca9a55836527ac65fea760844754fe93f01a9 /gold/i386.cc | |
parent | 5aafa1cc49c9a87aeb3e0aeaede8155fdf9f1645 (diff) | |
download | gdb-364c7fa5c98a7e2d75fe33ecb1ec4f7260849731.zip gdb-364c7fa5c98a7e2d75fe33ecb1ec4f7260849731.tar.gz gdb-364c7fa5c98a7e2d75fe33ecb1ec4f7260849731.tar.bz2 |
* 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.
Diffstat (limited to 'gold/i386.cc')
-rw-r--r-- | gold/i386.cc | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/gold/i386.cc b/gold/i386.cc index 04a2fa9..c01b5f2 100644 --- a/gold/i386.cc +++ b/gold/i386.cc @@ -113,7 +113,8 @@ class Target_i386 : public Target_freebsd<32, false> bool needs_special_offset_handling, unsigned char* view, elfcpp::Elf_types<32>::Elf_Addr view_address, - section_size_type view_size); + section_size_type view_size, + const Reloc_symbol_changes*); // Scan the relocs during a relocatable link. void @@ -168,6 +169,13 @@ class Target_i386 : public Target_freebsd<32, false> return Target::do_is_local_label_name(name); } + // Adjust -fstack-split code which calls non-stack-split code. + void + do_calls_non_split(Relobj* object, unsigned int shndx, + section_offset_type fnoffset, section_size_type fnsize, + unsigned char* view, section_size_type view_size, + std::string* from, std::string* to) const; + // Return the size of the GOT section. section_size_type got_size() @@ -2465,7 +2473,8 @@ Target_i386::relocate_section(const Relocate_info<32, false>* relinfo, bool needs_special_offset_handling, unsigned char* view, elfcpp::Elf_types<32>::Elf_Addr address, - section_size_type view_size) + section_size_type view_size, + const Reloc_symbol_changes* reloc_symbol_changes) { gold_assert(sh_type == elfcpp::SHT_REL); @@ -2479,7 +2488,8 @@ Target_i386::relocate_section(const Relocate_info<32, false>* relinfo, needs_special_offset_handling, view, address, - view_size); + view_size, + reloc_symbol_changes); } // Return the size of a relocation while scanning during a relocatable @@ -2699,6 +2709,63 @@ Target_i386::do_code_fill(section_size_type length) const return std::string(nops[length], length); } +// FNOFFSET in section SHNDX in OBJECT is the start of a function +// compiled with -fstack-split. The function calls non-stack-split +// code. We have to change the function so that it always ensures +// that it has enough stack space to run some random function. + +void +Target_i386::do_calls_non_split(Relobj* object, unsigned int shndx, + section_offset_type fnoffset, + section_size_type fnsize, + unsigned char* view, + section_size_type view_size, + std::string* from, + std::string* to) const +{ + // The function starts with a comparison of the stack pointer and a + // field in the TCB. This is followed by a jump. + + // cmp %gs:NN,%esp + if (this->match_view(view, view_size, fnoffset, "\x65\x3b\x25", 3) + && fnsize > 7) + { + // We will call __morestack if the carry flag is set after this + // comparison. We turn the comparison into an stc instruction + // and some nops. + view[fnoffset] = '\xf9'; + this->set_view_to_nop(view, view_size, fnoffset + 1, 6); + } + // lea NN(%esp),%ecx + else if (this->match_view(view, view_size, fnoffset, "\x8d\x8c\x24", 3) + && fnsize > 7) + { + // This is loading an offset from the stack pointer for a + // comparison. The offset is negative, so we decrease the + // offset by the amount of space we need for the stack. This + // means we will avoid calling __morestack if there happens to + // be plenty of space on the stack already. + unsigned char* pval = view + fnoffset + 3; + uint32_t val = elfcpp::Swap_unaligned<32, false>::readval(pval); + val -= parameters->options().split_stack_adjust_size(); + elfcpp::Swap_unaligned<32, false>::writeval(pval, val); + } + else + { + if (!object->has_no_split_stack()) + object->error(_("failed to match split-stack sequence at " + "section %u offset %0zx"), + shndx, fnoffset); + return; + } + + // We have to change the function so that it calls + // __morestack_non_split instead of __morestack. The former will + // allocate additional stack space. + *from = "__morestack"; + *to = "__morestack_non_split"; +} + // The selector for i386 object files. class Target_selector_i386 : public Target_selector_freebsd |