https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104011
Bug ID: 104011
Summary: s390: r12 is not setup for _mcount call
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: stli at linux dot ibm.com
Target Milestone: ---
On 31bit, as r12 is not setup before brasl _mcount@plt, we jump to a
different function.
Note that the PIE plt-slot is using r12.
In the debugging-case, e.g. __libc_calloc is called.
In a different glibc-testcase "gmon/tst-gmon-pie" we jump to another function,
which leads to a segfault.
This happens with, e.g.:
- gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC)
- gcc 11.2.0
Steps to reproduce:
$ cat tst-pie-mcount.c
#include <stdio.h>
#include <stdlib.h>
int
main (void)
{
puts ("Hello world");
return EXIT_SUCCESS;
}
$ gcc -o tst-pie-mcount -g -m31 -fpie -pg -pie tst-pie-mcount.c
$ objdump -d tst-pie-mcount
...
000005c8 <_mcount@plt>:
5c8: 58 10 c0 20 l %r1,32(%r12)
5cc: 07 f1 br %r1
5ce: 00 00 00 00 .long 0x00000000
5d2: 00 00 0d 10 .long 0x00000d10
5d6: 58 10 10 0e l %r1,14(%r1)
5da: a7 f4 ff 97 j 508 <.plt>
...
5e6: 00 3c .short 0x003c
...
00000860 <main>:
860: 50 e0 f0 04 st %r14,4(%r15)
864: c0 10 00 00 0b f2 larl %r1,2048 <__data_start+0x4>
We jump to the plt-slot, which uses r12, which is loaded later.
86a: c0 e5 ff ff fe af brasl %r14,5c8 <_mcount@plt>
870: 58 e0 f0 04 l %r14,4(%r15)
874: 90 bf f0 2c stm %r11,%r15,44(%r15)
878: a7 fa ff a0 ahi %r15,-96
87c: 18 bf lr %r11,%r15
GOT-Pointer is loaded here for puts:
87e: c0 c0 00 00 0b c1 larl %r12,2000 <_GLOBAL_OFFSET_TABLE_>
884: c0 20 00 00 00 6c larl %r2,95c <_IO_stdin_used+0x4>
88a: c0 e5 ff ff fe 7f brasl %r14,588 <puts@plt>
890: a7 18 00 00 lhi %r1,0
894: 18 21 lr %r2,%r1
896: 98 bf b0 8c lm %r11,%r15,140(%r11)
89a: 07 fe br %r14
89c: 07 07 nopr %r7
89e: 07 07 nopr %r7
*/