Bug 104011 - s390: r12 is not setup for _mcount call
Summary: s390: r12 is not setup for _mcount call
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 11.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2022-01-13 15:56 UTC by stli@linux.ibm.com
Modified: 2022-01-21 08:46 UTC (History)
2 users (show)

See Also:
Host:
Target: s390
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description stli@linux.ibm.com 2022-01-13 15:56:24 UTC
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
 */