From 98f42697409d53ee45da744d167ab875ed4fde8b Mon Sep 17 00:00:00 2001 From: Andrew Chambers Date: Wed, 20 Oct 2021 20:41:41 +1300 Subject: Use a fatal error instead of assert, improve jmp tests. --- main.c | 6 ++++-- test/test.sh | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index eb74bc8..df26f3e 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,3 @@ -#include #include "minias.h" /* Parsed assembly */ @@ -923,12 +922,15 @@ resolvereloc(Relocation *reloc) case R_X86_64_PC8: rdata = &reloc->section->data[reloc->offset]; value = sym->offset - reloc->offset + reloc->addend; - assert(value >= INT8_MIN && value <= INT8_MAX); + if (value > INT8_MAX || value < INT8_MIN) + fatal("R_X86_64_PC8 relocation overflow"); rdata[0] = value; return 1; case R_X86_64_PC32: rdata = &reloc->section->data[reloc->offset]; value = sym->offset - reloc->offset + reloc->addend; + if (value > INT32_MAX || value < INT32_MIN) + fatal("R_X86_64_PC32 relocation overflow"); rdata[0] = ((uint32_t)value & 0xff); rdata[1] = ((uint32_t)value & 0xff00) >> 8; rdata[2] = ((uint32_t)value & 0xff0000) >> 16; diff --git a/test/test.sh b/test/test.sh index c68e469..3510fa4 100644 --- a/test/test.sh +++ b/test/test.sh @@ -160,15 +160,21 @@ conditioncodes=" o p pe po s z " -for fill in 0 1 129 +t "l:\n .fill 1, 1, 0x00 \njmp l" +t "jmp l\n .fill 1, 1, 0x00 \nl:" +for cc in $conditioncodes +do + t "l:\n .fill 1, 1, 0x00 \nj${cc} l" + t "j${cc} l\n .fill 1, 1, 0x00 \nl:" +done + +# Check boundary on jump relaxing. +for fill in 0 $(seq 120 140) do t "l:\n .fill $fill, 1, 0x00 \njmp l" t "jmp l\n .fill $fill, 1, 0x00 \nl:" - for cc in $conditioncodes - do - t "l:\n .fill $fill, 1, 0x00 \nj${cc} l" - t "j${cc} l\n .fill $fill, 1, 0x00 \nl:" - done + t "l:\n .fill $fill, 1, 0x00 \njz l" + t "jz l\n .fill $fill, 1, 0x00 \nl:" done for cc in $conditioncodes -- cgit v1.2.3