diff options
author | Cherry Zhang <cherryyz@google.com> | 2019-02-15 23:22:29 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-02-15 23:22:29 +0000 |
commit | fba70f605e759144eeebfaabcf12756906578d59 (patch) | |
tree | edf18f3e7cae2f28d16b5bc522be03d23f734de5 /gcc/go/gofrontend/expressions.cc | |
parent | 9695618899f4f85d1e9fdbe7728d0e238b99511c (diff) | |
download | gcc-fba70f605e759144eeebfaabcf12756906578d59.zip gcc-fba70f605e759144eeebfaabcf12756906578d59.tar.gz gcc-fba70f605e759144eeebfaabcf12756906578d59.tar.bz2 |
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
Diffstat (limited to 'gcc/go/gofrontend/expressions.cc')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index d46c754..1576613 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -9903,17 +9903,18 @@ Call_expression::do_lower(Gogo* gogo, Named_object* function, && n == "getcallerpc") { static Named_object* builtin_return_address; + int arg = 0; return this->lower_to_builtin(&builtin_return_address, "__builtin_return_address", - 0); + &arg); } else if ((this->args_ == NULL || this->args_->size() == 0) && n == "getcallersp") { - static Named_object* builtin_frame_address; - return this->lower_to_builtin(&builtin_frame_address, - "__builtin_frame_address", - 1); + static Named_object* builtin_dwarf_cfa; + return this->lower_to_builtin(&builtin_dwarf_cfa, + "__builtin_dwarf_cfa", + NULL); } } } @@ -10031,21 +10032,24 @@ Call_expression::lower_varargs(Gogo* gogo, Named_object* function, this->varargs_are_lowered_ = true; } -// Return a call to __builtin_return_address or __builtin_frame_address. +// Return a call to __builtin_return_address or __builtin_dwarf_cfa. Expression* Call_expression::lower_to_builtin(Named_object** pno, const char* name, - int arg) + int* arg) { if (*pno == NULL) - *pno = Gogo::declare_builtin_rf_address(name); + *pno = Gogo::declare_builtin_rf_address(name, arg != NULL); Location loc = this->location(); Expression* fn = Expression::make_func_reference(*pno, NULL, loc); - Expression* a = Expression::make_integer_ul(arg, NULL, loc); Expression_list *args = new Expression_list(); - args->push_back(a); + if (arg != NULL) + { + Expression* a = Expression::make_integer_ul(*arg, NULL, loc); + args->push_back(a); + } Expression* call = Expression::make_call(fn, args, false, loc); // The builtin functions return void*, but the Go functions return uintptr. |