-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[BinaryFormat] Adjust OSABI functions and add unittests #90270
[BinaryFormat] Adjust OSABI functions and add unittests #90270
Conversation
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-llvm-binary-utilities Author: Fangrui Song (MaskRay) ChangesAdjust #89280: Full diff: https://github.com/llvm/llvm-project/pull/90270.diff 3 Files Affected:
diff --git a/llvm/lib/BinaryFormat/ELF.cpp b/llvm/lib/BinaryFormat/ELF.cpp
index 8c10ed1a980bbc..a07e5423a2ab66 100644
--- a/llvm/lib/BinaryFormat/ELF.cpp
+++ b/llvm/lib/BinaryFormat/ELF.cpp
@@ -573,7 +573,7 @@ uint8_t ELF::convertOSToOSAbi(StringRef OS) {
return StringSwitch<uint16_t>(LowerOS)
.StartsWith("hpux", ELFOSABI_HPUX)
.StartsWith("netbsd", ELFOSABI_NETBSD)
- .StartsWith("linux", ELFOSABI_LINUX)
+ .StartsWith("gnu", ELFOSABI_GNU)
.StartsWith("hurd", ELFOSABI_HURD)
.StartsWith("solaris", ELFOSABI_SOLARIS)
.StartsWith("aix", ELFOSABI_AIX)
@@ -603,8 +603,8 @@ StringRef ELF::convertOSAbiToOS(uint8_t OSAbi) {
return "hpux";
case ELFOSABI_NETBSD:
return "netbsd";
- case ELFOSABI_LINUX:
- return "linux";
+ case ELFOSABI_GNU:
+ return "gnu";
case ELFOSABI_HURD:
return "hurd";
case ELFOSABI_SOLARIS:
diff --git a/llvm/unittests/BinaryFormat/CMakeLists.txt b/llvm/unittests/BinaryFormat/CMakeLists.txt
index f0c42a0dd02b8e..40d3bc4dca0b66 100644
--- a/llvm/unittests/BinaryFormat/CMakeLists.txt
+++ b/llvm/unittests/BinaryFormat/CMakeLists.txt
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_unittest(BinaryFormatTests
DwarfTest.cpp
+ ELFTest.cpp
MachOTest.cpp
MsgPackDocumentTest.cpp
MsgPackReaderTest.cpp
diff --git a/llvm/unittests/BinaryFormat/ELFTest.cpp b/llvm/unittests/BinaryFormat/ELFTest.cpp
new file mode 100644
index 00000000000000..29793bf99c6000
--- /dev/null
+++ b/llvm/unittests/BinaryFormat/ELFTest.cpp
@@ -0,0 +1,32 @@
+//===- ELFTest.cpp ----------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/BinaryFormat/ELF.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::ELF;
+
+namespace {
+TEST(ELFTest, OSAbi) {
+ EXPECT_EQ(ELFOSABI_GNU, convertOSToOSAbi("gnu"));
+ EXPECT_EQ(ELFOSABI_FREEBSD, convertOSToOSAbi("freebsd"));
+ EXPECT_EQ(ELFOSABI_STANDALONE, convertOSToOSAbi("standalone"));
+ EXPECT_EQ(ELFOSABI_NONE, convertOSToOSAbi("none"));
+ // Test unrecognized strings.
+ EXPECT_EQ(ELFOSABI_NONE, convertOSToOSAbi(""));
+ EXPECT_EQ(ELFOSABI_NONE, convertOSToOSAbi("linux"));
+
+ EXPECT_EQ("gnu", convertOSAbiToOS(ELFOSABI_GNU));
+ EXPECT_EQ("freebsd", convertOSAbiToOS(ELFOSABI_FREEBSD));
+ EXPECT_EQ("standalone", convertOSAbiToOS(ELFOSABI_STANDALONE));
+ EXPECT_EQ("none", convertOSAbiToOS(ELFOSABI_NONE));
+ // Test unrecognized values.
+ EXPECT_EQ("none", convertOSAbiToOS(0xfe));
+}
+} // namespace
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of nits, but otherwise LGTM.
llvm/include/llvm/BinaryFormat/ELF.h
Outdated
/// Convert a OS into ELF's EI_OSABI value. | ||
uint8_t convertOSToOSAbi(StringRef OS); | ||
// Convert a lowercase string identifier into an OSABI value. | ||
uint8_t convertNameToOSAbi(StringRef Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: whilst changing the signature, now might be a good time to fix the casing of Abi
to ABI
, since it's an acronym and therefore should be all uppercase. Same below, including the parameter.
@@ -0,0 +1,32 @@ | |||
//===- ELFTest.cpp ----------------------------------------------*- C++ -*-===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I believe the C++
marker only needs to be in headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-*- C++ -*-
is indeed a rare exception, so I am removing the marker.
% rg 'C\+\+ \*-=' -l -g '*.cpp'
llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp
llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp
llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp
llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp
llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp
llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
llvm/lib/MC/SPIRVObjectWriter.cpp
Created using spr 1.3.5-bogner
Adjust #89280:
code. readelf -h displays "UNIX - GNU" instead of "Linux".
ELFOSABI_ARM.
Add some unittests.