Skip to content
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
4 changes: 2 additions & 2 deletions core/relinker/elfpatcher/src/windows/WindowsLoadImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Elfpatcher::Windows {

WindowsLoadImage::WindowsLoadImage(const std::vector<std::uint8_t>& source, const std::vector<Domain::ProgramHeader>& headers, const bool requireEntry, const std::uint64_t imageBase) : imageBase(imageBase) {
if (source.size() < 64 || Io::ReadU32(source, 0) != 0x464c457f || source[4] != 2 || source[5] != 1 || source[6] != 1 || Io::ReadU16(source, 18) != 62)
throw Domain::RelinkerException("Windows output requires a little-endian ELF64 x86-64 image");
throw Domain::RelinkerException("This target requires a little-endian ELF64 x86-64 image");
const auto type = Io::ReadU16(source, 16);
if (type != 3 && type != 0xfe10 && type != 0xfe18)
throw Domain::RelinkerException("Windows output requires a position-independent ELF image");
throw Domain::RelinkerException("This target requires a position-independent ELF image");
for (const auto& header : headers) {
if (header.Type != 1)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PeRelocations WindowsRelocationBuilder::Apply(WindowsLoadImage& image, const Dom
const auto type = static_cast<std::uint32_t>(info);
const auto symbol = info >> 32;
if ((plt && type != 7) || (type != 1 && type != 6 && type != 7 && type != 8 && type != 16 && type != 17 && type != 18))
throw Domain::RelinkerException("Unsupported Windows relocation type " + std::to_string(type), target);
throw Domain::RelinkerException("Relocation type " + std::to_string(type) + " is not supported for this target", target);
if (target > std::numeric_limits<std::uint64_t>::max() - 8)
throw Domain::RelinkerException("Relocation target address overflow", target);
const auto rva = image.GetRva(target, 8);
Expand Down
2 changes: 1 addition & 1 deletion core/relinker/relinker/tests/test_elf_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def object_type_cases(relinker, directory):
for filter_level in (0, 1, 2):
for object_type, error in cases:
if object_type == 2 and ("--windows" in flags or "--macos" in flags):
continue
error = "This target requires a position-independent ELF image"
case = Path(directory) / f"type-{mode}-{filter_level}-{object_type}"
case.mkdir()
source = case / "input.elf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
STT_TLS. The Windows and macOS images resolve TPOFF64 and DTPOFF64 statically against their block,
AlignUp(p_memsz, p_align) below the thread pointer, and reject what they cannot express. Every target
rejects the link-time types GOT32, PLT32, GOTPCREL, 32S, GOTPCRELX and REX_GOTPCRELX, which glibc's
ld.so does not apply."""
ld.so does not apply; the Windows and macOS images also reject other types they cannot apply, such as
PC32 and 32."""

from pathlib import Path
import struct
Expand Down Expand Up @@ -148,6 +149,10 @@ def main():
("dtpmod-addend", [(0x1000, DTPMOD64, NULL, 1)], True, (), "DTPMOD64 relocation has a nonzero addend"),
("windows-dtpmod", [(0x1000, DTPMOD64, NULL, 0)], True, ("--windows",), "DTPMOD64 relocation is not supported"),
("windows-import", [(0x1000, TPOFF64, IMPORTED, 0)], True, ("--windows",), "Imported TLS relocation"),
("windows-pc32", [(0x1000, 2, NULL, 0)], True, ("--windows",), "Relocation type 2 is not supported for this target"),
("windows-32", [(0x1000, 10, NULL, 0)], True, ("--windows",), "Relocation type 10 is not supported for this target"),
("macos-pc32", [(0x1000, 2, NULL, 0)], True, ("--macos",), "Relocation type 2 is not supported for this target"),
("macos-32", [(0x1000, 10, NULL, 0)], True, ("--macos",), "Relocation type 10 is not supported for this target"),
("macos-dtpmod", [(0x1000, DTPMOD64, NULL, 0)], True, ("--macos",), "DTPMOD64 relocation is not supported"),
("macos-import", [(0x1000, TPOFF64, IMPORTED, 0)], True, ("--macos",), "Imported TLS relocation"),
] + [(f"{target}-{name}", [(0x1000, kind, NULL, 0)], True, flags, f"Unsupported relocation type {kind:#x}")
Expand Down
Loading