Skip to content

Commit

Permalink
outobj: make a group cumulative
Browse files Browse the repository at this point in the history
On any other OMF assemblers such as MASM, TASM and ALP, a group is
cumulative.

Signed-off-by: KO Myung-Hun <[email protected]>
  • Loading branch information
komh committed Nov 29, 2024
1 parent 888d9ab commit 17d62ba
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions output/outobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '.')
Expand Down Expand Up @@ -1612,22 +1614,23 @@ 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;

obj_grp_needs_update = grp;
backend_label(v, grp->index + 1, 0L);
obj_grp_needs_update = 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);
obj_grp_needs_update = NULL;
}

while (*q) {
p = q;
Expand All @@ -1641,6 +1644,30 @@ 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) {
segname = NULL; /* make compiler happy */
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;
Expand Down

0 comments on commit 17d62ba

Please sign in to comment.