[llvm] [LLVM] set OpenBSD's ELFOSABI by default (PR #98158)

John Ericson via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 07:01:48 PDT 2024


https://github.com/Ericson2314 updated https://github.com/llvm/llvm-project/pull/98158

>From 9da46ac6e78ee5557ec05c38c3bf69bd846118f8 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson at Obsidian.Systems>
Date: Sun, 30 Jun 2024 18:47:58 -0400
Subject: [PATCH] [LLMV] set OpenBSD's ELFOSABI by default

This matches what is done for FreeBSD.

OpenBSD has a few special program header types, and other such ELF
extensions. Setting the ELFOSABI like so will allow LLD to support them
without needlessly impacting non-OpenBSD ELFs.

Testing strategy matches 8738c5b0fe0a92a153d7c678f7b51cac05f48b35 /
D107748. Added one for FreeBSD too for good measure.
---
 llvm/include/llvm/MC/MCELFObjectWriter.h | 2 ++
 llvm/test/MC/ELF/osabi-freebsd.s         | 2 ++
 llvm/test/MC/ELF/osabi-openbsd.s         | 2 ++
 3 files changed, 6 insertions(+)
 create mode 100644 llvm/test/MC/ELF/osabi-freebsd.s
 create mode 100644 llvm/test/MC/ELF/osabi-openbsd.s

diff --git a/llvm/include/llvm/MC/MCELFObjectWriter.h b/llvm/include/llvm/MC/MCELFObjectWriter.h
index d7c223cdcc07f..12237094ad86a 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -78,6 +78,8 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
         return ELF::ELFOSABI_FREEBSD;
       case Triple::Solaris:
         return ELF::ELFOSABI_SOLARIS;
+      case Triple::OpenBSD:
+        return ELF::ELFOSABI_OPENBSD;
       default:
         return ELF::ELFOSABI_NONE;
     }
diff --git a/llvm/test/MC/ELF/osabi-freebsd.s b/llvm/test/MC/ELF/osabi-freebsd.s
new file mode 100644
index 0000000000000..0dbef293772e9
--- /dev/null
+++ b/llvm/test/MC/ELF/osabi-freebsd.s
@@ -0,0 +1,2 @@
+# RUN: llvm-mc -filetype obj -triple amd64-freebsd %s | llvm-readobj -hS - | FileCheck %s
+# CHECK: OS/ABI: FreeBSD
diff --git a/llvm/test/MC/ELF/osabi-openbsd.s b/llvm/test/MC/ELF/osabi-openbsd.s
new file mode 100644
index 0000000000000..f501dfa7bb126
--- /dev/null
+++ b/llvm/test/MC/ELF/osabi-openbsd.s
@@ -0,0 +1,2 @@
+# RUN: llvm-mc -filetype obj -triple amd64-openbsd %s | llvm-readobj -hS - | FileCheck %s
+# CHECK: OS/ABI: OpenBSD



More information about the llvm-commits mailing list