Qt,GCC,SSE和堆栈对齐 [英] Qt, GCC, SSE and stack alignment
问题描述
我试图编写一个用GCC编译的程序,并使用Qt和SSE内在函数。
看来,当我的一个函数被Qt调用时,堆栈对齐不会被保留。这里有一个简短的例子来说明我的意思:
#include< cstdio>
#include< emmintrin.h>
#include< QtGui / QApplication.h>
#include< QtGui / QWidget.h>
class Widget:public QWidget {
public:
void paintEvent(QPaintEvent *){
__m128 a;
printf(a:0x%08x \\\
,((void *)& a));
}
};
int main(int argc,char ** argv)
{
QApplication应用程序(argc,argv);
Widget w;
w.paintEvent(NULL); //从这里调用,我的函数行为正确
w.show();
w.update();
// Qt将调用Widget :: paintEvent,并且我的__m128不会是
//在16个字节上对齐,因为它应该是
application.processEvents();
返回0;
}
以下是输出:
a:0x0023ff40 //确定,这对齐16个字节
a:0x0023d14c //未对齐!
配置:
我尝试使用与我在Qt makefile中看到的选项相同的选项来编译示例程序:
-O2 -Wall -frtti -fexceptions -mthreads
,链接选项:
-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo- reloc -Wl,-s -mthreads
现在我不知道要在哪个方向上搜索。
任何提示将不胜感激。谢谢!
Fabien
您可以使用<$
-mstackrealign $ b $ c> -mstackrealign 可以在您的源代码中添加属性。 $ b在条目处重新对齐堆栈。在Intel x86上,-mstackrealign选项将生成备用序幕和尾声,以便在必要时重新对齐运行时堆栈。这支持将保留4字节对齐堆栈的传统代码与保留16字节堆栈以保持SSE兼容性的现代代码混合。另请参见属性force_align_arg_pointer,适用于各个功能。
(from GCC文档)
I'm trying to make a program compiled with GCC and using Qt and SSE intrinsics. It seems that when one of my functions is called by Qt, the stack alignment is not preserved. Here's a short example to illustrate what I mean :
#include <cstdio>
#include <emmintrin.h>
#include <QtGui/QApplication.h>
#include <QtGui/QWidget.h>
class Widget: public QWidget {
public:
void paintEvent(QPaintEvent *) {
__m128 a;
printf("a: 0x%08x\n", ((void *) &a));
}
};
int main(int argc, char** argv)
{
QApplication application(argc, argv);
Widget w;
w.paintEvent(NULL); // Called from here, my function behaves correctly
w.show();
w.update();
// Qt will call Widget::paintEvent and my __m128 will not be
// aligned on 16 bytes as it should
application.processEvents();
return 0;
}
Here's the output:
a: 0x0023ff40 // OK, that's aligned on 16 bytes
a: 0x0023d14c // Not aligned!
Configuration:
- Intel Core2
- WinXP, SP3
- GCC 4.4 (Mingw included in the Qt SDK 2010.01)
I tried to compile the example program with the same options as those I saw in the Qt makefile :
-O2 -Wall -frtti -fexceptions -mthreads
,link options:
-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads
Now I don't know in which directions to search. Any hints would be appreciated. Thanks!
Fabien
You can use the option -mstackrealign
to do that without adding attributes to your source code:
-mstackrealign Realign the stack at entry. On the Intel x86, the -mstackrealign option will generate an alternate prologue and epilogue that realigns the runtime stack if necessary. This supports mixing legacy codes that keep a 4-byte aligned stack with modern codes that keep a 16-byte stack for SSE compatibility. See also the attribute force_align_arg_pointer, applicable to individual functions.
(from the GCC docs)
这篇关于Qt,GCC,SSE和堆栈对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!