Throw on invalid relocation type.

This commit is contained in:
Christian Speckner 2024-08-11 10:33:29 +02:00
parent 2a0fd0feb5
commit 647263aed7
2 changed files with 16 additions and 1 deletions

View File

@ -467,10 +467,12 @@ void ElfLinker::applyRelocationToSection(const ElfFile::Relocation& relocation,
ElfLinkError::raise("unable to relocate jump: offset out of bounds");
write32(target, elfUtil::encode_B_BL(offset, relocation.type == ElfFile::R_ARM_THM_CALL));
break;
}
default:
break;
ElfLinkError::raise("unknown relocation type");
}
}

View File

@ -1028,4 +1028,17 @@ TEST(ElfLinker, RodataSectionsGoToRodata) {
INSTANTIATE_TEST_SUITE_P(InitArraySuite, InitArrayTest, testing::Values(
ElfFile::SHT_INIT_ARRAY, ElfFile::SHT_PREINIT_ARRAY
));
TEST(ElfLinker, R_ARM_ABS32_UnknownRelocationTypeThrows) {
ElfFixture fixture(1000);
ElfLinker linker(0x00100000, 0x00200000, 0x00300000, fixture);
fixture
.addSection(".text.1", ElfFile::SHT_PROGBITS, 0, 0x10)
.addSection(".text.2", ElfFile::SHT_PROGBITS, 0x10, 0x10)
.addSymbol("foo", 0x12345678, ElfFile::SHN_ABS)
.addRelocation(2, 0, 0x04, 255);
EXPECT_THROW(linker.link({}), ElfLinker::ElfLinkError);
}
}