Ping patches. Without these two patches, using clang as a cross compiler is a difficult task involving the use of external scripts around clang to set an appropriate -ccc-host-triple flag that will set the target toolchain.
With these patches, one can configure clang to create a default target toolchain as specified by the --target flag at configure time. The default target toolchain *should not* be inferred from the host triplet: my patches only address this issue. Could somebody please let me know who maintains the configure scripts and who should be able to review and commit these changes? Thanks, Sebastian -- Qualcomm Innovation Center, Inc is a member of Code Aurora Forum On Mon, Oct 17, 2011 at 2:11 PM, Sebastian Pop <[email protected]> wrote: > On Mon, Oct 17, 2011 at 1:43 PM, Eric Christopher <[email protected]> wrote: >> Not quite sure what you're going for here. Is the idea to try to make >> --host=xxx and --target=yyy work in clang? > > Yes. The attached patches make --target work. > For the moment specifying --target at configure time has no effect: > the value set by the configure script into $target is not used. > Currently we are using the value set by the configure scripts in > $host to build the target toolchain, and this is IMHO the wrong > thing to do. > > With these two patches, we take the value from $target and use it > to build the default target toolchain: so when I say > configure --target=arm-none-linux-gnueabi > I get a clang that produces ARM assembly by default > (without these two patches, I currently get x86_64 assembly as > the host is x86_64). > > Thanks, > Sebastian > -- > Qualcomm Innovation Center, Inc is a member of Code Aurora Forum > >> >> -eric >> >> On Oct 17, 2011, at 10:22 AM, Sebastian Pop wrote: >> >>> Ping patches. >>> >>> On Thu, Oct 13, 2011 at 3:55 PM, Sebastian Pop <[email protected]> wrote: >>>> On Thu, Oct 13, 2011 at 3:14 PM, Joerg Sonnenberger >>>> <[email protected]> wrote: >>>>> LLVM_HOSTTRIPLE specifies the default *target*. It doesn't care about >>>>> the *host*. >>>> >>>> Ok, so let's get this one fixed: >>>> if you tell me the places where LLVM_HOSTTRIPLE is used for the target >>>> and that my patch has not changed into using the value set in $target, >>>> please let me know and I will amend my patches. >>>> >>> >>> Could somebody review and commit the attached patches? >>> >>> Thanks, >>> Sebastian >>> -- >>> Qualcomm Innovation Center, Inc is a member of Code Aurora Forum >>> <0001-add-getDefaultTargetTriple.patch.txt><0001-use-getDefaultTargetTriple-instead-of-getHostTriple.patch.txt>_______________________________________________ >>> llvm-commits mailing list >>> [email protected] >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> >
From 08bd5d82e6b4a4a0d218fd10044352f831fcc9ca Mon Sep 17 00:00:00 2001 From: Sebastian Pop <[email protected]> Date: Tue, 11 Oct 2011 12:04:55 -0500 Subject: [PATCH] add getDefaultTargetTriple --- autoconf/configure.ac | 2 ++ configure | 5 +++++ include/llvm/Config/config.h.cmake | 3 +++ include/llvm/Config/config.h.in | 3 +++ include/llvm/Config/llvm-config.h.cmake | 3 +++ include/llvm/Config/llvm-config.h.in | 3 +++ include/llvm/Support/Host.h | 9 +++++++++ lib/Support/Unix/Host.inc | 19 +++++++++++++------ lib/Support/Windows/Host.inc | 5 +++++ 9 files changed, 46 insertions(+), 6 deletions(-) diff --git a/autoconf/configure.ac b/autoconf/configure.ac index bdbb524..f8a5544 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -1456,6 +1456,8 @@ AC_DEFINE_UNQUOTED(LLVM_CONFIGTIME, "$LLVM_CONFIGTIME", [Time at which LLVM was configured]) AC_DEFINE_UNQUOTED(LLVM_HOSTTRIPLE, "$host", [Host triple we were built on]) +AC_DEFINE_UNQUOTED(LLVM_DEFAULT_TARGET_TRIPLE, "$target", + [Default target triple to build for]) # Determine which bindings to build. if test "$BINDINGS_TO_BUILD" = auto ; then diff --git a/configure b/configure index 1257d7a..d48057b 100755 --- a/configure +++ b/configure @@ -20867,6 +20867,11 @@ cat >>confdefs.h <<_ACEOF _ACEOF +cat >>confdefs.h <<_ACEOF +#define LLVM_DEFAULT_TARGET_TRIPLE "$target" +_ACEOF + + # Determine which bindings to build. if test "$BINDINGS_TO_BUILD" = auto ; then BINDINGS_TO_BUILD="" diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake index e44d429..9c56c99 100644 --- a/include/llvm/Config/config.h.cmake +++ b/include/llvm/Config/config.h.cmake @@ -557,6 +557,9 @@ /* Host triple we were built on */ #cmakedefine LLVM_HOSTTRIPLE "${LLVM_HOSTTRIPLE}" +/* Default target triple to build for */ +#cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" + /* Installation directory for include files */ #cmakedefine LLVM_INCLUDEDIR "${LLVM_INCLUDEDIR}" diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in index 86f4e77..b396d38 100644 --- a/include/llvm/Config/config.h.in +++ b/include/llvm/Config/config.h.in @@ -543,6 +543,9 @@ /* Installation directory for data files */ #undef LLVM_DATADIR +/* Default target triple to build for */ +#undef LLVM_DEFAULT_TARGET_TRIPLE + /* Installation directory for documentation */ #undef LLVM_DOCSDIR diff --git a/include/llvm/Config/llvm-config.h.cmake b/include/llvm/Config/llvm-config.h.cmake index 4147fd1..ff3ab74 100644 --- a/include/llvm/Config/llvm-config.h.cmake +++ b/include/llvm/Config/llvm-config.h.cmake @@ -37,6 +37,9 @@ /* Host triple we were built on */ #cmakedefine LLVM_HOSTTRIPLE "${LLVM_HOSTTRIPLE}" +/* Default target triple to build for */ +#cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" + /* Installation directory for include files */ #cmakedefine LLVM_INCLUDEDIR "${LLVM_INCLUDEDIR}" diff --git a/include/llvm/Config/llvm-config.h.in b/include/llvm/Config/llvm-config.h.in index b2257f3..49288fd 100644 --- a/include/llvm/Config/llvm-config.h.in +++ b/include/llvm/Config/llvm-config.h.in @@ -37,6 +37,9 @@ /* Host triple we were built on */ #undef LLVM_HOSTTRIPLE +/* Default target triple to build for */ +#undef LLVM_DEFAULT_TARGET_TRIPLE + /* Installation directory for include files */ #undef LLVM_INCLUDEDIR diff --git a/include/llvm/Support/Host.h b/include/llvm/Support/Host.h index f77d4c1..ec17a4d 100644 --- a/include/llvm/Support/Host.h +++ b/include/llvm/Support/Host.h @@ -33,6 +33,15 @@ namespace sys { return !isLittleEndianHost(); } + /// getDefaultTargetTriple() - Return the triple of the default + /// target system. + /// + /// The target triple is a string in the format of: + /// CPU_TYPE-VENDOR-OPERATING_SYSTEM + /// or + /// CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM + std::string getDefaultTargetTriple(); + /// getHostTriple() - Return the target triple of the running /// system. /// diff --git a/lib/Support/Unix/Host.inc b/lib/Support/Unix/Host.inc index dda3ce2..f76ed2a 100644 --- a/lib/Support/Unix/Host.inc +++ b/lib/Support/Unix/Host.inc @@ -35,12 +35,9 @@ static std::string getOSVersion() { return info.release; } -std::string sys::getHostTriple() { - // FIXME: Derive directly instead of relying on the autoconf generated - // variable. - - StringRef HostTripleString(LLVM_HOSTTRIPLE); - std::pair<StringRef, StringRef> ArchSplit = HostTripleString.split('-'); +static std::string getTriple(const char *name) { + StringRef TripleString(name); + std::pair<StringRef, StringRef> ArchSplit = TripleString.split('-'); // Normalize the arch, since the host triple may not actually match the host. std::string Arch = ArchSplit.first; @@ -64,3 +61,13 @@ std::string sys::getHostTriple() { return Triple; } + +std::string sys::getDefaultTargetTriple() { + return getTriple(LLVM_DEFAULT_TARGET_TRIPLE); +} + +std::string sys::getHostTriple() { + // FIXME: Derive directly instead of relying on the autoconf generated + // variable. + return getTriple(LLVM_HOSTTRIPLE); +} diff --git a/lib/Support/Windows/Host.inc b/lib/Support/Windows/Host.inc index 733830e..278550a 100644 --- a/lib/Support/Windows/Host.inc +++ b/lib/Support/Windows/Host.inc @@ -21,3 +21,8 @@ std::string sys::getHostTriple() { // FIXME: Adapt to running version. return LLVM_HOSTTRIPLE; } + +std::string sys::getDefaultTargetTriple() { + // FIXME: Adapt to running version. + return LLVM_DEFAULT_TARGET_TRIPLE; +} -- 1.7.3
From 241e142d1f70a9a3c227e0fc78b0d73905395e1e Mon Sep 17 00:00:00 2001 From: Sebastian Pop <[email protected]> Date: Tue, 11 Oct 2011 12:07:51 -0500 Subject: [PATCH] use getDefaultTargetTriple instead of getHostTriple --- examples/clang-interpreter/main.cpp | 2 +- lib/Frontend/CompilerInvocation.cpp | 4 ++-- lib/Frontend/CreateInvocationFromCommandLine.cpp | 2 +- tools/driver/cc1as_main.cpp | 4 ++-- tools/driver/driver.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp index c9734e5..4192c09 100644 --- a/examples/clang-interpreter/main.cpp +++ b/examples/clang-interpreter/main.cpp @@ -76,7 +76,7 @@ int main(int argc, const char **argv, char * const *envp) { llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); DiagnosticsEngine Diags(DiagID, DiagClient); - Driver TheDriver(Path.str(), llvm::sys::getHostTriple(), + Driver TheDriver(Path.str(), llvm::sys::getDefaultTargetTriple(), "a.out", /*IsProduction=*/false, Diags); TheDriver.setTitle("clang interpreter"); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index d92cf40..7e0fe3d 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1897,9 +1897,9 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) { Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version); Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); - // Use the host triple if unspecified. + // Use the default target triple if unspecified. if (Opts.Triple.empty()) - Opts.Triple = llvm::sys::getHostTriple(); + Opts.Triple = llvm::sys::getDefaultTargetTriple(); } // diff --git a/lib/Frontend/CreateInvocationFromCommandLine.cpp b/lib/Frontend/CreateInvocationFromCommandLine.cpp index fc15081..e94b944 100644 --- a/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -48,7 +48,7 @@ clang::createInvocationFromCommandLine(ArrayRef<const char *> ArgList, Args.push_back("-fsyntax-only"); // FIXME: We shouldn't have to pass in the path info. - driver::Driver TheDriver("clang", llvm::sys::getHostTriple(), + driver::Driver TheDriver("clang", llvm::sys::getDefaultTargetTriple(), "a.out", false, *Diags); // Don't check that inputs exist, they may have been remapped. diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index 7cc42aa..19e632a 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -151,8 +151,8 @@ void AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, // Target Options Opts.Triple = Triple::normalize(Args->getLastArgValue(OPT_triple)); - if (Opts.Triple.empty()) // Use the host triple if unspecified. - Opts.Triple = sys::getHostTriple(); + if (Opts.Triple.empty()) // Use the default target triple if unspecified. + Opts.Triple = sys::getDefaultTargetTriple(); // Language Options Opts.IncludePaths = Args->getAllArgValues(OPT_I); diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index bd1d2a2..4f5d3fe 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -382,7 +382,7 @@ int main(int argc_, const char **argv_) { #else const bool IsProduction = false; #endif - Driver TheDriver(Path.str(), llvm::sys::getHostTriple(), + Driver TheDriver(Path.str(), llvm::sys::getDefaultTargetTriple(), "a.out", IsProduction, Diags); // Attempt to find the original path used to invoke the driver, to determine -- 1.7.3
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
