[Bug target/100936] New: %p and %P modifiers should not emit segment overrides
ubizjak at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Jun 6 21:29:20 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100936
Bug ID: 100936
Summary: %p and %P modifiers should not emit segment overrides
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: ubizjak at gmail dot com
Target Milestone: ---
Following testcase:
--cut here--
__seg_gs int var = 123;
static int
*foo (void)
{
int *addr;
asm ("lea %p1, %0" : "=r"(addr) : "m"(var));
return addr;
}
static int
bar (int *addr)
{
int val;
asm ("mov %%gs:%1, %0" : "=r"(val) : "m"(*addr));
return val;
}
int
baz (void)
{
int *addr = foo();
int val = bar (addr);
return val;
}
--cut here--
emits assembly warning when compiled on x86 target:
gcc -O2 -c lea.c
lea.c: Assembler messages:
lea.c:8: Warning: segment override on `lea' is ineffectual
$ objdump -d lea.o
lea.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <baz>:
0: 65 48 8d 04 25 00 00 lea %gs:0x0,%rax
7: 00 00
9: 65 8b 00 mov %gs:(%rax),%eax
c: c3 retq
The problem is with %p operand modifier, which should emit raw symbol name:
P -- if PIC, print an @PLT suffix. For -fno-plt, load function
address from GOT.
p -- print raw symbol name.
but it also emits its segment override. As shown in the above example, it is
not possible to use LEA to load its address into a register.
Similar problem is with %P modifier, trying to CALL or JMP to overriden
symbol,e.g:
call %gs:zzz
jmp %gs:zzz
call.s:1: Warning: skipping prefixes on `call'
call.s:2: Warning: skipping prefixes on `jmp'
More information about the Gcc-bugs
mailing list