Skip to content

Commit 0a23fbd

Browse files
nathanchancenickdesaulniers
authored andcommitted
clang: Always pass PowerPC endian information to GNU as
When building a 64-bit big endian PowerPC Linux kernel with a 64-bit little endian PowerPC target, the 32-bit vDSO errors: ``` $ make ARCH=powerpc CC=clang CROSS_COMPILE=powerpc64le-linux-gnu- \ pseries_defconfig arch/powerpc/kernel/vdso32/ ld.lld: error: arch/powerpc/kernel/vdso32/sigtramp.o is incompatible with elf32-powerpc ld.lld: error: arch/powerpc/kernel/vdso32/gettimeofday.o is incompatible with elf32-powerpc ld.lld: error: arch/powerpc/kernel/vdso32/datapage.o is incompatible with elf32-powerpc ld.lld: error: arch/powerpc/kernel/vdso32/cacheflush.o is incompatible with elf32-powerpc ld.lld: error: arch/powerpc/kernel/vdso32/note.o is incompatible with elf32-powerpc ld.lld: error: arch/powerpc/kernel/vdso32/getcpu.o is incompatible with elf32-powerpc ld.lld: error: arch/powerpc/kernel/vdso32/vgettimeofday.o is incompatible with elf32-powerpc ... ``` This happens because the endian information is missing from the call to the assembler, even though it was explicitly passed to clang. See the below example. ``` $ echo | clang --target=powerpc64le-linux-gnu \ --prefix=/usr/bin/powerpc64le-linux-gnu- \ -no-integrated-as -m32 -mbig-endian -### -x c -c - ".../clang-12" "-cc1" "-triple" "powerpc-unknown-linux-gnu" ... ... "/usr/bin/powerpc64le-linux-gnu-as" "-a32" "-mppc" "-many" "-o" "-.o" "/tmp/--e69e28.s" ``` clang sets the right target with -m32 and -mbig-endian but -mbig-endian does not make it to the assembler, resulting in a 32-bit little endian binary. This differs from the little endian targets, which always pass -mlittle-endian. ``` $ echo | clang --target=powerpc64-linux-gnu \ --prefix=/usr/bin/powerpc64-linux-gnu- \ -no-integrated-as -m32 -mlittle-endian -### -x c -c - ".../clang-12" "-cc1" "-triple" "powerpcle-unknown-linux-gnu" ... ... "/usr/bin/powerpc64-linux-gnu-as" "-a32" "-mppc" "-mlittle-endian" "-many" "-o" "-.o" "/tmp/--405dbd.s" ``` Do the same thing for the big endian targets so that there is no more error. This matches GCC's behavior, where -mbig and -mlittle are always passed along to GNU as. ``` $ echo | powerpc64-linux-gcc -### -x c -c - ... .../powerpc64-linux/bin/as -a64 -mpower4 -many -mbig -o -.o /tmp/ccVn7NAm.s ... $ echo | powerpc64le-linux-gcc -### -x c -c - ... .../powerpc64le-linux/bin/as -a64 -mpower8 -many -mlittle -o -.o /tmp/ccPN9ato.s ... ``` Reviewed By: nickdesaulniers, MaskRay Differential Revision: https://reviews.llvm.org/D94442
1 parent 9ecc991 commit 0a23fbd

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
731731
case llvm::Triple::ppc: {
732732
CmdArgs.push_back("-a32");
733733
CmdArgs.push_back("-mppc");
734+
CmdArgs.push_back("-mbig-endian");
734735
CmdArgs.push_back(
735736
ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
736737
break;
@@ -746,6 +747,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
746747
case llvm::Triple::ppc64: {
747748
CmdArgs.push_back("-a64");
748749
CmdArgs.push_back("-mppc64");
750+
CmdArgs.push_back("-mbig-endian");
749751
CmdArgs.push_back(
750752
ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
751753
break;

clang/test/Driver/ppc-features.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,25 @@
156156
// CHECK-NOSPE: "-target-feature" "-spe"
157157

158158
// Assembler features
159-
// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o -no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_BE_AS_ARGS %s
160-
// CHECK_BE_AS_ARGS: "-mppc64"
161-
// CHECK_BE_AS_ARGS: "-many"
162-
163-
// RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o -no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_LE_AS_ARGS %s
164-
// CHECK_LE_AS_ARGS: "-mppc64"
165-
// CHECK_LE_AS_ARGS: "-mlittle-endian"
166-
// CHECK_LE_AS_ARGS: "-mpower8"
159+
// RUN: %clang -target powerpc-unknown-linux-gnu %s -### -o %t.o -no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_32_BE_AS_ARGS %s
160+
// CHECK_32_BE_AS_ARGS: "-mppc"
161+
// CHECK_32_BE_AS_ARGS-SAME: "-mbig-endian"
162+
// CHECK_32_BE_AS_ARGS-SAME: "-many"
163+
164+
// RUN: %clang -target powerpcle-unknown-linux-gnu %s -### -o %t.o -no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_32_LE_AS_ARGS %s
165+
// CHECK_32_LE_AS_ARGS: "-mppc"
166+
// CHECK_32_LE_AS_ARGS-SAME: "-mlittle-endian"
167+
// CHECK_32_LE_AS_ARGS-SAME: "-many"
168+
169+
// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o -no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_64_BE_AS_ARGS %s
170+
// CHECK_64_BE_AS_ARGS: "-mppc64"
171+
// CHECK_64_BE_AS_ARGS-SAME: "-mbig-endian"
172+
// CHECK_64_BE_AS_ARGS-SAME: "-many"
173+
174+
// RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o -no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_64_LE_AS_ARGS %s
175+
// CHECK_64_LE_AS_ARGS: "-mppc64"
176+
// CHECK_64_LE_AS_ARGS-SAME: "-mlittle-endian"
177+
// CHECK_64_LE_AS_ARGS-SAME: "-mpower8"
167178

168179
// OpenMP features
169180
// RUN: %clang -target powerpc-unknown-linux-gnu %s -### -fopenmp=libomp -o %t.o 2>&1 | FileCheck -check-prefix=CHECK_OPENMP_TLS %s

0 commit comments

Comments
 (0)