clang dependency generation (-Mxx) with -emit-llvm

Hi All,

I’m attempting to use the above-mentioned flags together but I cannot figure out a combination of flags that will get clang to emit the dependency file if the emit-llvm flag is also on. I’ve seen examples in the forums of people doing this, so it seems like it should work, but there must be some small mistake I’m making.

clang++ -O2 -o build/network.ll network.cxx -std=c++11 -S -emit-llvm -target my_target -I /depot/include -I build -v -MMD -MP -MF build/network.ll.dep.mk -MT build/network.ll

I’ve tried a number of variations on the compiler -M flags to no avail. We do have a custom target my_target that really only adds a few additional defines into the environment. Do we need to specify something in our target to allow dependency generation?

Thanks!

This question is probably better addressed to the Clang mailing list. Moving llvm-dev to BCC so replies move to cfe-dev.

Hi All,

I'm attempting to use the above-mentioned flags together but I cannot
figure out a combination of flags that will get clang to emit the
dependency file if the emit-llvm flag is also on. I've seen examples in the
forums of people doing this, so it seems like it should work, but there
must be some small mistake I'm making.

clang++ -O2 -o build/network.ll network.cxx -std=c++11 -S -emit-llvm
-target my_target -I /depot/include -I build -v -MMD -MP -MF build/
network.ll.dep.mk -MT build/network.ll

That works for me:

$ touch network.cxx
$ mkdir build
$ clang++ -O2 -o build/network.ll network.cxx -std=c++11 -S -emit-llvm
-target x86_64 -I /depot/include -I build -v -MMD -MP -MF build/
network.ll.dep.mk -MT build/network.ll
$ ls build
network.ll network.ll.dep.mk
$ cat build/network.ll.dep.mk
build/network.ll: network.cxx

Can you try running clang under strace and see whether it tries to open
your .dep.mk file?

I've tried a number of variations on the compiler -M flags to no avail. We

do have a custom target my_target that really only adds a few additional
defines into the environment. Do we need to specify something in our target
to allow dependency generation?

Do you see a dependency file being generated if you use a different target?

Yes, the dependency file gets generated if I use one of the standard targets.

When running clang++, it turns around and recalls clang (clang-3.9 specifically) with a bunch of options, one of which includes a -dependency-file build/network.ll.dep.mk which looks promising. However, I tried to run clang with those arguments via copy/paste into the shell and I get the following errors.

error: unknown argument: ‘–driver-mode=g++’
error: unknown argument: ‘–target=my_target’
error: unknown argument: ‘-MMD’
error: unknown argument: ‘-MF’

Those errors do not show up when invoked internally from clang++, and the output file is generated successfully but the dependency file is not. That seems to match the fact that those unknown arguments show up above. I know the target is being recognized because custom passes we’ve inserted specifically for our target are getting run. I’m guessing the -triple argument is sufficient for triggering the proper backend.

Is there a way for me to strace into the sub-clang process invoked by clang++? I’m not very familiar with those tools, but running strace just on clang++ reveals very little other than gathering a few things and then spawning off clang-3.9.

Dustyn Blasig via cfe-dev <cfe-dev@lists.llvm.org> writes:

Yes, the dependency file gets generated if I use one of the standard targets.

When running clang++, it turns around and recalls clang (clang-3.9
specifically) with a bunch of options, one of which includes a
-dependency-file build/network.ll.dep.mk which looks promising. However, I
tried to run clang with those arguments via copy/paste into the shell and I
get the following errors.

error: unknown argument: '--driver-mode=g++'
error: unknown argument: '--target=my_target'
error: unknown argument: '-MMD'
error: unknown argument: '-MF'

Those errors do not show up when invoked internally from clang++, and the
output file is generated successfully but the dependency file is not. That
seems to match the fact that those unknown arguments show up above. I know the
target is being recognized because custom passes we've inserted specifically
for our target are getting run. I'm guessing the -triple argument is
sufficient for triggering the proper backend.

Is there a way for me to strace into the sub-clang process invoked by clang++?
I'm not very familiar with those tools, but running strace just on clang++
reveals very little other than gathering a few things and then spawning off
clang-3.9.

IIRC strace has a -f flag that follows forks into children. You can also
run your clang command with -### and it should print out the subcommand
it will spawn.