From f2ed95c1da5561b9d7fa4cc6930845ce59c2d475 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Sat, 7 Dec 2013 00:57:46 +0000 Subject: [PATCH] Pass correct flags to assembler and linker for OpenBSD on AMD64, PowerPC and MIPS64. From Brad Smith. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196630 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 39 +++++++++++++++++++++++++++++++++++++++ test/Driver/openbsd.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 10dd69a8b8..a14a41914d 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -5430,6 +5430,40 @@ void openbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, const char *LinkingOutput) const { ArgStringList CmdArgs; + // When building 32-bit code on OpenBSD/amd64, we have to explicitly + // instruct as in the base system to assemble 32-bit code. + if (getToolChain().getArch() == llvm::Triple::x86) + CmdArgs.push_back("--32"); + else if (getToolChain().getArch() == llvm::Triple::ppc) { + CmdArgs.push_back("-mppc"); + CmdArgs.push_back("-many"); + } else if (getToolChain().getArch() == llvm::Triple::mips64 || + getToolChain().getArch() == llvm::Triple::mips64el) { + StringRef CPUName; + StringRef ABIName; + getMipsCPUAndABI(Args, getToolChain().getTriple(), CPUName, ABIName); + + CmdArgs.push_back("-mabi"); + CmdArgs.push_back(getGnuCompatibleMipsABIName(ABIName).data()); + + if (getToolChain().getArch() == llvm::Triple::mips64) + CmdArgs.push_back("-EB"); + else + CmdArgs.push_back("-EL"); + + Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, + options::OPT_fpic, options::OPT_fno_pic, + options::OPT_fPIE, options::OPT_fno_PIE, + options::OPT_fpie, options::OPT_fno_pie); + if (LastPICArg && + (LastPICArg->getOption().matches(options::OPT_fPIC) || + LastPICArg->getOption().matches(options::OPT_fpic) || + LastPICArg->getOption().matches(options::OPT_fPIE) || + LastPICArg->getOption().matches(options::OPT_fpie))) { + CmdArgs.push_back("-KPIC"); + } + } + Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); @@ -5463,6 +5497,11 @@ void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, // handled somewhere else. Args.ClaimAllArgs(options::OPT_w); + if (getToolChain().getArch() == llvm::Triple::mips64) + CmdArgs.push_back("-EB"); + else if (getToolChain().getArch() == llvm::Triple::mips64el) + CmdArgs.push_back("-EL"); + if ((!Args.hasArg(options::OPT_nostdlib)) && (!Args.hasArg(options::OPT_shared))) { CmdArgs.push_back("-e"); diff --git a/test/Driver/openbsd.c b/test/Driver/openbsd.c index 4fd5b6a41b..ef02b07d29 100644 --- a/test/Driver/openbsd.c +++ b/test/Driver/openbsd.c @@ -17,6 +17,10 @@ // RUN: | FileCheck --check-prefix=CHECK-LD-T %s // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -Z %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-LD-Z %s +// RUN: %clang -no-canonical-prefixes -target mips64-unknown-openbsd %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s +// RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s // CHECK-LD-R: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-R: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-r" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // CHECK-LD-S: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" @@ -25,3 +29,27 @@ // CHECK-LD-T: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-t" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // CHECK-LD-Z: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-Z: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-Z" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" +// CHECK-MIPS64-LD: clang{{.*}}" "-cc1" "-triple" "mips64-unknown-openbsd" +// CHECK-MIPS64-LD: ld{{.*}}" "-EB" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" +// CHECK-MIPS64EL-LD: clang{{.*}}" "-cc1" "-triple" "mips64el-unknown-openbsd" +// CHECK-MIPS64EL-LD: ld{{.*}}" "-EL" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" + +// Check passing options to the assembler for various OpenBSD targets +// RUN: %clang -target amd64-pc-openbsd -m32 -### -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-AMD64-M32 %s +// RUN: %clang -target powerpc-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-POWERPC %s +// RUN: %clang -target mips64-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-MIPS64 %s +// RUN: %clang -target mips64-unknown-openbsd -fPIC -### -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-MIPS64-PIC %s +// RUN: %clang -target mips64el-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-MIPS64EL %s +// RUN: %clang -target mips64el-unknown-openbsd -fPIC -### -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-MIPS64EL-PIC %s +// CHECK-AMD64-M32: as{{.*}}" "--32" +// CHECK-POWERPC: as{{.*}}" "-mppc" "-many" +// CHECK-MIPS64: as{{.*}}" "-mabi" "64" "-EB" +// CHECK-MIPS64-PIC: as{{.*}}" "-mabi" "64" "-EB" "-KPIC" +// CHECK-MIPS64EL: as{{.*}}" "-mabi" "64" "-EL" +// CHECK-MIPS64EL-PIC: as{{.*}}" "-mabi" "64" "-EL" "-KPIC" -- 2.40.0