This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/81490] x86: Handling of symbol ranges for __seg_fs/__seg_gs
- From: "hjl.tools at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 03 Aug 2017 23:06:24 +0000
- Subject: [Bug target/81490] x86: Handling of symbol ranges for __seg_fs/__seg_gs
- Auto-submitted: auto-generated
- References: <bug-81490-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81490
--- Comment #18 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to H.J. Lu from comment #17)
> Created attachment 41920 [details]
> A binutils patch
>
With this patch:
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 587dbe61e8b..953c153a834 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -19429,8 +19429,10 @@ ix86_print_operand_address_as (FILE *file, rtx addr,
fputs (string, file);
}
- /* Use one byte shorter RIP relative addressing for 64bit mode. */
- if (TARGET_64BIT && !base && !index && !no_rip)
+ /* Use one byte shorter RIP relative addressing for
+ symbols in the generic address space. */
+ if (TARGET_64BIT && !base && !index
+ && ADDR_SPACE_GENERIC_P (as) && !no_rip)
{
rtx symbol = disp;
@@ -19465,6 +19467,8 @@ ix86_print_operand_address_as (FILE *file, rtx addr,
output_pic_addr_const (file, disp, 0);
else
output_addr_const (file, disp);
+ if (!ADDR_SPACE_GENERIC_P (as))
+ fputs ("@GPREL", file);
}
else
{
I got
[hjl@gnu-6 gprel-1]$ cat xx.c
extern int __seg_gs foo;
int
xxx (void)
{
return foo;
}
[hjl@gnu-6 gprel-1]$ /export/build/gnu/gcc-x32/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc-x32/build-x86_64-linux/gcc/ -B./ -fPIE -O2 xx.c -S
[hjl@gnu-6 gprel-1]$ cat xx.s
.file "xx.c"
.text
.p2align 4,,15
.globl xxx
.type xxx, @function
xxx:
.LFB0:
.cfi_startproc
movl %gs:foo@GPREL, %eax
ret
.cfi_endproc
.LFE0:
.size xxx, .-xxx
.ident "GCC: (GNU) 8.0.0 20170801 (experimental)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-6 gprel-1]$ ./as -o xx.o xx.s
[hjl@gnu-6 gprel-1]$ ./objdump -dwr xx.o
xx.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <xxx>:
0: 65 8b 04 25 00 00 00 00 mov %gs:0x0,%eax 4:
R_X86_64_GPREL foo
8: c3 retq
[hjl@gnu-6 gprel-1]$