我如何获得gcc配置文件引导的优化以在“优化"后停止写入文件? [英] How can i get gcc profile guided optimizations to stop writing files after being 'optimized'?

查看:134
本文介绍了我如何获得gcc配置文件引导的优化以在“优化"后停止写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在makefile中执行此操作,它会在第一次运行时在该目录中创建.gcda文件.但是,只要我执行第二步,如果发现可执行文件的运行速度几乎一样慢(而且这肯定是相关的),在编译后仍将 new 文件写入dir.据我了解,这不应该发生.删除-fprofile-arcs(或-lgcov)会使第二个编译器抱怨缺少符号.我想念什么?我在这两个执行之间都make clean.

I'm doing this in a makefile and it results on the first run creating the .gcda files in that dir; but as soon as i do the second, if find that the executable is almost as slow (and this is surely related), is still writing new files to the dir after compiled. From my understanding this shouldn't occur. Removing -fprofile-arcs (or -lgcov for that matter) makes the second compile complain about missing symbols. What amd i missing? I make clean in between both of these executions btw.

除了-lgcov之外,我还尝试了一些变体,但是我通过阅读手册达到了这一点,并且意识到-fprofile-use打开了很多优化,包括-fprofile-arcs,而我尝试过的任何简单选择都没有.

I also tried some variations besides -lgcovbut i reached this one from reading the manual and realizing -fprofile-use opens a lot of optimizations, including -fprofile-arcs and no easy alternative i tried was working.

PROFILE_DIR=/tmp/pgo/${PN}
ifeq ($(wildcard $(PROFILE_DIR)),)
all:
  CXXFLAGS += -O3 -march=native -fprofile-generate=${PROFILE_DIR} -fprofile-correction
  CFLAGS   += -O3 -march=native -fprofile-generate=${PROFILE_DIR} -fprofile-correction
  LDFLAGS  += -fprofile-arcs
  $(info profile-sampling build)
else
all:
  CXXFLAGS += -O3 -march=native -fprofile-use=${PROFILE_DIR} -fprofile-correction
  CFLAGS   += -O3 -march=native -fprofile-use=${PROFILE_DIR} -fprofile-correction
  LDFLAGS  += -fprofile-arcs
  $(info profile-guided build)
endif

gcc版本为gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008

带有文件的案件的最终LDFLAGS已经是:-lpthread -ldl -lrt -fPIC -shared -Wl,--no-undefined -Wl,--version-script=link.T -fprofile-arcs

edit: the final LDFLAGS of the case with the files already is : -lpthread -ldl -lrt -fPIC -shared -Wl,--no-undefined -Wl,--version-script=link.T -fprofile-arcs

如果我没记错的话,-Wl,--no-undefined会破坏不链接gcov或不使用-fprofile-arcs的原因,因为gcov的符号即使在不再重要的位置也位于使用的文件中,并且该选项明确地使所有缺少的符号编译失败.因此,解决方案可能是在第二次编译中省略了-fprofile-arcs,并且(以某种方式)只允许单个库gcov包含未初始化的符号.我不知道如何尝试第二个.

If i'm not mistaken,-Wl,--no-undefined is sabotaging not linking gcov or not using -fprofile-arcs because the symbols for gcov are somewhere in the files used even if they're no longer important and that option explicitly fails the compile on all missing symbols. So the solution might be omitting -fprofile-arcs in the second compile and (somehow) allowing just this single library gcov to have uninitialized symbols. I don't know how to try the second.

edit 2:不幸的是,不,它在没有该标志且没有链接到-gcov(直接或间接)的情况下崩溃.因此,.gcda文件中的东西会强制-lgcov,这会强制生成的可执行文件开始写入.gcda文件,但是,如果您尝试删除-lgcov,则会导致构建失败或崩溃运行.我不知道这应该如何工作,或者为什么这些文件不只是编译时的工件....

edit 2: unfortunately, no, it crashes at runtime without that flag and without the linking to -gcov (direct or indirect). So something in the .gcda files is forcing -lgcov and that forces the resulting executable to start writing .gcda files, but if you try to remove the -lgcov you either get a failed build or a crash at runtime. I don't understand how this is supposed to work, or why those files are not just a compile time artifact....

推荐答案

这是由于"make clean"而不是删除所有创建的.o文件而是过时的部分硬编码列表引起的.第二个编译重用"了第一个(带工具的)编译中的某些.o文件,因此需要-lgcov LDFLAG,后者自然会启动第二个编译以再次进行概要分析.

This was caused by 'make clean' not removing all created .o files but a outdated partial hardcoded list. The second compilation 'reused' some .o files from the first (instrumented) compilation, and thus required the -lgcov LDFLAG which naturally started the second compilation to profile again.

这篇关于我如何获得gcc配置文件引导的优化以在“优化"后停止写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