概述
本文只从结果进行表述,详细原因请参考:记一次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 queue
toRemove->handleTimeout(); // call <3>
}
}
<3>
virtual void AlarmHandler::handleTimeout() {
(*fProc)(fClientData);
DelayQueueEntry::handleTimeout();
}
最后
以上就是清爽睫毛为你收集整理的【编译】gcc -O2 编译flag里面做了什么的全部内容,希望文章能够帮你解决【编译】gcc -O2 编译flag里面做了什么所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复