JonBelanger
JonBelanger

Reputation: 150

How can I get the path to clang when clang runs the linker?

I am working with LLVM 8.0 and clang and am performing some work during the optimization and I need to get the path to clang. I am running clang using the -flto flag, so that clang actually calls the linker and ultimately my code. I am doing this on Ubuntu 16.04.

I'm trying to get the image path using readlink("/proc/self/exe");. The clang image was build in my home folder, so the path I specify to run clang is /home/users/me/llvm/build/llvm/bin/clang. I also have a version of clang installed in /usr/bin/clang.

What I get from the call to readlink is: /usr/bin/ld. What I want to get is: /home/users/me/llvm/bin/clang.

I realize that -flto calls system() with /usr/bin/ld ... as the command to run. But how can I get the clang path? Since I have multiple versions of clang, I cannot use whereis or the like, as it will return either the wrong one or multiple.

Is there a global variable in LLVM, or some way to query LLVM, or some way I have not yet discovered to get the image path for the parent process?


The suggestions for using getppid and using the in the "?/proc//exe" worked perfectly.

Upvotes: 0

Views: 2596

Answers (1)

JonBelanger
JonBelanger

Reputation: 150

The suggestion by @Ismail was perfect. Did exactly what I wanted it to.

Upvotes: 1

Related Questions