compiler,runtime: use __builtin_dwarf_cfa for getcallersp
commitfba70f605e759144eeebfaabcf12756906578d59
authorCherry Zhang <cherryyz@google.com>
Fri, 15 Feb 2019 23:22:29 +0000 (15 23:22 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 15 Feb 2019 23:22:29 +0000 (15 23:22 +0000)
treeedf18f3e7cae2f28d16b5bc522be03d23f734de5
parent9695618899f4f85d1e9fdbe7728d0e238b99511c
compiler,runtime: use __builtin_dwarf_cfa for getcallersp

    Currently, the compiler lowers runtime.getcallersp to
    __builtin_frame_address(1). In the C side of the runtime,
    getcallersp is defined as __builtin_frame_address(0). They don't
    match. Further, neither of them actually returns the caller's SP.
    On AMD64, __builtin_frame_address(0) just returns the frame
    pointer. __builtin_frame_address(1) returns the memory content
    where the frame pointer points to, which is typically the
    caller's frame pointer but can also be garbage if the frame
    pointer is not enabled.

    This CL changes it to use __builtin_dwarf_cfa(), which returns
    the caller's SP at the call site. This matches the SP we get
    from unwinding the stack.

    Currently getcallersp is not used for anything real. It will be
    used for precise stack scan (a new version of CL 159098).

    Reviewed-on: https://go-review.googlesource.com/c/162905

* go-gcc.cc (Gcc_backend::Gcc_backend): Define __builtin_dwarf_cfa
instead of __builtin_frame_address.

From-SVN: r268952
gcc/go/ChangeLog
gcc/go/go-gcc.cc
gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/expressions.h
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/gogo.h
libgo/runtime/runtime.h