From dddff0f4507f297c0bd36d77caf5180be7f56acd Mon Sep 17 00:00:00 2001 From: Rangi Date: Fri, 12 Feb 2021 15:54:15 -0500 Subject: [PATCH] Cannot start a new section that's already on the stack This is only relevant for FRAGMENT or UNION sections, since normal ones would fail with "Section already defined previously". Fixes #730 --- src/asm/section.c | 12 ++++++------ test/asm/new-pushed-section.asm | 7 +++++++ test/asm/new-pushed-section.err | 2 ++ test/asm/new-pushed-section.out | 0 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 test/asm/new-pushed-section.asm create mode 100644 test/asm/new-pushed-section.err create mode 100644 test/asm/new-pushed-section.out diff --git a/src/asm/section.c b/src/asm/section.c index e77018ea..44a816f2 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -87,15 +87,10 @@ static inline void reserveSpace(uint32_t delta_size) struct Section *out_FindSectionByName(const char *name) { - struct Section *sect = pSectionList; - - while (sect) { + for (struct Section *sect = pSectionList; sect; sect = sect->next) { if (strcmp(name, sect->name) == 0) return sect; - - sect = sect->next; } - return NULL; } @@ -376,6 +371,11 @@ void out_NewSection(char const *name, uint32_t type, uint32_t org, if (currentLoadSection) fatalerror("Cannot change the section within a `LOAD` block\n"); + for (struct SectionStackEntry *stack = sectionStack; stack; stack = stack->next) { + if (stack->section && !strcmp(name, stack->section->name)) + fatalerror("Section '%s' is already on the stack\n", name); + } + struct Section *sect = getSection(name, type, org, attribs, mod); changeSection(); diff --git a/test/asm/new-pushed-section.asm b/test/asm/new-pushed-section.asm new file mode 100644 index 00000000..c94bcda3 --- /dev/null +++ b/test/asm/new-pushed-section.asm @@ -0,0 +1,7 @@ +SECTION FRAGMENT "A", ROM0 + db 1 +PUSHS +SECTION FRAGMENT "A", ROM0 + db 2 +POPS + db 3 diff --git a/test/asm/new-pushed-section.err b/test/asm/new-pushed-section.err new file mode 100644 index 00000000..8a1b9beb --- /dev/null +++ b/test/asm/new-pushed-section.err @@ -0,0 +1,2 @@ +FATAL: new-pushed-section.asm(4): + Section 'A' is already on the stack diff --git a/test/asm/new-pushed-section.out b/test/asm/new-pushed-section.out new file mode 100644 index 00000000..e69de29b