peter.smith created this revision. peter.smith added reviewers: rengolin, compnerd, olista01. Herald added subscribers: chrib, kristof.beyls, srhines. Herald added a reviewer: javed.absar.
The big-endian arm32 Linux builds are currently failing when the -mbig-endian and -fno-use-integrated-as flags are used and the assembler default is little endian. We are not registering that the clang -mbig-endian flag needs to be passed through to the assembler to override its default target. The patch always passes through -EL or -BE to the assembler, taking into account the target and the -mbig-endian and -mlittle-endian flag. Fixes pr38770 FIXME: While fixing this I note that giving the endianness in march does not override the endianness in the triple. This is not specific to -fno-integrated-as so if I write --target=arm-linux-gnueabihf -march=armebv7-a then the output is little endian. I've updated the targets in the test so that the target endian matches the march endianness. I think that this behaviour is wrong for a couple of reasons: - -march=armebv7-a should either give an error message if it disagrees with the triple or should override the triple. - The GNU assembler doesn't understand eb in march so we should ideally not pass it through, or rely on people to not use march that way. This can be fixed but I've not done so in this patch. https://reviews.llvm.org/D52784 Files: lib/Driver/ToolChains/Gnu.cpp test/Driver/linux-as.c
Index: test/Driver/linux-as.c =================================================================== --- test/Driver/linux-as.c +++ test/Driver/linux-as.c @@ -3,129 +3,140 @@ // RUN: %clang -target arm-linux -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM %s -// CHECK-ARM: as{{(.exe)?}}" "-mfloat-abi=soft" +// CHECK-ARM: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" // // RUN: %clang -target arm-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-MCPU %s -// CHECK-ARM-MCPU: as{{(.exe)?}}" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-ARM-MCPU: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target arm-linux -mfpu=neon -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-MFPU %s -// CHECK-ARM-MFPU: as{{(.exe)?}}" "-mfloat-abi=soft" "-mfpu=neon" +// CHECK-ARM-MFPU: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" "-mfpu=neon" // // RUN: %clang -target arm-linux -march=armv7-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-MARCH %s -// CHECK-ARM-MARCH: as{{(.exe)?}}" "-mfloat-abi=soft" "-march=armv7-a" +// CHECK-ARM-MARCH: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" "-march=armv7-a" +// +// RUN: %clang -target armeb-linux -mlittle-endian -mcpu=cortex-a8 -mfpu=neon -march=armv7-a -### \ +// RUN: -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ARM-ALL %s +// CHECK-ARM-ALL: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" "-march=armv7-a" "-mcpu=cortex-a8" "-mfpu=neon" // // RUN: %clang -target arm-linux -mcpu=cortex-a8 -mfpu=neon -march=armv7-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-ALL %s -// CHECK-ARM-ALL: as{{(.exe)?}}" "-mfloat-abi=soft" "-march=armv7-a" "-mcpu=cortex-a8" "-mfpu=neon" // -// RUN: %clang -target arm-linux -mcpu=cortex-a8 -mfpu=neon -march=armebv7-a -### \ +// RUN: %clang -target armeb-linux -mcpu=cortex-a8 -mfpu=neon -march=armebv7-a -### \ +// RUN: -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ARMEB-ALL %s +// CHECK-ARMEB-ALL: as{{(.exe)?}}" "-EB" "-mfloat-abi=soft" "-march=armebv7-a" "-mcpu=cortex-a8" "-mfpu=neon" +// +// RUN: %clang -target arm-linux -mcpu=cortex-a8 -mfpu=neon -march=armebv7-a -mbig-endian -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARMEB-ALL %s -// CHECK-ARMEB-ALL: as{{(.exe)?}}" "-mfloat-abi=soft" "-march=armebv7-a" "-mcpu=cortex-a8" "-mfpu=neon" // // RUN: %clang -target thumb-linux -mcpu=cortex-a8 -mfpu=neon -march=thumbv7-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMB-ALL %s -// CHECK-THUMB-ALL: as{{(.exe)?}}" "-mfloat-abi=soft" "-march=thumbv7-a" "-mcpu=cortex-a8" "-mfpu=neon" +// CHECK-THUMB-ALL: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" "-march=thumbv7-a" "-mcpu=cortex-a8" "-mfpu=neon" // -// RUN: %clang -target thumb-linux -mcpu=cortex-a8 -mfpu=neon -march=thumbebv7-a -### \ +// RUN: %clang -target thumbeb-linux -mcpu=cortex-a8 -mfpu=neon -march=thumbebv7-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMBEB-ALL %s -// CHECK-THUMBEB-ALL: as{{(.exe)?}}" "-mfloat-abi=soft" "-march=thumbebv7-a" "-mcpu=cortex-a8" "-mfpu=neon" +// CHECK-THUMBEB-ALL: as{{(.exe)?}}" "-EB" "-mfloat-abi=soft" "-march=thumbebv7-a" "-mcpu=cortex-a8" "-mfpu=neon" // // RUN: %clang -target armv7-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-TARGET %s -// CHECK-ARM-TARGET: as{{(.exe)?}}" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-ARM-TARGET: as{{(.exe)?}}" "-EL" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target armebv7-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARMEB-TARGET %s -// CHECK-ARMEB-TARGET: as{{(.exe)?}}" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-ARMEB-TARGET: as{{(.exe)?}}" "-EB" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target thumbv7-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMB-TARGET %s -// CHECK-THUMB-TARGET: as{{(.exe)?}}" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-THUMB-TARGET: as{{(.exe)?}}" "-EL" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target thumbebv7-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMBEB-TARGET %s -// CHECK-THUMBEB-TARGET: as{{(.exe)?}}" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-THUMBEB-TARGET: as{{(.exe)?}}" "-EB" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target armv8-linux -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-TARGET-V8 %s -// CHECK-ARM-TARGET-V8: as{{(.exe)?}}" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" +// CHECK-ARM-TARGET-V8: as{{(.exe)?}}" "-EL" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" // // RUN: %clang -target armebv8-linux -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARMEB-TARGET-V8 %s -// CHECK-ARMEB-TARGET-V8: as{{(.exe)?}}" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" +// CHECK-ARMEB-TARGET-V8: as{{(.exe)?}}" "-EB" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" // // RUN: %clang -target thumbv8-linux -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMB-TARGET-V8 %s -// CHECK-THUMB-TARGET-V8: as{{(.exe)?}}" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" +// CHECK-THUMB-TARGET-V8: as{{(.exe)?}}" "-EL" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" // // RUN: %clang -target thumbebv8-linux -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMBEB-TARGET-V8 %s -// CHECK-THUMBEB-TARGET-V8: as{{(.exe)?}}" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" +// CHECK-THUMBEB-TARGET-V8: as{{(.exe)?}}" "-EB" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" // // RUN: %clang -target arm-linux -mfloat-abi=hard -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-MFLOAT-ABI %s -// CHECK-ARM-MFLOAT-ABI: as{{(.exe)?}}" "-mfloat-abi=hard" +// CHECK-ARM-MFLOAT-ABI: as{{(.exe)?}}" "-EL" "-mfloat-abi=hard" // // RUN: %clang -target arm-linux-androideabi -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-ANDROID %s -// CHECK-ARM-ANDROID: as{{(.exe)?}}" "-mfloat-abi=soft" +// CHECK-ARM-ANDROID: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" // // RUN: %clang -target arm-linux-androideabi -march=armv7-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-ANDROID-SOFTFP %s -// CHECK-ARM-ANDROID-SOFTFP: as{{(.exe)?}}" "-mfloat-abi=softfp" "-march=armv7-a" +// CHECK-ARM-ANDROID-SOFTFP: as{{(.exe)?}}" "-EL" "-mfloat-abi=softfp" "-march=armv7-a" // // RUN: %clang -target arm-linux-eabi -mhard-float -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-HARDFP %s -// CHECK-ARM-HARDFP: as{{(.exe)?}}" "-mfloat-abi=hard" +// CHECK-ARM-HARDFP: as{{(.exe)?}}" "-EL" "-mfloat-abi=hard" // // RUN: %clang -target aarch64-linux-gnu -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM64-MCPU %s -// CHECK-ARM64-MCPU: as{{(.exe)?}}" "-mcpu=cortex-a53" +// CHECK-ARM64-MCPU: as{{(.exe)?}}" "-EL" "-mcpu=cortex-a53" // // RUN: %clang -target aarch64-linux-gnu -march=armv8-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM64-MARCH %s -// CHECK-ARM64-MARCH: as{{(.exe)?}}" "-march=armv8-a" +// CHECK-ARM64-MARCH: as{{(.exe)?}}" "-EL" "-march=armv8-a" // // RUN: %clang -target aarch64-linux-gnu -mcpu=cortex-a53 -march=armv8-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM64-ALL %s -// CHECK-ARM64-ALL: as{{(.exe)?}}" "-march=armv8-a" "-mcpu=cortex-a53" +// CHECK-ARM64-ALL: as{{(.exe)?}}" "-EL" "-march=armv8-a" "-mcpu=cortex-a53" // // RUN: %clang -target aarch64_be-linux-gnu -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-ARM64-MCPU %s +// RUN: | FileCheck -check-prefix=CHECK-ARM64BE-MCPU %s +// CHECK-ARM64BE-MCPU: as{{(.exe)?}}" "-EB" "-mcpu=cortex-a53" // // RUN: %clang -target aarch64_be-linux-gnu -march=armv8-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-ARM64-MARCH %s +// RUN: | FileCheck -check-prefix=CHECK-ARM64BE-MARCH %s +// CHECK-ARM64BE-MARCH: as{{(.exe)?}}" "-EB" "-march=armv8-a" // // RUN: %clang -target aarch64_be-linux-gnu -mcpu=cortex-a53 -march=armv8-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-ARM64-ALL %s +// RUN: | FileCheck -check-prefix=CHECK-ARM64BE-ALL %s +// CHECK-ARM64BE-ALL: as{{(.exe)?}}" "-EB" "-march=armv8-a" "-mcpu=cortex-a53" // // RUN: %clang -target ppc-linux -mcpu=invalid-cpu -### \ // RUN: -no-integrated-as -c %s 2>&1 \ Index: lib/Driver/ToolChains/Gnu.cpp =================================================================== --- lib/Driver/ToolChains/Gnu.cpp +++ lib/Driver/ToolChains/Gnu.cpp @@ -535,6 +535,19 @@ C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); } + +// On Arm and AArch64 the endianness of the output file is determined by +// the target and can be overridden by the pseudo-target flags +// '-mlittle-endian'/'-EL' and '-mbig-endian'/'-EB'. Return the assembler +// flag we need to ensure the correct endianness of the assembler output. +static const char* GetEndianArg(bool IsBigEndian, const ArgList &Args) { + if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian, + options::OPT_mbig_endian)) { + IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian); + } + return (IsBigEndian) ? "-EB" : "-EL"; +} + void tools::gnutools::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, @@ -638,6 +651,9 @@ case llvm::Triple::thumb: case llvm::Triple::thumbeb: { const llvm::Triple &Triple2 = getToolChain().getTriple(); + bool IsBigEndian = Triple2.getArch() == llvm::Triple::armeb || + Triple2.getArch() == llvm::Triple::thumbeb; + CmdArgs.push_back(GetEndianArg(IsBigEndian, Args)); switch (Triple2.getSubArch()) { case llvm::Triple::ARMSubArch_v7: CmdArgs.push_back("-mfpu=neon"); @@ -670,6 +686,9 @@ } case llvm::Triple::aarch64: case llvm::Triple::aarch64_be: { + bool IsBigEndian = + getToolChain().getTriple().getArch() == llvm::Triple::aarch64_be; + CmdArgs.push_back(GetEndianArg(IsBigEndian, Args)); Args.AddLastArg(CmdArgs, options::OPT_march_EQ); normalizeCPUNamesForAssembler(Args, CmdArgs);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits