Skip to content
Closed
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
19 changes: 19 additions & 0 deletions core/relinker/relinker/tests/test_guest_none_relocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ def change_tag(image, tag, value=None, replacement=None):
raise AssertionError(f"Missing dynamic tag {tag:#x}")


def invalid_tls_segment_large_memsz(image):
image = bytearray(image)
phnum, = struct.unpack_from("<H", image, 56)
insert_at = 64 + phnum * 56
if insert_at + 56 > len(image):
image.extend(bytes(insert_at + 56 - len(image)))
struct.pack_into("<IIQQQQQQ", image, insert_at, 7, 4, 0x2700, 0x2700, 0x2700, 0, 0x80000000, 8)
struct.pack_into("<H", image, 56, phnum + 1)
return image


def unsized_lifecycle(rela, sce, initial):
image = module(rela, sce=sce, lifecycle=True, initial=initial)
return change_tag(change_tag(image, 27, replacement=0x61000001), 28, replacement=0x61000001)
Expand Down Expand Up @@ -140,6 +151,10 @@ def invalid_cases(sce):
replacement=20 if sce else 0x6100002b), "Missing or ambiguous dynamic tag"


def invalid_cases_windows(sce):
yield "invalid-tls-segment-large-memsz", invalid_tls_segment_large_memsz(module([NOOP], sce=sce)), "Invalid or unsupported ELF TLS layout"


def main():
if sys.argv[1] == "--load":
import ctypes
Expand Down Expand Up @@ -206,6 +221,10 @@ def convert(name, system, image):
result, artifact, output = convert(f"{sce}-{name}", "linux", image)
assert result.returncode == 2 and error in result.stderr, (sce, name, result.stderr)
assert not artifact.exists() and not output.exists(), name
for name, image, error in invalid_cases_windows(sce):
result, artifact, output = convert(f"{sce}-{name}", "windows", image)
assert result.returncode == 2 and error in result.stderr, (sce, name, result.stderr)
assert not artifact.exists() and not output.exists(), name
print("Guest no-op relocation tests passed")


Expand Down
Loading