diff options
author | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2014-07-28 13:17:52 +0000 |
---|---|---|
committer | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2014-07-28 13:17:52 +0000 |
commit | 8afad61a9336e8f212ec551a38a1e30411d82ff4 (patch) | |
tree | d184c0038b59dfd9a14bd8cf1a6da0a5b6a9bd3a /clang/test | |
parent | 085a10c49e35f3c61234fee53ce7e69abc662441 (diff) | |
download | bcm5719-llvm-8afad61a9336e8f212ec551a38a1e30411d82ff4.tar.gz bcm5719-llvm-8afad61a9336e8f212ec551a38a1e30411d82ff4.zip |
[PowerPC] Support ELFv1/ELFv2 ABI selection via -mabi= option
While Clang now supports both ELFv1 and ELFv2 ABIs, their use is currently
hard-coded via the target triple: powerpc64-linux is always ELFv1, while
powerpc64le-linux is always ELFv2.
These are of course the most common scenarios, but in principle it is
possible to support the ELFv2 ABI on big-endian or the ELFv1 ABI on
little-endian systems (and GCC does support that), and there are some
special use cases for that (e.g. certain Linux kernel versions could
only be built using ELFv1 on LE).
This patch implements the Clang side of supporting this, based on the
LLVM commit 214072. The command line options -mabi=elfv1 or -mabi=elfv2
select the desired ABI if present. (If not, Clang uses the same default
rules as now.)
Specifically, the patch implements the following changes based on the
presence of the -mabi= option:
In the driver:
- Pass the appropiate -target-abi flag to the back-end
- Select the correct dynamic loader version (/lib64/ld64.so.[12])
In the preprocessor:
- Define _CALL_ELF to the appropriate value (1 or 2)
In the compiler back-end:
- Select the correct ABI in TargetInfo.cpp
- Select the desired ABI for LLVM via feature (elfv1/elfv2)
llvm-svn: 214074
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGen/ppc64-elf-abi.c | 40 | ||||
-rw-r--r-- | clang/test/Driver/linux-ld.c | 35 | ||||
-rw-r--r-- | clang/test/Driver/ppc-abi.c | 19 | ||||
-rw-r--r-- | clang/test/Preprocessor/init.c | 9 |
4 files changed, 103 insertions, 0 deletions
diff --git a/clang/test/CodeGen/ppc64-elf-abi.c b/clang/test/CodeGen/ppc64-elf-abi.c new file mode 100644 index 00000000000..0dd183e2a6d --- /dev/null +++ b/clang/test/CodeGen/ppc64-elf-abi.c @@ -0,0 +1,40 @@ +// REQUIRES: powerpc-registered-target + +// Verify ABI selection by the front end + +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -emit-llvm -o - %s \ +// RUN: | FileCheck %s --check-prefix=CHECK-ELFv1 +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -emit-llvm -o - %s \ +// RUN: -target-abi elfv1 | FileCheck %s --check-prefix=CHECK-ELFv1 +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -emit-llvm -o - %s \ +// RUN: -target-abi elfv2 | FileCheck %s --check-prefix=CHECK-ELFv2 +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s \ +// RUN: | FileCheck %s --check-prefix=CHECK-ELFv2 +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s \ +// RUN: -target-abi elfv1 | FileCheck %s --check-prefix=CHECK-ELFv1 +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s \ +// RUN: -target-abi elfv2 | FileCheck %s --check-prefix=CHECK-ELFv2 + +// CHECK-ELFv1: define void @func_fab(%struct.fab* noalias sret %agg.result, i64 %x.coerce) +// CHECK-ELFv2: define [2 x float] @func_fab([2 x float] %x.coerce) +struct fab { float a; float b; }; +struct fab func_fab(struct fab x) { return x; } + +// Verify ABI choice is passed on to the back end + +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -S -o - %s \ +// RUN: | FileCheck %s --check-prefix=CHECK-ASM-ELFv1 +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -S -o - %s \ +// RUN: -target-abi elfv1 | FileCheck %s --check-prefix=CHECK-ASM-ELFv1 +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -S -o - %s \ +// RUN: -target-abi elfv2 | FileCheck %s --check-prefix=CHECK-ASM-ELFv2 +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -S -o - %s \ +// RUN: | FileCheck %s --check-prefix=CHECK-ASM-ELFv2 +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -S -o - %s \ +// RUN: -target-abi elfv1 | FileCheck %s --check-prefix=CHECK-ASM-ELFv1 +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -S -o - %s \ +// RUN: -target-abi elfv2 | FileCheck %s --check-prefix=CHECK-ASM-ELFv2 + +// CHECK-ASM-ELFv2: .abiversion 2 +// CHECK-ASM-ELFv1-NOT: .abiversion 2 + diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index 6a47d08274d..dbdaaa1e1c4 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -524,12 +524,47 @@ // CHECK-ARM-HF: "-dynamic-linker" "{{.*}}/lib/ld-linux-armhf.so.3" // // RUN: %clang %s -### -o %t.o 2>&1 \ +// RUN: --target=powerpc64-linux-gnu \ +// RUN: | FileCheck --check-prefix=CHECK-PPC64 %s +// CHECK-PPC64: "{{.*}}ld{{(.exe)?}}" +// CHECK-PPC64: "-m" "elf64ppc" +// CHECK-PPC64: "-dynamic-linker" "{{.*}}/lib64/ld64.so.1" +// +// RUN: %clang %s -### -o %t.o 2>&1 \ +// RUN: --target=powerpc64-linux-gnu -mabi=elfv1 \ +// RUN: | FileCheck --check-prefix=CHECK-PPC64-ELFv1 %s +// CHECK-PPC64-ELFv1: "{{.*}}ld{{(.exe)?}}" +// CHECK-PPC64-ELFv1: "-m" "elf64ppc" +// CHECK-PPC64-ELFv1: "-dynamic-linker" "{{.*}}/lib64/ld64.so.1" +// +// RUN: %clang %s -### -o %t.o 2>&1 \ +// RUN: --target=powerpc64-linux-gnu -mabi=elfv2 \ +// RUN: | FileCheck --check-prefix=CHECK-PPC64-ELFv2 %s +// CHECK-PPC64-ELFv2: "{{.*}}ld{{(.exe)?}}" +// CHECK-PPC64-ELFv2: "-m" "elf64ppc" +// CHECK-PPC64-ELFv2: "-dynamic-linker" "{{.*}}/lib64/ld64.so.2" +// +// RUN: %clang %s -### -o %t.o 2>&1 \ // RUN: --target=powerpc64le-linux-gnu \ // RUN: | FileCheck --check-prefix=CHECK-PPC64LE %s // CHECK-PPC64LE: "{{.*}}ld{{(.exe)?}}" // CHECK-PPC64LE: "-m" "elf64lppc" // CHECK-PPC64LE: "-dynamic-linker" "{{.*}}/lib64/ld64.so.2" // +// RUN: %clang %s -### -o %t.o 2>&1 \ +// RUN: --target=powerpc64le-linux-gnu -mabi=elfv1 \ +// RUN: | FileCheck --check-prefix=CHECK-PPC64LE-ELFv1 %s +// CHECK-PPC64LE-ELFv1: "{{.*}}ld{{(.exe)?}}" +// CHECK-PPC64LE-ELFv1: "-m" "elf64lppc" +// CHECK-PPC64LE-ELFv1: "-dynamic-linker" "{{.*}}/lib64/ld64.so.1" +// +// RUN: %clang %s -### -o %t.o 2>&1 \ +// RUN: --target=powerpc64le-linux-gnu -mabi=elfv2 \ +// RUN: | FileCheck --check-prefix=CHECK-PPC64LE-ELFv2 %s +// CHECK-PPC64LE-ELFv2: "{{.*}}ld{{(.exe)?}}" +// CHECK-PPC64LE-ELFv2: "-m" "elf64lppc" +// CHECK-PPC64LE-ELFv2: "-dynamic-linker" "{{.*}}/lib64/ld64.so.2" +// // Check that we do not pass --hash-style=gnu and --hash-style=both to linker // and provide correct path to the dynamic linker and emulation mode when build // for MIPS platforms. diff --git a/clang/test/Driver/ppc-abi.c b/clang/test/Driver/ppc-abi.c new file mode 100644 index 00000000000..6fee63a303c --- /dev/null +++ b/clang/test/Driver/ppc-abi.c @@ -0,0 +1,19 @@ +// Check passing PowerPC ABI options to the backend. + +// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ELFv1 %s +// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ +// RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1 %s +// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ +// RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s + +// RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ELFv2 %s +// RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ +// RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1 %s +// RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ +// RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s + +// CHECK-ELFv1: "-target-abi" "elfv1" +// CHECK-ELFv2: "-target-abi" "elfv2" + diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 48f586a7de3..3342225ddc9 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -4916,6 +4916,15 @@ // PPC64-LINUX:#define __powerpc__ 1 // PPC64-LINUX:#define __ppc64__ 1 // PPC64-LINUX:#define __ppc__ 1 + +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu < /dev/null | FileCheck -check-prefix PPC64-ELFv1 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu -target-abi elfv1 < /dev/null | FileCheck -check-prefix PPC64-ELFv1 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu -target-abi elfv2 < /dev/null | FileCheck -check-prefix PPC64-ELFv2 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-unknown-linux-gnu < /dev/null | FileCheck -check-prefix PPC64-ELFv2 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < /dev/null | FileCheck -check-prefix PPC64-ELFv1 %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < /dev/null | FileCheck -check-prefix PPC64-ELFv2 %s +// PPC64-ELFv1:#define _CALL_ELF 1 +// PPC64-ELFv2:#define _CALL_ELF 2 // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-none-none -fno-signed-char < /dev/null | FileCheck -check-prefix PPC %s // |