Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jul 11, 2024

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

Take two of #98158 / b64c1de, which was reverted in #98494 / c026135. preexisting test is fixed now.

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

(cherry picked from commit b64c1de)
@llvmbot llvmbot added lld mc Machine (object) code lld:ELF labels Jul 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2024

@llvm/pr-subscribers-lld-elf
@llvm/pr-subscribers-lld

@llvm/pr-subscribers-mc

Author: John Ericson (Ericson2314)

Changes

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

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


Full diff: https://github.com/llvm/llvm-project/pull/98553.diff

3 Files Affected:

  • (modified) lld/test/ELF/basic-sparcv9.s (+1-1)
  • (modified) llvm/include/llvm/MC/MCELFObjectWriter.h (+2)
  • (modified) llvm/test/MC/ELF/osabi.s (+4)
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

@Ericson2314
Copy link
Member Author

I did a basic grep for SystemV and openbsd to make sure there weren't any more such downstream tests.

@Ericson2314 Ericson2314 merged commit 6bc6f6b into llvm:main Jul 11, 2024
8 of 10 checks passed
@Ericson2314 Ericson2314 deleted the mc-elfosabi-openbsd branch July 11, 2024 21:22
Ericson2314 added a commit that referenced this pull request Jul 11, 2024
Ericson2314 added a commit to obsidiansystems/llvm-project that referenced this pull request Jul 11, 2024
Ericson2314 added a commit that referenced this pull request Jul 11, 2024
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 12, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-expensive-checks-debian running on gribozavr4 while building lld,llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/1592

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'lld :: ELF/basic-sparcv9.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-mc -filetype=obj -triple=sparc64-unknown-openbsd /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/ELF/basic-sparcv9.s -o /b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-mc -filetype=obj -triple=sparc64-unknown-openbsd /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/ELF/basic-sparcv9.s -o /b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp
RUN: at line 3: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/ld.lld /b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp -o /b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/ld.lld /b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp -o /b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
RUN: at line 4: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-readobj --file-headers --sections -l --symbols /b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2    | /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/ELF/basic-sparcv9.s
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-readobj --file-headers --sections -l --symbols /b/1/llvm-clang-x86_64-expensive-checks-debian/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/ELF/basic-sparcv9.s
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/ELF/basic-sparcv9.s:20:15: error: CHECK-NEXT: expected string not found in input
# CHECK-NEXT: OS/ABI: OpenBSD (0x0)
              ^
<stdin>:12:16: note: scanning from here
 FileVersion: 1
               ^
<stdin>:13:2: note: possible intended match here
 OS/ABI: OpenBSD (0xC)
 ^

