S390: Implement 64-bit __fentry__

* Since __fentry__ is almost the same as _mcount, reuse the code by
  #including it twice with different #defines around.
* Remove LA usages - they are needed in 31-bit mode to clear the top
  bit, but in 64-bit they appear to do nothing.
* Add CFI rule for the nonstandard return register. This rule applies
  to the current function (binutils generates a new CIE - see
  gas/dw2gencfi.c:select_cie_for_fde()), so it is not necessary to put
  __fentry__ into a new file.
* Fix CFI offset for %r14.
* Add CFI rule for %r0.
* Fix unwound value of %r15 being off by 244 bytes.
* Unwinding in __fentry__@plt does not work, no plan to fix it - it
  would require asking linker to generate CFI for return address in
  %r0.  From functional perspective keeping it broken is fine, since
  the callee did not have a chance to do anything yet.  From
  convenience perspective it would be possible to enhance GDB in the
  future to treat __fentry__@plt in a special way.
* Fix whitespace.
* Fix offsets in comments, which were copied from 32-bit code.
* 32-bit version will not be implemented, since it's not compatible
  with the corresponding PLT stubs: they assume %r12 points to GOT,
  which is not the case for gcc-emitted __fentry__ stub, which runs
  before the prolog.

This patch adds the runtime support in glibc for the -mfentry
gcc feature introduced in [1] and [2].

[1] https://gcc.gnu.org/ml/gcc-patches/2018-07/msg00784.html
[2] https://gcc.gnu.org/ml/gcc-patches/2018-07/msg00912.html

ChangeLog:

	* sysdeps/s390/s390-64/Versions (__fentry__): Add.
	* sysdeps/s390/s390-64/s390x-mcount.S: Move the common
	code to s390x-mcount.h and #include it.
	* sysdeps/s390/s390-64/s390x-mcount.h: New file.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
	(__fentry__): Add.
This commit is contained in:
Ilya Leoshkevich 2018-08-10 09:07:44 +02:00 committed by Stefan Liebler
parent 8d997d2253
commit 71c01af52f
5 changed files with 133 additions and 56 deletions

View File

@ -1,3 +1,12 @@
2018-08-10 Ilya Leoshkevich <iii@linux.ibm.com>
* sysdeps/s390/s390-64/Versions (__fentry__): Add.
* sysdeps/s390/s390-64/s390x-mcount.S: Move the common
code to s390x-mcount.h and #include it.
* sysdeps/s390/s390-64/s390x-mcount.h: New file.
* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
(__fentry__): Add.
2018-08-10 Ilya Leoshkevich <iii@linux.ibm.com>
* stdlib/Versions: Remove __fentry__.

View File

@ -0,0 +1,5 @@
libc {
GLIBC_2.29 {
__fentry__;
}
}

View File

@ -1,6 +1,5 @@
/* 64 bit S/390-specific implementation of profiling support.
Copyright (C) 2001-2018 Free Software Foundation, Inc.
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com)
Copyright (C) 2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -17,61 +16,25 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#define MCOUNT_SYMBOL _mcount
#define MCOUNT_CALLER_OFF 232 /* Pushed by the _mcount stub. */
#define MCOUNT_CALLEE_REG 14 /* Normal calling convention. */
#define MCOUNT_RETURN_REG 14
#include "s390x-mcount.h"
#undef MCOUNT_SYMBOL
#undef MCOUNT_CALLER_OFF
#undef MCOUNT_CALLEE_REG
#undef MCOUNT_RETURN_REG
/* How profiling works on 64 bit S/390:
On the start of each function _mcount is called with the address of a
data word in %r1 (initialized to 0, used for counting). The compiler
with the option -p generates code of the form:
STM 6,15,24(15)
BRAS 13,.LTN0_0
.LT0_0:
.LC13: .long .LP0
.data
.align 4
.LP0: .long 0
.text
# function profiler
stg 14,4(15)
lg 1,.LC13-.LT0_0(13)
brasl 14,_mcount
lg 14,4(15)
The _mcount implementation now has to call __mcount_internal with the
address of .LP0 as first parameter and the return address as second
parameter. &.LP0 was loaded to %r1 and the return address is in %r14.
_mcount may not modify any register. */
.globl C_SYMBOL_NAME(_mcount)
.type C_SYMBOL_NAME(_mcount), @function
cfi_startproc
.align ALIGNARG(4)
C_LABEL(_mcount)
/* Save the caller-clobbered registers. */
aghi %r15,-224
cfi_adjust_cfa_offset (224)
stmg %r14,%r5,160(%r15)
cfi_offset (r14, 0)
cfi_offset (r15, 8)
lg %r2,232(%r15) # callers address = first parameter
la %r2,0(%r2) # clear bit 0
la %r3,0(%r14) # callees address = second parameter
#ifdef PIC
brasl %r14,__mcount_internal@PLT
#else
brasl %r14,__mcount_internal
#endif
/* Pop the saved registers. Please note that `mcount' has no
return value. */
lmg %r14,%r5,160(%r15)
aghi %r15,224
cfi_adjust_cfa_offset (-224)
br %r14
cfi_endproc
ASM_SIZE_DIRECTIVE(C_SYMBOL_NAME(_mcount))
#define MCOUNT_SYMBOL __fentry__
#define MCOUNT_CALLER_OFF 160 /* Saved %r14. */
#define MCOUNT_CALLEE_REG 0 /* __fentry__ calling convention. */
#define MCOUNT_RETURN_REG 1 /* Cannot return via %r0. */
#include "s390x-mcount.h"
#undef MCOUNT_SYMBOL
#undef MCOUNT_CALLER_OFF
#undef MCOUNT_CALLEE_REG
#undef MCOUNT_RETURN_REG
#undef mcount
weak_alias (_mcount, mcount)

