Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22029

How can i get gcc profile guided optimizations to stop writing files after being 'optimized'?

$
0
0

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.

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)elseall:  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 version is gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008

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

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: 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....


Viewing all articles
Browse latest Browse all 22029

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>