x
login Signup

emake compatibility when enable LTO

When build Yocto project, if we enable LTO (Link time optimization) by adding below CFLAGS and LDFLAGS to bb file:

TARGET_CFLAGS += "-flto -fno-fat-lto-objects" TARGET_LDFLAGS += "-flto=8 -fno-fat-lto-objects -fuse-linker-plugin"

Then we will get this error:

| /DATA/workspace/Z_POC_AVN_PREMIUM6_DAILYBUILD_101_LTO_TEST/build/premium6-kr/tmp/sysroots/x86_64-linux/usr/libexec/aarch64-gnu-linux/gcc/aarch64-gnu-linux/6.4.1/ld: cannot find /DATA/workspace/eatemp/agentemp-6/cczHgR2b.ltrans0.ltrans.o: No such file or directory | /DATA/workspace/Z_POC_AVN_PREMIUM6_DAILYBUILD_101_LTO_TEST/build/premium6-kr/tmp/sysroots/x86_64-linux/usr/libexec/aarch64-gnu-linux/gcc/aarch64-gnu-linux/6.4.1/ld: cannot find /DATA/workspace/eatemp/agentemp-6/cczHgR2b.ltrans1.ltrans.o: No such file or directory | /DATA/workspace/Z_POC_AVN_PREMIUM6_DAILYBUILD_101_LTO_TEST/build/premium6-kr/tmp/sysroots/x86_64-linux/usr/libexec/aarch64-gnu-linux/gcc/aarch64-gnu-linux/6.4.1/ld: cannot find /DATA/workspace/eatemp/agentemp-6/cczHgR2b.ltrans2.ltrans.o: No such file or directory | /DATA/workspace/Z_POC_AVN_PREMIUM6_DAILYBUILD_101_LTO_TEST/build/premium6-kr/tmp/sysroots/x86_64-linux/usr/libexec/aarch64-gnu-linux/gcc/aarch64-gnu-linux/6.4.1/ld: error: could not unlink output file

How to fix this?

avatar image By holy 47 asked Apr 19 at 11:21 AM
more ▼
(comments are locked)
10|750 characters needed characters left

1 answer: sort voted first

After analyzing the anno file, We noticed that there are something could cause this problem, in the failed job: J0000000001adfb50, there is a submake (ID: M00000004) , which called: “/opt/ecloud/i686_Linux/64/bin/emake -f /DATA/workspace/eatemp/agentemp-1/ccX1IZbl.mk -j8 all” The tmp directory: /DATA/workspace/eatemp/agentemp-1/ is not in emake-root, but it’s accessed by emake at here.

And this submake is actually generated due to the -flto=8 option we used

Please check out the document here: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html , the -flto[=n] section:

If you specify the optional n, the optimization and code generation done at link time is executed in parallel using n parallel jobs by utilizing an installed make program. The environment variable MAKE may be used to override the program used. The default value for n is 1.

It’s funny that a link command need to generate a Makefile (in the $TMP directory) and run make

So the simple solution is to use “-flto=1” instead of 8. Or tell gcc to generate those file somewhere else, but we couldn’t find documentation to change the location of the files that were generated in this step.

Then the solution is to use “-flto=1”.

avatar image By holy 47 answered Apr 19 at 11:23 AM
more ▼
(comments are locked)
10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.