Skip to content

[llvm-ifs] Treat unknown symbol types as error. #75872

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 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/lib/InterfaceStub/IFSHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/InterfaceStub/IFSStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
11 changes: 11 additions & 0 deletions llvm/test/tools/llvm-ifs/ifs-read-invalid-symbol-type.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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: nor, Type: bogus, Undefined: true }
...

# CHECK: error: IFS symbol type for symbol 'nor' is unsupported
21 changes: 19 additions & 2 deletions llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ TEST(ElfYamlTextAPI, YAMLReadableTBE) {
EXPECT_STREQ(Stub->NeededLibs[2].c_str(), "libbar.so");
}

TEST(ElfYamlTextAPI, YAMLReadsInvalidSymbols) {
const char Data[] =
"--- !ifs-v1\n"
"IfsVersion: 1.0\n"
"SoName: test.so\n"
"Target: { ObjectFormat: ELF, Arch: x86_64, Endianness: little, "
"BitWidth: 64 }\n"
"Symbols:\n"
" - { Name: not, Type: File, Undefined: true, Size: 111, "
"Weak: true, Warning: \'All fields populated!\' }\n"
"...\n";
Expected<std::unique_ptr<IFSStub>> StubOrErr = readIFSFromBuffer(Data);
ASSERT_THAT_ERROR(
StubOrErr.takeError(),
FailedWithMessage("IFS symbol type for symbol 'not' is unsupported"));
}

TEST(ElfYamlTextAPI, YAMLReadsTBESymbols) {
const char Data[] =
"--- !ifs-v1\n"
Expand All @@ -68,7 +85,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);
Expand Down Expand Up @@ -116,7 +133,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);
Expand Down