[lld] [llvm] [MC] set OpenBSD's ELFOSABI by default (#98158) (PR #98553)

John Ericson via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 14:14:18 PDT 2024


https://github.com/Ericson2314 created https://github.com/llvm/llvm-project/pull/98553

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 06cecdc60ec9ebfdd4d8cdb2586d201272bdf6bd.

Take two of #98158 / b64c1de714c50bec7493530446ebf5e540d5f96a, preexisting test is fixed now.

>From beda91bfb7efca31805736e272cece11445bfc82 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson at Obsidian.Systems>
Date: Thu, 11 Jul 2024 09:10:24 -0400
Subject: [PATCH] [MC] set OpenBSD's ELFOSABI by default (#98158)

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 06cecdc60ec9ebfdd4d8cdb2586d201272bdf6bd.

(cherry picked from commit b64c1de714c50bec7493530446ebf5e540d5f96a)
---
 lld/test/ELF/basic-sparcv9.s             | 2 +-
 llvm/include/llvm/MC/MCELFObjectWriter.h | 2 ++
 llvm/test/MC/ELF/osabi.s                 | 4 ++++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lld/test/ELF/basic-sparcv9.s b/lld/test/ELF/basic-sparcv9.s
index af63dc47ae84e..b2f760f21ab05 100644
--- a/lld/test/ELF/basic-sparcv9.s
+++ b/lld/test/ELF/basic-sparcv9.s
@@ -17,7 +17,7 @@ _start:
 # CHECK-NEXT:     Class: 64-bit (0x2)
 # CHECK-NEXT:     DataEncoding: BigEndian (0x2)
 # CHECK-NEXT:     FileVersion: 1
-# CHECK-NEXT:     OS/ABI: SystemV (0x0)
+# CHECK-NEXT:     OS/ABI: OpenBSD (0x0)
 # CHECK-NEXT:     ABIVersion: 0
 # CHECK-NEXT:     Unused: (00 00 00 00 00 00 00)
 # CHECK-NEXT:   }
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.s b/llvm/test/MC/ELF/osabi.s
index dc6ad2a349d75..44912f4987c11 100644
--- a/llvm/test/MC/ELF/osabi.s
+++ b/llvm/test/MC/ELF/osabi.s
@@ -10,3 +10,7 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s | llvm-readobj -h - | \
 # RUN:   FileCheck %s --check-prefix=FREEBSD
 # FREEBSD: OS/ABI: FreeBSD
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-openbsd %s | llvm-readobj -h - | \
+# RUN:   FileCheck %s --check-prefix=OPENBSD
+# OPENBSD: OS/ABI: OpenBSD



More information about the llvm-commits mailing list