[PATCH] D54016: [X86] don't allow X86_64 PIC mode addresses to be used as immediates
Reid Kleckner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 27 11:42:58 PST 2018
rnk added a comment.
Here is the original test case from the PR:
#include <stdio.h>
int offset = 0;
static void foo2() { printf("foo2 is called\n"); }
void foo() {
__asm__ volatile("movq %0,%%gs:(%1)" : : "ir"((void *)&foo2), "r"(offset));
printf("foo is called\n");
}
If you compile with GCC, you will see that it generates the same assembly that LLVM does:
foo:
.LFB15:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movl offset(%rip), %eax
#APP
# 21 "t.c" 1
movq $foo2,%gs:(%eax)
# 0 "" 2
#NO_APP
leaq .LC1(%rip), %rdi
call puts at PLT
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
So, I think LLVM is already correct here. You can confirm on compiler explorer: https://gcc.godbolt.org/z/rOHCb6
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D54016/new/
https://reviews.llvm.org/D54016
More information about the llvm-commits
mailing list