From 6ecc7a993f939c5255c36c7c0d965fb9c1543f2a Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sat, 2 May 2009 21:41:52 +0000 Subject: [PATCH] Driver: When using the generic gcc tool, pass -m32 or -m64 if we recognize the architecture. - This is an attempt to force gcc to the write target. - PR4094. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70647 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 11 ++++++++++- test/Driver/unknown-gcc-arch.c | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/Driver/unknown-gcc-arch.c diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d79f850f07..a714be81c3 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -617,7 +617,8 @@ void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, if (A->getOption().hasForwardToGCC()) { // It is unfortunate that we have to claim here, as this means // we will basically never report anything interesting for - // platforms using a generic gcc. + // platforms using a generic gcc, even if we are just using gcc + // to get to the assembler. A->claim(); A->render(Args, CmdArgs); } @@ -638,6 +639,14 @@ void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Str); } + // Try to force gcc to match the tool chain we want, if we recognize + // the arch. + const char *Str = getToolChain().getArchName().c_str(); + if (strcmp(Str, "i386") == 0 || strcmp(Str, "powerpc") == 0) + CmdArgs.push_back("-m32"); + else if (strcmp(Str, "x86_64") == 0 || strcmp(Str, "powerpc64") == 0) + CmdArgs.push_back("-m64"); + if (Output.isPipe()) { CmdArgs.push_back("-o"); CmdArgs.push_back("-"); diff --git a/test/Driver/unknown-gcc-arch.c b/test/Driver/unknown-gcc-arch.c new file mode 100644 index 0000000000..de9e8e84c4 --- /dev/null +++ b/test/Driver/unknown-gcc-arch.c @@ -0,0 +1,8 @@ +// RUN: clang -ccc-host-triple x86_64-unknown-unknown -c -x assembler %s -### 2> %t.log && +// RUN: grep '.*gcc.*"-m64"' %t.log && +// RUN: clang -ccc-host-triple x86_64-unknown-unknown -c -x assembler %s -### -m32 2> %t.log && +// RUN: grep '.*gcc.*"-m32"' %t.log && +// RUN: clang -ccc-host-triple i386-unknown-unknown -c -x assembler %s -### 2> %t.log && +// RUN: grep '.*gcc.*"-m32"' %t.log && +// RUN: clang -ccc-host-triple i386-unknown-unknown -c -x assembler %s -### -m64 2> %t.log && +// RUN: grep '.*gcc.*"-m64"' %t.log -- 2.40.0