Skip to content

Commit

Permalink
Fix unwinding on OS X 10.9.
Browse files Browse the repository at this point in the history
OS X 10.9's linker has a bug that results in it failing to preserve
DWARF unwind information when passed the -no_compact_unwind flag.
This flag is passed on OS X because the unwind information for
__morestack cannot be represented by the compact unwind format.

We can work around this problem by using a more targeted approach
to disabling compact unwind information. The OS X linker looks for
a particular pattern in the DWARF unwind information and will not
attempt to convert the unwind information to the compact format.
The pattern in question is the return address register being saved
twice to the same location.

Fixes #6849.
  • Loading branch information
bdash committed Oct 22, 2013
1 parent 7e4404b commit fd8c06e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions mk/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ CFG_LIB_GLOB_x86_64-apple-darwin=lib$(1)-*.dylib
CFG_LIB_DSYM_GLOB_x86_64-apple-darwin=lib$(1)-*.dylib.dSYM
CFG_GCCISH_CFLAGS_x86_64-apple-darwin := -Wall -Werror -g -fPIC -m64 -arch x86_64
CFG_GCCISH_CXXFLAGS_x86_64-apple-darwin := -fno-rtti
CFG_GCCISH_LINK_FLAGS_x86_64-apple-darwin := -dynamiclib -pthread -framework CoreServices -Wl,-no_compact_unwind -m64
CFG_GCCISH_LINK_FLAGS_x86_64-apple-darwin := -dynamiclib -pthread -framework CoreServices -m64
CFG_GCCISH_DEF_FLAG_x86_64-apple-darwin := -Wl,-exported_symbols_list,
CFG_GCCISH_PRE_LIB_FLAGS_x86_64-apple-darwin :=
CFG_GCCISH_POST_LIB_FLAGS_x86_64-apple-darwin :=
Expand All @@ -230,7 +230,7 @@ CFG_LIB_GLOB_i686-apple-darwin=lib$(1)-*.dylib
CFG_LIB_DSYM_GLOB_i686-apple-darwin=lib$(1)-*.dylib.dSYM
CFG_GCCISH_CFLAGS_i686-apple-darwin := -Wall -Werror -g -fPIC -m32 -arch i386
CFG_GCCISH_CXXFLAGS_i686-apple-darwin := -fno-rtti
CFG_GCCISH_LINK_FLAGS_i686-apple-darwin := -dynamiclib -pthread -framework CoreServices -Wl,-no_compact_unwind -m32
CFG_GCCISH_LINK_FLAGS_i686-apple-darwin := -dynamiclib -pthread -framework CoreServices -m32
CFG_GCCISH_DEF_FLAG_i686-apple-darwin := -Wl,-exported_symbols_list,
CFG_GCCISH_PRE_LIB_FLAGS_i686-apple-darwin :=
CFG_GCCISH_POST_LIB_FLAGS_i686-apple-darwin :=
Expand Down
8 changes: 0 additions & 8 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,14 +1112,6 @@ pub fn link_args(sess: Session,
~"-Wl,-rpath,/usr/local/lib/gcc44"]);
}

// OS X 10.6 introduced 'compact unwind info', which is produced by the
// linker from the dwarf unwind info. Unfortunately, it does not seem to
// understand how to unwind our __morestack frame, so we have to turn it
// off. This has impacted some other projects like GHC.
if sess.targ_cfg.os == session::OsMacos {
args.push(~"-Wl,-no_compact_unwind");
}

// Stack growth requires statically linking a __morestack function
args.push(~"-lmorestack");

Expand Down
15 changes: 12 additions & 3 deletions src/rt/arch/i386/morestack.S
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
is that OS X 10.6+ uses its own 'compact unwind info',
an undocumented format generated by the linker from
the DWARF CFI. This compact unwind info doesn't correctly
capture the nuance of the __morestack frame, and as a
result all of our linking on OS X uses the -no_compact_unwind
flag.
capture the nuance of the __morestack frame, so we need to
prevent the linker from attempting to convert its DWARF unwind
information.
*/

.text
Expand Down Expand Up @@ -118,6 +118,15 @@ MORESTACK:
// FIXME(#9854) these cfi directives don't work on windows.

pushl %ebp

#if defined(__APPLE__)
// The pattern of the return address being saved twice to the same location
// tells the OS X linker that it should not attempt to convert the DWARF
// unwind information to the compact format.
.cfi_offset %eip, -4
.cfi_offset %eip, -4
#endif

// The CFA is 20 bytes above the register that it is
// associated with for this frame (which will be %ebp)
.cfi_def_cfa_offset 20
Expand Down
9 changes: 9 additions & 0 deletions src/rt/arch/x86_64/morestack.S
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ MORESTACK:
// bytes greater than a normal frame, to allow the unwinder
// to skip the partial frame of the original function.
.cfi_def_cfa_offset 24

#if defined(__APPLE__)
// The pattern of the return address being saved twice to the same location
// tells the OS X linker that it should not attempt to convert the DWARF
// unwind information to the compact format.
.cfi_offset %rip, -8
.cfi_offset %rip, -8
#endif

// %rbp is -24 bytes from the CFA
.cfi_offset %rbp, -24
movq %rsp, %rbp
Expand Down

5 comments on commit fd8c06e

@bors
Copy link
Contributor

@bors bors commented on fd8c06e Oct 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on fd8c06e Oct 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bdash/rust/mavericks-unwinding = fd8c06e into auto

@bors
Copy link
Contributor

@bors bors commented on fd8c06e Oct 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bdash/rust/mavericks-unwinding = fd8c06e merged ok, testing candidate = b477f7a

@bors
Copy link
Contributor

@bors bors commented on fd8c06e Oct 22, 2013

@bors
Copy link
Contributor

@bors bors commented on fd8c06e Oct 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = b477f7a

Please sign in to comment.