[llvm-bugs] [Bug 37573] New: AArch64 MachineOutliner incorrectly outlines use of r16/r17
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed May 23 18:41:13 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=37573
Bug ID: 37573
Summary: AArch64 MachineOutliner incorrectly outlines use of
r16/r17
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: AArch64
Assignee: unassignedbugs at nondot.org
Reporter: efriedma at codeaurora.org
CC: jpaquette at apple.com, llvm-bugs at lists.llvm.org
Take the following contrived testcase; compile it with "-O2 -mllvm
-enable-machine-outliner -ffunction-sections", for the target
aarch64-pc-linux-gnu. The resulting binary prints 19454, when it should print
5. The problem is that calling the outlined function requires a veneer, so r16
gets clobbered.
It's probably unlikely this will come up in practice... usually the outlined
function will be close enough to its callers that we don't need a veneer. But
it would be painful to debug if someone did manage to trip over it somehow.
In theory, the linker could also clobber r17, but that doesn't seem to happen
in practice; not sure if it's a good idea to try to take advantage of that.
(Without -ffunction-sections, the testcase fails to compile; that's also an
issue, but it's very unlikely to come up in practice, and it prints a readable
error message. There are four separate padding functions to work around a bug
in binutils ld: the program fails to link with a single, larger padding
function.)
#include <stdio.h>
int a(int x) {
register int y asm("r16") = x;
asm("nop":"+r"(y));
y = (y*33333+44444)/55555+2;
asm("nop":"+r"(y));
return y+1;
}
int b(int x) {
register int y asm("r16") = x;
asm("nop":"+r"(y));
y = (y*33333+44444)/55555+2;
asm("nop":"+r"(y));
return y+2;
}
void c() {
asm(".fill 0x2000000");
}
void c2() {
asm(".fill 0x2000000");
}
void c3() {
asm(".fill 0x2000000");
}
void c4() {
asm(".fill 0x2000000");
}
int main() {
void * volatile aa = a, * volatile bb = b;
printf("%d\n", ((int(*)(int))aa)(3));
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180524/c1bf028d/attachment.html>
More information about the llvm-bugs
mailing list