[PATCH] D109407: [InlineAsm] Support call function label in x86 inline asm with PIC
Xiang Zhang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 7 17:58:34 PDT 2021
xiangzhangllvm created this revision.
xiangzhangllvm added reviewers: craig.topper, LuoYuanke, pengfei, RKSimon, jyu2.
Herald added a subscriber: hiraditya.
xiangzhangllvm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
In Linux PIC model, Global Address (GA) of Global Variable (GV) will be got from loading GOT slot.
Different instructions has different understanding about using Global Address.
**For example** in X86:
1. We assign a value to GV, we can use "MOV GV, ...", it corresping to "MOV (Global Address) ...".
2. We got related address of GV, we can use "LEA GV, ...", it corresping to "LEA (Global Address) ...".
3. But if we call the label (GV can be a label), we can use "CALL GV", it didn't equal with "CALL (Global Address)".
So, it is obvious that Global Address of Global Variable should be specially handled case by case.
This is done in normal IR/MIR which has "single" purpose use of the Global Address.
But things changed in inline asm which represented by only one IR/MIR but may contains
a lot of instructions with mult-purpose on same or different Global Address.
What is more, **llvm didn't distinguish the instructions in inline asm IR/MIR**.
**TODO**: The other targets may also has this problem, we need to fix them too. It is an arch defect for llvm inline asm.
**llvm-dev link**: https://lists.llvm.org/pipermail/llvm-dev/2021-August/152144.html
Take a concrete example: test.c: (clang t.c -fasm-blocks -S -fpic -emit-llvm test.c )
extern void sincos();
int GV=3;
int Arr[10] = {1,};
void foo() {
asm {
lea r8, Arr
mov rax, GV
lea r9, sincos
call sincos
ret }
}
it will generate following wrong code:
movq sincos at GOTPCREL(%rip), %rsi
movq GV at GOTPCREL(%rip), %rdx
movq Arr at GOTPCREL(%rip), %rcx
#APP
leaq (%rcx), %r8
movq (%rdx), %rax // Not like "MOV GV", CALL don't get the context of the Function sincos
leaq (%rsi), %r9 // CALL Not like "LEA sincos", LEA can get the address without Dereference
callq *(%rsi) // It should directly call the sincos --> callq %rsi --> in normal case (non-large code model) it should be "**call sincos at PLT**"
retq
#NO_APP
https://reviews.llvm.org/D109407
Files:
llvm/include/llvm/CodeGen/TargetSubtargetInfo.h
llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
llvm/lib/Target/X86/X86AsmPrinter.cpp
llvm/test/CodeGen/X86/inline-asm-call.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109407.371223.patch
Type: text/x-patch
Size: 20487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210908/0b18b99e/attachment.bin>
More information about the llvm-commits
mailing list