diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-12-01 10:44:40 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-12-01 10:44:40 +0100 |
commit | 69157fe75823fc34f1e3265345f2d2b99cd8d380 (patch) | |
tree | 5847d5a087f989264c63d24f34215e294ff8787c /gcc | |
parent | 57fcbe579c2f2b0919486b658a5bec8f4e1ef42b (diff) | |
download | gcc-69157fe75823fc34f1e3265345f2d2b99cd8d380.zip gcc-69157fe75823fc34f1e3265345f2d2b99cd8d380.tar.gz gcc-69157fe75823fc34f1e3265345f2d2b99cd8d380.tar.bz2 |
x86_64: Fix up -fpic -mcmodel=large -fno-plt [PR98063]
On the following testcase with -fpic -mcmodel=large -fno-plt we emit
call puts@GOTPCREL(%rip)
but that is not really appropriate for CM_LARGE_PIC, the .text can be larger
than 2GB in that case and the .got slot further away from %rip than what can
fit into the signed 32-bit immediate.
The following patch computes the address of the .got slot the way it is
computed for that model for function pointer loads, and calls that.
2020-12-01 Jakub Jelinek <jakub@redhat.com>
PR target/98063
* config/i386/i386-expand.c (ix86_expand_call): Handle non-plt
CM_LARGE_PIC calls.
* gcc.target/i386/pr98063.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/config/i386/i386-expand.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr98063.c | 13 |
2 files changed, 24 insertions, 1 deletions
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index 408cd9b..bf775a3 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -8063,7 +8063,17 @@ ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1, } else if (!TARGET_PECOFF && !TARGET_MACHO) { - if (TARGET_64BIT) + if (TARGET_64BIT + && ix86_cmodel == CM_LARGE_PIC + && DEFAULT_ABI != MS_ABI) + { + fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), + UNSPEC_GOT); + fnaddr = gen_rtx_CONST (Pmode, fnaddr); + fnaddr = force_reg (Pmode, fnaddr); + fnaddr = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, fnaddr); + } + else if (TARGET_64BIT) { fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), diff --git a/gcc/testsuite/gcc.target/i386/pr98063.c b/gcc/testsuite/gcc.target/i386/pr98063.c new file mode 100644 index 0000000..f76435a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98063.c @@ -0,0 +1,13 @@ +/* PR target/98063 */ +/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-require-effective-target fpic } */ +/* { dg-options "-O2 -fpic -mcmodel=large -fno-plt -save-temps" } */ +/* { dg-final { scan-assembler-not "puts@GOTPCREL" } } */ + +int +main () +{ + __builtin_puts ("Hello, world!"); + return 0; +} |