[llvm] [llvm-ifs] Treat unknown symbol types as error. (PR #75872)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 18 15:10:44 PST 2023
https://github.com/zeroomega created https://github.com/llvm/llvm-project/pull/75872
Before this patch, when an unknown symbol type is used in IFS stub, it will be treated as a NO_TYPE and parsed without error. This patch makes llvm-ifs throw an error when this scenario happens.
>From 3374f89d95e7888e0edb01a205cb2b4c85185265 Mon Sep 17 00:00:00 2001
From: Haowei Wu <haowei at google.com>
Date: Mon, 18 Dec 2023 15:04:57 -0800
Subject: [PATCH] [llvm-ifs] Treat unknown symbol types as error.
Before this patch, when an unknown symbol type is used in IFS stub, it
will be treated as a NO_TYPE and parsed without error. This patch makes
llvm-ifs throw an error when this scenario happens.
---
llvm/lib/InterfaceStub/IFSHandler.cpp | 6 ++++++
llvm/lib/InterfaceStub/IFSStub.cpp | 3 ++-
.../llvm-ifs/ifs-read-invalid-symbol-type.test | 15 +++++++++++++++
llvm/unittests/InterfaceStub/ELFYAMLTest.cpp | 4 ++--
4 files changed, 25 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/tools/llvm-ifs/ifs-read-invalid-symbol-type.test
diff --git a/llvm/lib/InterfaceStub/IFSHandler.cpp b/llvm/lib/InterfaceStub/IFSHandler.cpp
index da46592bd3819e..0178ff882b93bb 100644
--- a/llvm/lib/InterfaceStub/IFSHandler.cpp
+++ b/llvm/lib/InterfaceStub/IFSHandler.cpp
@@ -201,6 +201,12 @@ Expected<std::unique_ptr<IFSStub>> ifs::readIFSFromBuffer(StringRef Buf) {
"IFS arch '" + *Stub->Target.ArchString + "' is unsupported");
Stub->Target.Arch = eMachine;
}
+ for (const auto &item : Stub->Symbols) {
+ if (item.Type == IFSSymbolType::Unknown)
+ return createStringError(
+ std::make_error_code(std::errc::invalid_argument),
+ "IFS symbol type for symbol '" + item.Name + "' is unsupported");
+ }
return std::move(Stub);
}
diff --git a/llvm/lib/InterfaceStub/IFSStub.cpp b/llvm/lib/InterfaceStub/IFSStub.cpp
index f043f7e9e383f2..cde15ccfdba069 100644
--- a/llvm/lib/InterfaceStub/IFSStub.cpp
+++ b/llvm/lib/InterfaceStub/IFSStub.cpp
@@ -89,8 +89,9 @@ uint8_t ifs::convertIFSSymbolTypeToELF(IFSSymbolType SymbolType) {
case IFSSymbolType::TLS:
return ELF::STT_TLS;
case IFSSymbolType::NoType:
- default:
return ELF::STT_NOTYPE;
+ default:
+ llvm_unreachable("unknown symbol type");
}
}
diff --git a/llvm/test/tools/llvm-ifs/ifs-read-invalid-symbol-type.test b/llvm/test/tools/llvm-ifs/ifs-read-invalid-symbol-type.test
new file mode 100644
index 00000000000000..b4b8ede7f7853c
--- /dev/null
+++ b/llvm/test/tools/llvm-ifs/ifs-read-invalid-symbol-type.test
@@ -0,0 +1,15 @@
+# RUN: not llvm-ifs --output-ifs=- %s 2>&1 | FileCheck %s
+
+--- !ifs-v1
+SoName: somelib.so
+IfsVersion: 3.0
+Target: { ObjectFormat: ELF, Arch: Aarch64, Endianness: little, BitWidth: 64 }
+Symbols:
+ - { Name: foo, Type: Func }
+ - { Name: bar, Type: Object, Size: 42 }
+ - { Name: baz, Type: Object, Size: 8 }
+ - { Name: not, Type: Object, Size: 128, Undefined: true }
+ - { Name: nor, Type: bogus, Undefined: true }
+...
+
+# CHECK: error: IFS symbol type for symbol 'nor' is unsupported
diff --git a/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp b/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
index 5008f053888629..83d1e5e09fc0b3 100644
--- a/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
+++ b/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
@@ -68,7 +68,7 @@ TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) {
" - { Name: baz, Type: TLS, Size: 3 }\n"
" - { Name: foo, Type: Func, Warning: \"Deprecated!\" }\n"
" - { Name: nor, Type: NoType, Undefined: true }\n"
- " - { Name: not, Type: File, Undefined: true, Size: 111, "
+ " - { Name: not, Type: NoType, Undefined: true, Size: 111, "
"Weak: true, Warning: \'All fields populated!\' }\n"
"...\n";
Expected<std::unique_ptr<IFSStub>> StubOrErr = readIFSFromBuffer(Data);
@@ -116,7 +116,7 @@ TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) {
IFSSymbol const &SymNot = *Iterator++;
EXPECT_STREQ(SymNot.Name.c_str(), "not");
EXPECT_EQ(*SymNot.Size, 111u);
- EXPECT_EQ(SymNot.Type, IFSSymbolType::Unknown);
+ EXPECT_EQ(SymNot.Type, IFSSymbolType::NoType);
EXPECT_TRUE(SymNot.Undefined);
EXPECT_TRUE(SymNot.Weak);
EXPECT_TRUE(SymNot.Warning);
More information about the llvm-commits
mailing list