View File

@ -0,0 +1,99 @@
/* 64 bit S/390-specific implementation of profiling support.
Copyright (C) 2001-2018 Free Software Foundation, Inc.
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com)
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
/* How profiling works on 64 bit S/390:
On the start of each function _mcount is called with the address of a
data word in %r1 (initialized to 0, used for counting). The compiler
with the option -p generates code of the form:
STM 6,15,24(15)
BRAS 13,.LTN0_0
.LT0_0:
.LC13: .long .LP0
.data
.align 4
.LP0: .long 0
.text
# function profiler
stg 14,8(15)
lg 1,.LC13-.LT0_0(13)
brasl 14,_mcount
lg 14,8(15)
The _mcount implementation now has to call __mcount_internal with the
address of .LP0 as first parameter and the return address as second
parameter. &.LP0 was loaded to %r1 and the return address is in %r14.
_mcount may not modify any register.
Alternatively, at the start of each function __fentry__ is called using a
single
# function profiler
brasl 0,__fentry__
instruction. In this case %r0 points to the callee, and %r14 points to the
caller. These values need to be passed to __mcount_internal using the same
sequence as for _mcount, so the code below is shared between both functions.
The only major difference is that __fentry__ cannot return through %r0, in
which the return address is located, because br instruction is a no-op with
this register. Therefore %r1, which is clobbered by the PLT anyway, is
used. */
#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
.globl C_SYMBOL_NAME(MCOUNT_SYMBOL)
.type C_SYMBOL_NAME(MCOUNT_SYMBOL), @function
cfi_startproc
.align ALIGNARG(4)
C_LABEL(MCOUNT_SYMBOL)
cfi_return_column (glue(r, MCOUNT_CALLEE_REG))
/* Save the caller-clobbered registers. */
aghi %r15,-224
cfi_adjust_cfa_offset (224)
/* binutils 2.28+: .cfi_val_offset r15, -160 */
.cfi_escape \
/* DW_CFA_val_offset */ 0x14, \
/* r15 */ 0x0f, \
/* scaled offset */ 0x14
stmg %r14,%r5,160(%r15)
cfi_offset (r14, -224)
cfi_offset (r0, -224+16)
lg %r2,MCOUNT_CALLER_OFF(%r15) # callers address = 1st param
lgr %r3,glue(%r, MCOUNT_CALLEE_REG) # callees address = 2nd param
#ifdef PIC
brasl %r14,__mcount_internal@PLT
#else
brasl %r14,__mcount_internal
#endif
/* Pop the saved registers. Please note that `mcount' has no
return value. */
lmg %r14,%r5,160(%r15)
aghi %r15,224
cfi_adjust_cfa_offset (-224)
#if MCOUNT_RETURN_REG != MCOUNT_CALLEE_REG
lgr glue(%r, MCOUNT_RETURN_REG),glue(%r, MCOUNT_CALLEE_REG)
#endif
br glue(%r, MCOUNT_RETURN_REG)
cfi_endproc
ASM_SIZE_DIRECTIVE(C_SYMBOL_NAME(MCOUNT_SYMBOL))

View File

@ -1907,6 +1907,7 @@ GLIBC_2.28 thrd_current F
GLIBC_2.28 thrd_equal F
GLIBC_2.28 thrd_sleep F
GLIBC_2.28 thrd_yield F
GLIBC_2.29 __fentry__ F
GLIBC_2.3 __ctype_b_loc F
GLIBC_2.3 __ctype_tolower_loc F
GLIBC_2.3 __ctype_toupper_loc F