本文主要是介绍【编译】gcc -O2 编译flag里面做了什么,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文只从结果进行表述,详细原因请参考:记一次gcc -O2大幅度增加binary size的问题_电影旅行敲代码的博客-CSDN博客
用live555进行了一个测试,正常代码逻辑为以下
<1> -> <2> -> <3>
不设置-O flag,调用堆栈为<1> -> <2> -> <3>
编译出的文件size
$ ll live555/libBasicUsageEnvironment.so.1
-rwxrwxr-x 1 dljx dljx 119256 Apr 14 17:36 live555/libBasicUsageEnvironment.so.1
调用堆栈:
#1 0x00007ffff30c8a69 in AlarmHandler::handleTimeout (this=0x7fffe4001230) at BasicTaskScheduler0.cpp:34
#2 0x00007ffff30caae4 in DelayQueue::handleAlarm (this=0x66f1f8) at DelayQueue.cpp:187
#3 0x00007ffff30c9a8c in BasicTaskScheduler::SingleStep (this=0x66f1f0, maxDelayTime=0) at BasicTaskScheduler.cpp:212
#4 0x00007ffff30c82c6 in BasicTaskScheduler0::doEventLoop (this=0x66f1f0, watchVariable=0x66f1d0 "") at BasicTaskScheduler0.cpp:80
设置-O2 flag,调用堆栈为<1> -> <3>
编译出的文件size还变大
$ ll live555/libBasicUsageEnvironment.so.1
-rwxrwxr-x 1 dljx dljx 131824 Apr 14 17:23 live555/libBasicUsageEnvironment.so.1
调用堆栈:
#1 0x00007ffff30c9d8b in AlarmHandler::handleTimeout (this=0x7fffe4001230) at BasicTaskScheduler0.cpp:34
#2 0x00007ffff30ca5dd in BasicTaskScheduler::SingleStep (this=0x66f1f0, maxDelayTime=<optimized out>) at BasicTaskScheduler.cpp:212
#3 0x00007ffff30c96dc in BasicTaskScheduler0::doEventLoop (this=0x66f1f0, watchVariable=0x66f1d0 "") at BasicTaskScheduler0.cpp:80
代码块如下:
<1>
void BasicTaskScheduler::SingleStep(unsigned maxDelayTime) {....// Also handle any delayed event that may have come due.fDelayQueue.handleAlarm(); // call <2>
}
<2>
void DelayQueue::handleAlarm() {if (head()->fDeltaTimeRemaining != DELAY_ZERO) synchronize();if (head()->fDeltaTimeRemaining == DELAY_ZERO) {// This event is due to be handled:DelayQueueEntry* toRemove = head();removeEntry(toRemove); // do this first, in case handler accesses queuetoRemove->handleTimeout(); // call <3>}
}
<3>
virtual void AlarmHandler::handleTimeout() {(*fProc)(fClientData);DelayQueueEntry::handleTimeout();}
这篇关于【编译】gcc -O2 编译flag里面做了什么的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!