Input file: <stdin>
Check file: /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/lld/test/ELF/basic-sparcv9.s

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           .
           .
           .
           7: ElfHeader { 
           8:  Ident { 
           9:  Magic: (7F 45 4C 46) 
          10:  Class: 64-bit (0x2) 
          11:  DataEncoding: BigEndian (0x2) 
          12:  FileVersion: 1 
next:20'0                    X error: no match found
          13:  OS/ABI: OpenBSD (0xC) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~
next:20'1      ?                      possible intended match
          14:  ABIVersion: 0 
next:20'0     ~~~~~~~~~~~~~~~
          15:  Unused: (00 00 00 00 00 00 00) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          16:  } 
next:20'0     ~~~
          17:  Type: Executable (0x2) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~
...

@Ericson2314
Copy link
Member Author

Ericson2314 commented Jul 12, 2024

That issue is non spurious, but I fixed it immediately after in #98555

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 12, 2024

LLVM Buildbot has detected a new failure on builder lld-x86_64-ubuntu-fast running on as-builder-4 while building lld,llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/33/builds/545

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'lld :: ELF/basic-sparcv9.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/llvm-mc -filetype=obj -triple=sparc64-unknown-openbsd /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/ELF/basic-sparcv9.s -o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/llvm-mc -filetype=obj -triple=sparc64-unknown-openbsd /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/ELF/basic-sparcv9.s -o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp
RUN: at line 3: /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/ld.lld /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp -o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/ld.lld /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp -o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
RUN: at line 4: /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/llvm-readobj --file-headers --sections -l --symbols /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2    | /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/ELF/basic-sparcv9.s
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/llvm-readobj --file-headers --sections -l --symbols /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/ELF/basic-sparcv9.s
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/ELF/basic-sparcv9.s:20:15: error: CHECK-NEXT: expected string not found in input
# CHECK-NEXT: OS/ABI: OpenBSD (0x0)
              ^
<stdin>:12:16: note: scanning from here
 FileVersion: 1
               ^
<stdin>:13:2: note: possible intended match here
 OS/ABI: OpenBSD (0xC)
 ^

Input file: <stdin>
Check file: /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/ELF/basic-sparcv9.s

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           .
           .
           .
           7: ElfHeader { 
           8:  Ident { 
           9:  Magic: (7F 45 4C 46) 
          10:  Class: 64-bit (0x2) 
          11:  DataEncoding: BigEndian (0x2) 
          12:  FileVersion: 1 
next:20'0                    X error: no match found
          13:  OS/ABI: OpenBSD (0xC) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~
next:20'1      ?                      possible intended match
          14:  ABIVersion: 0 
next:20'0     ~~~~~~~~~~~~~~~
          15:  Unused: (00 00 00 00 00 00 00) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          16:  } 
next:20'0     ~~~
          17:  Type: Executable (0x2) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 12, 2024

LLVM Buildbot has detected a new failure on builder llvm-x86_64-debian-dylib running on gribozavr4 while building lld,llvm at step 8 "test-build-unified-tree-check-lld".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/2269

Here is the relevant piece of the build log for the reference:

Step 8 (test-build-unified-tree-check-lld) failure: test (failure)
******************** TEST 'lld :: ELF/basic-sparcv9.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /b/1/llvm-x86_64-debian-dylib/build/bin/llvm-mc -filetype=obj -triple=sparc64-unknown-openbsd /b/1/llvm-x86_64-debian-dylib/llvm-project/lld/test/ELF/basic-sparcv9.s -o /b/1/llvm-x86_64-debian-dylib/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp
+ /b/1/llvm-x86_64-debian-dylib/build/bin/llvm-mc -filetype=obj -triple=sparc64-unknown-openbsd /b/1/llvm-x86_64-debian-dylib/llvm-project/lld/test/ELF/basic-sparcv9.s -o /b/1/llvm-x86_64-debian-dylib/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp
RUN: at line 3: /b/1/llvm-x86_64-debian-dylib/build/bin/ld.lld /b/1/llvm-x86_64-debian-dylib/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp -o /b/1/llvm-x86_64-debian-dylib/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
+ /b/1/llvm-x86_64-debian-dylib/build/bin/ld.lld /b/1/llvm-x86_64-debian-dylib/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp -o /b/1/llvm-x86_64-debian-dylib/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
RUN: at line 4: /b/1/llvm-x86_64-debian-dylib/build/bin/llvm-readobj --file-headers --sections -l --symbols /b/1/llvm-x86_64-debian-dylib/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2    | /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck /b/1/llvm-x86_64-debian-dylib/llvm-project/lld/test/ELF/basic-sparcv9.s
+ /b/1/llvm-x86_64-debian-dylib/build/bin/llvm-readobj --file-headers --sections -l --symbols /b/1/llvm-x86_64-debian-dylib/build/tools/lld/test/ELF/Output/basic-sparcv9.s.tmp2
+ /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck /b/1/llvm-x86_64-debian-dylib/llvm-project/lld/test/ELF/basic-sparcv9.s
/b/1/llvm-x86_64-debian-dylib/llvm-project/lld/test/ELF/basic-sparcv9.s:20:15: error: CHECK-NEXT: expected string not found in input
# CHECK-NEXT: OS/ABI: OpenBSD (0x0)
              ^
<stdin>:12:16: note: scanning from here
 FileVersion: 1
               ^
<stdin>:13:2: note: possible intended match here
 OS/ABI: OpenBSD (0xC)
 ^

Input file: <stdin>
Check file: /b/1/llvm-x86_64-debian-dylib/llvm-project/lld/test/ELF/basic-sparcv9.s

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           .
           .
           .
           7: ElfHeader { 
           8:  Ident { 
           9:  Magic: (7F 45 4C 46) 
          10:  Class: 64-bit (0x2) 
          11:  DataEncoding: BigEndian (0x2) 
          12:  FileVersion: 1 
next:20'0                    X error: no match found
          13:  OS/ABI: OpenBSD (0xC) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~
next:20'1      ?                      possible intended match
          14:  ABIVersion: 0 
next:20'0     ~~~~~~~~~~~~~~~
          15:  Unused: (00 00 00 00 00 00 00) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          16:  } 
next:20'0     ~~~
          17:  Type: Executable (0x2) 
next:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~
...

aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
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 06cecdc.

Take two of llvm#98158 / b64c1de, which was
reverted in llvm#98494 / c026135.
Preexisting test is fixed now.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lld:ELF lld mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants