Page MenuHomePhabricator

Move routines for guessing mode/target from driver to ToolChain

Authored by zarko on Sep 18 2015, 1:26 PM.



The Clang gcc-compatible driver (clang/tools/driver/driver.cpp) has some logic to select an alternate target based on the executable it was called as. For instance, if you symlink i686-linux-android-gcc to clang and invoke it, the driver will act as though it were called with another argument ("-target i686-linux-android"). This leads to visible effects even in syntax-only compilations (like the ANDROID preprocessor symbol being defined).

This behavior is not replicated for tool invocations--for instance, clang::createInvocationFromCommandLine will not choose an alternate target based on ArgList[0]. This means that configurations stored in compilation databases aren't accurately replayed.

This diff separates the logic for selecting a mode flag and target from the executable name into a new member function on ToolChain. It should have no functional effects (but will allow other code to reuse the target/mode selection logic).

Diff Detail


Event Timeline

zarko updated this revision to Diff 35129.Sep 18 2015, 1:26 PM
zarko retitled this revision from to Move routines for guessing mode/target from driver to ToolChain.
zarko updated this object.
zarko added reviewers: rnk, echristo.
zarko set the repository for this revision to rL LLVM.
zarko added a subscriber: cfe-commits.
echristo accepted this revision.Sep 21 2015, 2:01 PM
echristo edited edge metadata.

Looks like a straight move? If so, LGTM, if not can you explain what changed?

This revision is now accepted and ready to land.Sep 21 2015, 2:01 PM
zarko added a comment.Sep 21 2015, 2:55 PM

This should be a straight move, unless there is something I don't understand about the semantics of llvm::InitializeAllTargets(); that would make moving it earlier in main a bad idea.

Nothing comes to mind.




I don't have commit access; would someone who does please land this?

Oh, sure I can.

Done thusly:

dzur:~/sources/llvm/tools/clang> git svn dcommit
Committing to ...
M include/clang/Driver/ToolChain.h
M lib/Driver/ToolChain.cpp
M tools/driver/driver.cpp
Committed r248592


zarko closed this revision.Oct 1 2015, 10:53 AM