From c941d8b0a69acd996fd7014ccb05b32c628ea386 Mon Sep 17 00:00:00 2001 From: KO Myung-Hun Date: Wed, 27 Nov 2024 13:49:02 +0900 Subject: [PATCH] outobj: make a group cumulative On any other OMF assemblers such as MASM, TASM and ALP, a group is cumulative. Signed-off-by: KO Myung-Hun --- output/outobj.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/output/outobj.c b/output/outobj.c index 281839d0..6a18e40d 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -1584,6 +1584,8 @@ obj_directive(enum directive directive, char *value) struct Segment *seg; struct External **extp; int obj_idx; + const char *segname; + int i; q = value; while (*q == '.') @@ -1612,18 +1614,19 @@ obj_directive(enum directive directive, char *value) for (grp = grphead; grp; grp = grp->next) { obj_idx++; if (!strcmp(grp->name, v)) { - nasm_nonfatal("group `%s' defined twice", v); - return DIRR_ERROR; + break; } } - *grptail = grp = nasm_malloc(sizeof(*grp)); - grp->next = NULL; - grptail = &grp->next; - grp->index = seg_alloc(); - grp->obj_index = obj_idx; - grp->nindices = grp->nentries = 0; - grp->name = NULL; + if (!grp) { + *grptail = grp = nasm_malloc(sizeof(*grp)); + grp->next = NULL; + grptail = &grp->next; + grp->index = seg_alloc(); + grp->obj_index = obj_idx; + grp->nindices = grp->nentries = 0; + grp->name = NULL; + } obj_grp_needs_update = grp; backend_label(v, grp->index + 1, 0L); @@ -1641,6 +1644,29 @@ obj_directive(enum directive directive, char *value) /* * Now p contains a segment name. Find it. */ + for (i = 0; i < grp->nentries; i++) { + if (i < grp->nindices) { + for (seg = seghead; seg; seg = seg->next) { + if (grp->segs[i].index == seg->obj_index) { + segname = seg->name; + break; + } + } + } + else + segname = grp->segs[i].name; + /* + * See if this segment is defined in this group. + */ + if (!strcmp(segname, p)) + break; + } + if (i < grp->nentries) { + /* + * We have already this segment. Skip. + */ + continue; + } for (seg = seghead; seg; seg = seg->next) if (!strcmp(seg->name, p)) break;