[llvm-bugs] [Bug 41612] New: unaligned access in 32-bit SSE PIC code
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Apr 26 04:10:51 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41612
Bug ID: 41612
Summary: unaligned access in 32-bit SSE PIC code
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: jay.foad at gmail.com
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, spatel+llvm at rotateright.com
I'm using Clang 8 on Ubuntu 19.04. I believe the bug affects at least clang 7
and 8 and trunk, according to godbolt.org.
$ clang --version
clang version 8.0.0-3 (tags/RELEASE_800/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
To reproduce:
cat h.c
typedef __attribute__((aligned)) struct { long long a[2]; } T;
T b(void);
int e(void);
void c(T *g) {
*g = b();
}
T h(T g) {
if (e())
c(&g);
return g;
}
$ cat main.c
typedef __attribute__((aligned)) struct { long long a[2]; } T;
T h(T);
T b(void) {
T x = {0};
return x;
}
int e(void) {
return 1;
}
int main() {
T x = {0};
(void)h(x);
return 0;
}
$ clang -m32 -O -march=pentium4 -mfpmath=sse -fPIC main.c h.c -o main -Wall
$ ./main
Segmentation fault (core dumped)
The problem seems to be that when c() is inlined into h(), it assigns to g
using a movapd instruction, even though g is an argument on the stack and is
not 16-byte aligned.
Here's a godbolt link: https://godbolt.org/z/LrgIXg
You can see that the disassembly of h() includes:
lea edi, [esp + 52]
...
movaps xmmword ptr [edi], xmm0
Assuming that esp was 16-byte aligned at this point, this does an unaligned
store to esp + 52.
--
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/20190426/8471e835/attachment.html>
More information about the llvm-bugs
mailing list