Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outobj: make a group cumulative #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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