]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Fix AMD64 return value ABI in expression evaluation
authorLeszek Swirski <leszeks@google.com>
Mon, 15 Apr 2019 15:56:43 +0000 (11:56 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 15 Apr 2019 15:56:43 +0000 (11:56 -0400)
commit4aa866af6b13c7080c6d92201fc1a2f4ea19998e
tree7fe759b287f5232a0c3f5472451b2a5cf79f7f23
parent86333705ae268aa00da41b094b0d632eae31e9ae
Fix AMD64 return value ABI in expression evaluation

The AMD64 System V ABI specifies that when a function has a return type
classified as MEMORY, the caller provides space for the value and passes
the address to this space as the first argument to the function (before
even the "this" pointer). The classification of MEMORY is applied to
struct that are sufficiently large, or ones with unaligned fields.

The expression evaluator uses call_function_by_hand to call functions,
and the hand-built frame has to push arguments in a way that matches the
ABI of the called function. call_function_by_hand supports ABI-based
struct returns, based on the value of gdbarch_return_value, however on
AMD64 the implementation of the classifier incorrectly assumed that all
non-POD types (implemented as "all types with a base class") should be
classified as MEMORY and use the struct return.

This ABI mismatch resulted in issues when calling a function that returns
a class of size <16 bytes which has a base class, including issues such
as the "this" pointer being incorrect (as it was passed as the second
argument rather than the first).

This is now fixed by checking for field alignment rather than POD-ness,
and a testsuite is added to test expression evaluation for AMD64.

gdb/ChangeLog:

* amd64-tdep.c (amd64_classify_aggregate): Use cp_pass_by_reference
rather than a hand-rolled POD check when checking for forced MEMORY
classification.

gdb/testsuite/ChangeLog:

* gdb.arch/amd64-eval.cc: New file.
* gdb.arch/amd64-eval.exp: New file.
gdb/ChangeLog
gdb/amd64-tdep.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.arch/amd64-eval.cc [new file with mode: 0644]
gdb/testsuite/gdb.arch/amd64-eval.exp [new file with mode: 0644]