[PATCH] D128127: [Driver][OpenBSD] Specify linker emulations

Brad Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 18 15:40:38 PDT 2022


brad created this revision.
brad added a reviewer: MaskRay.
brad added a project: clang.
Herald added subscribers: luke957, StephenFan, s.egerton, simoncook, fedor.sergeev.
Herald added a project: All.
brad requested review of this revision.
Herald added a subscriber: pcwang-thead.

Have the driver specify the linker emulations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128127

Files:
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/test/Driver/openbsd.c


Index: clang/test/Driver/openbsd.c
===================================================================
--- clang/test/Driver/openbsd.c
+++ clang/test/Driver/openbsd.c
@@ -56,6 +56,38 @@
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SYSROOT %s
 // CHECK-LD-SYSROOT: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
 
+// Check the ld emulation type passed to the linker
+// RUN: %clang -no-canonical-prefixes -target aarch64-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-AARCH64 %s
+// RUN: %clang -no-canonical-prefixes -target arm-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-ARM %s
+// RUN: %clang -no-canonical-prefixes -target mips64-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-MIPS64 %s
+// RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-MIPS64EL %s
+// RUN: %clang -no-canonical-prefixes -target powerpc-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-POWERPC %s
+// RUN: %clang -no-canonical-prefixes -target powerpc64-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-POWERPC64 %s
+// RUN: %clang -no-canonical-prefixes -target riscv64-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-RISCV64 %s
+// RUN: %clang -no-canonical-prefixes -target sparc64-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-SPARC64 %s
+// RUN: %clang -no-canonical-prefixes -target i386-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-i386 %s
+// RUN: %clang -no-canonical-prefixes -target amd64-unknown-openbsd %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-M-AMD64 %s
+// CHECK-LD-M-AARCH64: "-m" "aarch64elf"
+// CHECK-LD-M-ARM: "-m" "armelf"
+// CHECK-LD-M-MIPS64: "-m" "elf64btsmip"
+// CHECK-LD-M-MIPS64EL: "-m" "elf64ltsmip"
+// CHECK-LD-M-POWERPC: "-m" "elf32ppc"
+// CHECK-LD-M-POWERPC64: "-m" "elf64ppc"
+// CHECK-LD-M-RISCV64: "-m" "elf64lriscv"
+// CHECK-LD-M-SPARC64: "-m" "elf64_sparc"
+// CHECK-LD-M-i386: "-m" "elf_i386"
+// CHECK-LD-M-AMD64: "-m" "elf_x86_64"
+
 // 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
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===================================================================
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -157,6 +157,52 @@
   if (Args.hasArg(options::OPT_nopie) || Args.hasArg(options::OPT_pg))
     CmdArgs.push_back("-nopie");
 
+  // Determine the correct emulation for ld.
+  switch (Arch) {
+  case llvm::Triple::aarch64:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("aarch64elf");
+    break;
+  case llvm::Triple::arm:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("armelf");
+    break;
+  case llvm::Triple::mips64:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf64btsmip");
+    break;
+  case llvm::Triple::mips64el:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf64ltsmip");
+    break;
+  case llvm::Triple::ppc:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf32ppc");
+    break;
+  case llvm::Triple::ppc64:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf64ppc");
+    break;
+  case llvm::Triple::riscv64:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf64lriscv");
+    break;
+  case llvm::Triple::sparcv9:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf64_sparc");
+    break;
+  case llvm::Triple::x86:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf_i386");
+    break;
+  case llvm::Triple::x86_64:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf_x86_64");
+    break;
+  default:
+    break;
+  }
+
   if (Arch == llvm::Triple::riscv64)
     CmdArgs.push_back("-X");
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128127.438158.patch
Type: text/x-patch
Size: 4013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220618/433bf6b8/attachment-0001.bin>


More information about the cfe-commits mailing list