From 18e83c17b48469f647151ad39eaacaf46aa9c0ba Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 19 Feb 2024 00:23:00 +0100 Subject: [PATCH] Add a few more linker script tests --- src/link/script.y | 11 ++++++----- test/link/script-align-17.link | 2 ++ test/link/script-align-17.out | 2 ++ test/link/script-ds-overflow.link | 7 +++++++ test/link/script-ds-overflow.out | 3 +++ test/link/script-excess-align-ofs.link | 2 ++ test/link/script-excess-align-ofs.out | 2 ++ test/link/script-huge-ds.link | 2 ++ test/link/script-huge-ds.out | 2 ++ test/link/script-oob-org.link | 15 +++++++++++++++ test/link/script-oob-org.out | 10 ++++++++++ test/link/script-overflowing-sect.link | 5 +++++ test/link/script-overflowing-sect.out | 2 ++ test/link/script-typeless-bank.link | 1 + test/link/script-typeless-bank.out | 2 ++ test/link/script.asm | 4 ++++ 16 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 test/link/script-align-17.link create mode 100644 test/link/script-align-17.out create mode 100644 test/link/script-ds-overflow.link create mode 100644 test/link/script-ds-overflow.out create mode 100644 test/link/script-excess-align-ofs.link create mode 100644 test/link/script-excess-align-ofs.out create mode 100644 test/link/script-huge-ds.link create mode 100644 test/link/script-huge-ds.out create mode 100644 test/link/script-oob-org.link create mode 100644 test/link/script-oob-org.out create mode 100644 test/link/script-overflowing-sect.link create mode 100644 test/link/script-overflowing-sect.out create mode 100644 test/link/script-typeless-bank.link create mode 100644 test/link/script-typeless-bank.out diff --git a/src/link/script.y b/src/link/script.y index 58d9dd57..2155b6d4 100644 --- a/src/link/script.y +++ b/src/link/script.y @@ -422,7 +422,7 @@ static void alignTo(uint32_t alignment, uint32_t alignOfs) { if (alignOfs >= alignSize) { scriptError(context, "Cannot align: The alignment offset (%" PRIu32 - ") must be less than alignment size (%" PRIu32 ")\n", + ") must be less than alignment size (%" PRIu32 ")", alignOfs, alignSize); return; } @@ -437,7 +437,7 @@ static void alignTo(uint32_t alignment, uint32_t alignOfs) { auto &pc = curAddr[activeType][activeBankIdx]; if (alignment > 16) { - scriptError(context, "Cannot align: The alignment (%" PRIu32 ") must be less than 16\n", + scriptError(context, "Cannot align: The alignment (%" PRIu32 ") must be less than 16", alignment); return; } @@ -450,7 +450,7 @@ static void alignTo(uint32_t alignment, uint32_t alignOfs) { if (alignOfs >= alignSize) { scriptError(context, "Cannot align: The alignment offset (%" PRIu32 - ") must be less than alignment size (%" PRIu32 ")\n", + ") must be less than alignment size (%" PRIu32 ")", alignOfs, alignSize); return; } @@ -546,9 +546,10 @@ static void placeSection(std::string const &name, bool isOptional) { uint16_t curOfs = org - typeInfo.startAddr; if (section->size > typeInfo.size - curOfs) { - scriptError(context, "The linker script assigns section \"%s\" to address $%04" PRIx16 ", but then it would overflow %s by %" PRIx16 " bytes", + uint16_t overflowSize = section->size - (typeInfo.size - curOfs); + scriptError(context, "The linker script assigns section \"%s\" to address $%04" PRIx16 ", but then it would overflow %s by %" PRIx16 " byte%s", name.c_str(), org, typeInfo.name.c_str(), - (uint16_t)(section->size - (typeInfo.size - curOfs))); + overflowSize, overflowSize == 1 ? "" : "s"); // Fill as much as possible without going out of bounds. org = typeInfo.startAddr + typeInfo.size; } else { diff --git a/test/link/script-align-17.link b/test/link/script-align-17.link new file mode 100644 index 00000000..a37517af --- /dev/null +++ b/test/link/script-align-17.link @@ -0,0 +1,2 @@ +rom0 + align 17, $1234 diff --git a/test/link/script-align-17.out b/test/link/script-align-17.out new file mode 100644 index 00000000..757e2875 --- /dev/null +++ b/test/link/script-align-17.out @@ -0,0 +1,2 @@ +error: script-align-17.link(2): Cannot align: The alignment (17) must be less than 16 +Linking failed with 1 error diff --git a/test/link/script-ds-overflow.link b/test/link/script-ds-overflow.link new file mode 100644 index 00000000..424e6609 --- /dev/null +++ b/test/link/script-ds-overflow.link @@ -0,0 +1,7 @@ +rom0 + ds $4000 ; OK + ds 1 ; Boom! + +hram + ds $7F ; OK + ds $FFFF ; Boom! diff --git a/test/link/script-ds-overflow.out b/test/link/script-ds-overflow.out new file mode 100644 index 00000000..bf537260 --- /dev/null +++ b/test/link/script-ds-overflow.out @@ -0,0 +1,3 @@ +error: script-ds-overflow.link(3): Cannot increase the current address by 1 bytes: only 0 bytes to $4000 +error: script-ds-overflow.link(7): Cannot increase the current address by 65535 bytes: only 0 bytes to $ffff +Linking failed with 2 errors diff --git a/test/link/script-excess-align-ofs.link b/test/link/script-excess-align-ofs.link new file mode 100644 index 00000000..2ec64861 --- /dev/null +++ b/test/link/script-excess-align-ofs.link @@ -0,0 +1,2 @@ +rom0 + align 1, 2 diff --git a/test/link/script-excess-align-ofs.out b/test/link/script-excess-align-ofs.out new file mode 100644 index 00000000..8412034b --- /dev/null +++ b/test/link/script-excess-align-ofs.out @@ -0,0 +1,2 @@ +error: script-excess-align-ofs.link(2): Cannot align: The alignment offset (2) must be less than alignment size (2) +Linking failed with 1 error diff --git a/test/link/script-huge-ds.link b/test/link/script-huge-ds.link new file mode 100644 index 00000000..0bf979fd --- /dev/null +++ b/test/link/script-huge-ds.link @@ -0,0 +1,2 @@ +rom0 + ds $10000 diff --git a/test/link/script-huge-ds.out b/test/link/script-huge-ds.out new file mode 100644 index 00000000..fbd99ca8 --- /dev/null +++ b/test/link/script-huge-ds.out @@ -0,0 +1,2 @@ +error: script-huge-ds.link(2): Cannot increase the current address by 65536 bytes: only 16384 bytes to $4000 +Linking failed with 1 error diff --git a/test/link/script-oob-org.link b/test/link/script-oob-org.link new file mode 100644 index 00000000..4fedcbc0 --- /dev/null +++ b/test/link/script-oob-org.link @@ -0,0 +1,15 @@ +rom0 + org $4000 ; OK + org $4001 ; Nope + +romx 1 + org $3FFF ; Nope + org $8000 ; OK + org $8001 ; Nope + +hram + org 0 ; Nope + org $FF7F ; Nope + org $FF80 ; OK + org $FFFF ; OK + org $10000 ; Nope diff --git a/test/link/script-oob-org.out b/test/link/script-oob-org.out new file mode 100644 index 00000000..b0517043 --- /dev/null +++ b/test/link/script-oob-org.out @@ -0,0 +1,10 @@ +error: script-oob-org.link(2): Cannot set the current address to $4000: ROM0 ends at $3fff +error: script-oob-org.link(3): Cannot set the current address to $4001: ROM0 ends at $3fff +error: script-oob-org.link(6): Cannot decrease the current address (from $4000 to $3fff) +error: script-oob-org.link(7): Cannot set the current address to $8000: ROMX ends at $7fff +error: script-oob-org.link(8): Cannot set the current address to $8001: ROMX ends at $7fff +error: script-oob-org.link(11): Cannot decrease the current address (from $ff80 to $0000) +error: script-oob-org.link(12): Cannot decrease the current address (from $ff80 to $ff7f) +error: script-oob-org.link(14): Cannot set the current address to $ffff: HRAM ends at $fffe +error: script-oob-org.link(15): Cannot set the current address to $10000: HRAM ends at $fffe +Linking failed with 9 errors diff --git a/test/link/script-overflowing-sect.link b/test/link/script-overflowing-sect.link new file mode 100644 index 00000000..bf838f3e --- /dev/null +++ b/test/link/script-overflowing-sect.link @@ -0,0 +1,5 @@ + +romx 2 + org $7000 + "ROM2 1K" ; OK + "ROM2 1" ; Boom! diff --git a/test/link/script-overflowing-sect.out b/test/link/script-overflowing-sect.out new file mode 100644 index 00000000..9f58ef78 --- /dev/null +++ b/test/link/script-overflowing-sect.out @@ -0,0 +1,2 @@ +error: script-overflowing-sect.link(5): The linker script assigns section "ROM2 1" to address $8000, but then it would overflow ROMX by 1 byte +Linking failed with 1 error diff --git a/test/link/script-typeless-bank.link b/test/link/script-typeless-bank.link new file mode 100644 index 00000000..fb114a5d --- /dev/null +++ b/test/link/script-typeless-bank.link @@ -0,0 +1 @@ +"The section isn't even known" diff --git a/test/link/script-typeless-bank.out b/test/link/script-typeless-bank.out new file mode 100644 index 00000000..75173cf9 --- /dev/null +++ b/test/link/script-typeless-bank.out @@ -0,0 +1,2 @@ +error: script-typeless-bank.link(1): No memory region has been specified to place section "The section isn't even known" in +Linking failed with 1 error diff --git a/test/link/script.asm b/test/link/script.asm index 3c15d9a0..1b272ba5 100644 --- a/test/link/script.asm +++ b/test/link/script.asm @@ -3,3 +3,7 @@ SECTION "ROM0", ROM0 SECTION "ROM1", ROMX,BANK[1] +SECTION "ROM2 1K", ROMX,BANK[2] + ds $1000 +SECTION "ROM2 1", ROMX,BANK[2] + ds 1