简体   繁体   English

有选择地忽略MSVC中的帧指针

[英]Selectively omit frame pointer in MSVC

In GCC i can selectively set optimization flags for specific function, so this: 在GCC中,我可以有选择地为特定功能设置优化标志,因此:

void func() {}

generates: 产生:

func():
    push    rbp
    mov     rbp, rsp
    nop
    pop     rbp
    ret

And this: 和这个:

__attribute__((optimize("-fomit-frame-pointer")))
void func() {}

generates: 产生:

func():
        nop
        ret

How can i do the same in visual studio? 我如何在Visual Studio中做同样的事情?

There's a command line parameter to the compiler, /Oy , this makes the compiler to omit frame pointers. 编译器有一个命令行参数/Oy ,这使编译器可以省略帧指针。 You can achieve the same with #pragma : 您可以使用#pragma实现相同的目的:

#pragma optimize("y", on)

int foo(int a) { // foo will be compiled with omitted frame pointers
    return a;
}

#pragma optimize("y", off)

Here, foo() will be compiled with omitted frame pointers. 在这里, foo()将使用省略的帧指针进行编译。

Note: As I see, you have to build an optimized build to make this option have an effect. 注意:如我所见,您必须构建一个优化的版本才能使此选项生效。 So, either supply some optimization flag to the compiler (like "/Og"), or include "g" into the pragma: #pragma optimize("gy", ...) 因此,要么为编译器提供一些优化标志(例如“ / Og”),要么将“ g”包含在编译指示中: #pragma optimize("gy", ...)

(I've checked this with Visual Studio 2015) (我已使用Visual Studio 2015进行了检查)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM