[Bug c++/85961] New: scratch register rsi used after function call

bki at hacon dot de gcc-bugzilla@gcc.gnu.org
Mon May 28 22:31:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85961

            Bug ID: 85961
           Summary: scratch register rsi used after function call
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bki at hacon dot de
  Target Milestone: ---

Created attachment 44203
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44203&action=edit
Minimal cpp-File producing the bug

With g++ 7.0.0 and g++ 7.3.0 and compiling the attached file as detailed in the
comments, produces an object file containing the following instruction
sequence:

  76:   48 89 c6                mov    %rax,%rsi
  79:   e8 82 ff ff ff          callq  0
<_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv.isra.0>
  7e:   48 8d 14 06             lea    (%rsi,%rax,1),%rdx

According to the System V AMD64 ABI
(https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf),
%rsi is a scratch register not preserved across function calls. I therefore
think that this instruction sequence is wrong.

Why is this a problem?

The function which is called does not clobber %rsi itself. But compiling with
'-pg -mfentry' will instrument that function call and allow a user specified
function to clobber %rsi. A call to __fentry__ should not clobber %rsi, since
%rsi is used for parameter passing and must be unchanged when __fentry__
returns. But by temporarily replacing the return address __fentry__ can
instrument the function exit. There, clobbering %rsi (and all other scratch
registers) should be acceptable.


More information about the Gcc-bugs mailing list