mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-07-24 10:25:42 -04:00
output: obj -- Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
f8d9bf9d83
commit
0623e7dcf5
@ -774,8 +774,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
bool used_special = false; /* have we used the special text? */
|
bool used_special = false; /* have we used the special text? */
|
||||||
|
|
||||||
#if defined(DEBUG) && DEBUG>2
|
#if defined(DEBUG) && DEBUG>2
|
||||||
nasm_error(ERR_DEBUG,
|
nasm_debug(" obj_deflabel: %s, seg=%"PRIx32", off=%"PRIx64", is_global=%d, %s\n",
|
||||||
" obj_deflabel: %s, seg=%"PRIx32", off=%"PRIx64", is_global=%d, %s\n",
|
|
||||||
name, segment, offset, is_global, special);
|
name, segment, offset, is_global, special);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -795,7 +794,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
obj_entry_ofs = offset;
|
obj_entry_ofs = offset;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
|
nasm_nonfatal("unrecognised special symbol `%s'", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -826,7 +825,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
pub->segment = (segment == NO_SEG ? 0 : segment & ~SEG_ABS);
|
pub->segment = (segment == NO_SEG ? 0 : segment & ~SEG_ABS);
|
||||||
}
|
}
|
||||||
if (special)
|
if (special)
|
||||||
nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features"
|
nasm_nonfatal("OBJ supports no special symbol features"
|
||||||
" for this symbol type");
|
" for this symbol type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -855,8 +854,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
loc->offset = offset;
|
loc->offset = offset;
|
||||||
|
|
||||||
if (special)
|
if (special)
|
||||||
nasm_error(ERR_NONFATAL,
|
nasm_nonfatal("OBJ supports no special symbol features"
|
||||||
"OBJ supports no special symbol features"
|
|
||||||
" for this symbol type");
|
" for this symbol type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -922,7 +920,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
obj_ext_set_defwrt(ext, p);
|
obj_ext_set_defwrt(ext, p);
|
||||||
special += len;
|
special += len;
|
||||||
if (*special && *special != ':')
|
if (*special && *special != ':')
|
||||||
nasm_error(ERR_NONFATAL, "`:' expected in special symbol"
|
nasm_nonfatal("`:' expected in special symbol"
|
||||||
" text for `%s'", ext->name);
|
" text for `%s'", ext->name);
|
||||||
else if (*special == ':')
|
else if (*special == ':')
|
||||||
special++;
|
special++;
|
||||||
@ -936,8 +934,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
if (ext->commonsize)
|
if (ext->commonsize)
|
||||||
ext->commonelem = 1;
|
ext->commonelem = 1;
|
||||||
else
|
else
|
||||||
nasm_error(ERR_NONFATAL,
|
nasm_nonfatal("`%s': `far' keyword may only be applied"
|
||||||
"`%s': `far' keyword may only be applied"
|
|
||||||
" to common variables\n", ext->name);
|
" to common variables\n", ext->name);
|
||||||
special += 3;
|
special += 3;
|
||||||
special += strspn(special, " \t");
|
special += strspn(special, " \t");
|
||||||
@ -945,8 +942,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
if (ext->commonsize)
|
if (ext->commonsize)
|
||||||
ext->commonelem = 0;
|
ext->commonelem = 0;
|
||||||
else
|
else
|
||||||
nasm_error(ERR_NONFATAL,
|
nasm_nonfatal("`%s': `far' keyword may only be applied"
|
||||||
"`%s': `far' keyword may only be applied"
|
|
||||||
" to common variables\n", ext->name);
|
" to common variables\n", ext->name);
|
||||||
special += 4;
|
special += 4;
|
||||||
special += strspn(special, " \t");
|
special += strspn(special, " \t");
|
||||||
@ -971,15 +967,14 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
|
e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
|
||||||
if (e) {
|
if (e) {
|
||||||
if (!is_simple(e))
|
if (!is_simple(e))
|
||||||
nasm_error(ERR_NONFATAL, "cannot use relocatable"
|
nasm_nonfatal("cannot use relocatable"
|
||||||
" expression as common-variable element size");
|
" expression as common-variable element size");
|
||||||
else
|
else
|
||||||
ext->commonelem = reloc_value(e);
|
ext->commonelem = reloc_value(e);
|
||||||
}
|
}
|
||||||
special = stdscan_get();
|
special = stdscan_get();
|
||||||
} else {
|
} else {
|
||||||
nasm_error(ERR_NONFATAL,
|
nasm_nonfatal("`%s': element-size specifications only"
|
||||||
"`%s': element-size specifications only"
|
|
||||||
" apply to common variables", ext->name);
|
" apply to common variables", ext->name);
|
||||||
while (*special && *special != ':')
|
while (*special && *special != ':')
|
||||||
special++;
|
special++;
|
||||||
@ -1010,7 +1005,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
ext->index = ++externals;
|
ext->index = ++externals;
|
||||||
|
|
||||||
if (special && !used_special)
|
if (special && !used_special)
|
||||||
nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features"
|
nasm_nonfatal("OBJ supports no special symbol features"
|
||||||
" for this symbol type");
|
" for this symbol type");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1079,10 +1074,10 @@ static void obj_out(int32_t segto, const void *data,
|
|||||||
size = abs((int)size);
|
size = abs((int)size);
|
||||||
|
|
||||||
if (segment == NO_SEG && type != OUT_ADDRESS)
|
if (segment == NO_SEG && type != OUT_ADDRESS)
|
||||||
nasm_error(ERR_NONFATAL, "relative call to absolute address not"
|
nasm_nonfatal("relative call to absolute address not"
|
||||||
" supported by OBJ format");
|
" supported by OBJ format");
|
||||||
if (segment >= SEG_ABS)
|
if (segment >= SEG_ABS)
|
||||||
nasm_error(ERR_NONFATAL, "far-absolute relocations not supported"
|
nasm_nonfatal("far-absolute relocations not supported"
|
||||||
" by OBJ format");
|
" by OBJ format");
|
||||||
|
|
||||||
ldata = *(int64_t *)data;
|
ldata = *(int64_t *)data;
|
||||||
@ -1128,7 +1123,7 @@ static void obj_out(int32_t segto, const void *data,
|
|||||||
|
|
||||||
switch (size) {
|
switch (size) {
|
||||||
default:
|
default:
|
||||||
nasm_error(ERR_NONFATAL, "OBJ format can only handle 16- or "
|
nasm_nonfatal("OBJ format can only handle 16- or "
|
||||||
"32-byte relocations");
|
"32-byte relocations");
|
||||||
segment = NO_SEG; /* Don't actually generate a relocation */
|
segment = NO_SEG; /* Don't actually generate a relocation */
|
||||||
break;
|
break;
|
||||||
@ -1152,7 +1147,7 @@ static void obj_out(int32_t segto, const void *data,
|
|||||||
*/
|
*/
|
||||||
rsize = 2;
|
rsize = 2;
|
||||||
if (ldata & 0xFFFF)
|
if (ldata & 0xFFFF)
|
||||||
nasm_error(ERR_NONFATAL, "OBJ format cannot handle complex"
|
nasm_nonfatal("OBJ format cannot handle complex"
|
||||||
" dword-size segment base references");
|
" dword-size segment base references");
|
||||||
}
|
}
|
||||||
if (segment != NO_SEG)
|
if (segment != NO_SEG)
|
||||||
@ -1164,8 +1159,7 @@ static void obj_out(int32_t segto, const void *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
nasm_error(ERR_NONFATAL,
|
nasm_nonfatal("Relocation type not supported by output format");
|
||||||
"Relocation type not supported by output format");
|
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
|
||||||
case OUT_RESERVE:
|
case OUT_RESERVE:
|
||||||
@ -1191,7 +1185,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
|
|||||||
ObjRecord *forp;
|
ObjRecord *forp;
|
||||||
|
|
||||||
if (bytes != 2 && bytes != 4) {
|
if (bytes != 2 && bytes != 4) {
|
||||||
nasm_error(ERR_NONFATAL, "`obj' output driver does not support"
|
nasm_nonfatal("`obj' output driver does not support"
|
||||||
" %d-bit relocations", bytes << 3);
|
" %d-bit relocations", bytes << 3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1282,7 +1276,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
|
|||||||
else if (e->defwrt_type == DEFWRT_GROUP)
|
else if (e->defwrt_type == DEFWRT_GROUP)
|
||||||
method |= 0x10, fidx = e->defwrt_ptr.grp->obj_index;
|
method |= 0x10, fidx = e->defwrt_ptr.grp->obj_index;
|
||||||
else {
|
else {
|
||||||
nasm_error(ERR_NONFATAL, "default WRT specification for"
|
nasm_nonfatal("default WRT specification for"
|
||||||
" external `%s' unresolved", e->name);
|
" external `%s' unresolved", e->name);
|
||||||
method |= 0x50, fidx = -1; /* got to do _something_ */
|
method |= 0x50, fidx = -1; /* got to do _something_ */
|
||||||
}
|
}
|
||||||
@ -1339,7 +1333,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
|
|||||||
* by sponging off the label manager.
|
* by sponging off the label manager.
|
||||||
*/
|
*/
|
||||||
#if defined(DEBUG) && DEBUG>=3
|
#if defined(DEBUG) && DEBUG>=3
|
||||||
nasm_error(ERR_DEBUG, " obj_segment: < %s >, pass=%d, *bits=%d\n",
|
nasm_debug(" obj_segment: < %s >, pass=%d, *bits=%d\n",
|
||||||
name, pass, *bits);
|
name, pass, *bits);
|
||||||
#endif
|
#endif
|
||||||
if (!name) {
|
if (!name) {
|
||||||
@ -1386,7 +1380,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
|
|||||||
|
|
||||||
if (!strcmp(seg->name, name)) {
|
if (!strcmp(seg->name, name)) {
|
||||||
if (attrs > 0 && pass == 1)
|
if (attrs > 0 && pass == 1)
|
||||||
nasm_error(ERR_WARNING, "segment attributes specified on"
|
nasm_warn("segment attributes specified on"
|
||||||
" redeclaration of segment: ignoring");
|
" redeclaration of segment: ignoring");
|
||||||
if (seg->use32)
|
if (seg->use32)
|
||||||
*bits = 32;
|
*bits = 32;
|
||||||
@ -1477,8 +1471,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
|
|||||||
seg->align = readnum(p + 6, &rn_error);
|
seg->align = readnum(p + 6, &rn_error);
|
||||||
if (rn_error) {
|
if (rn_error) {
|
||||||
seg->align = 1;
|
seg->align = 1;
|
||||||
nasm_error(ERR_NONFATAL, "segment alignment should be"
|
nasm_nonfatal("segment alignment should be numeric");
|
||||||
" numeric");
|
|
||||||
}
|
}
|
||||||
switch (seg->align) {
|
switch (seg->align) {
|
||||||
case 1: /* BYTE */
|
case 1: /* BYTE */
|
||||||
@ -1489,29 +1482,26 @@ static int32_t obj_segment(char *name, int pass, int *bits)
|
|||||||
case 4096: /* PharLap extension */
|
case 4096: /* PharLap extension */
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
nasm_error(ERR_WARNING,
|
nasm_warn("OBJ format does not support alignment"
|
||||||
"OBJ format does not support alignment"
|
|
||||||
" of 8: rounding up to 16");
|
" of 8: rounding up to 16");
|
||||||
seg->align = 16;
|
seg->align = 16;
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
case 64:
|
case 64:
|
||||||
case 128:
|
case 128:
|
||||||
nasm_error(ERR_WARNING,
|
nasm_warn("OBJ format does not support alignment"
|
||||||
"OBJ format does not support alignment"
|
|
||||||
" of %d: rounding up to 256", seg->align);
|
" of %d: rounding up to 256", seg->align);
|
||||||
seg->align = 256;
|
seg->align = 256;
|
||||||
break;
|
break;
|
||||||
case 512:
|
case 512:
|
||||||
case 1024:
|
case 1024:
|
||||||
case 2048:
|
case 2048:
|
||||||
nasm_error(ERR_WARNING,
|
nasm_warn("OBJ format does not support alignment"
|
||||||
"OBJ format does not support alignment"
|
|
||||||
" of %d: rounding up to 4096", seg->align);
|
" of %d: rounding up to 4096", seg->align);
|
||||||
seg->align = 4096;
|
seg->align = 4096;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nasm_error(ERR_NONFATAL, "invalid alignment value %d",
|
nasm_nonfatal("invalid alignment value %d",
|
||||||
seg->align);
|
seg->align);
|
||||||
seg->align = 1;
|
seg->align = 1;
|
||||||
break;
|
break;
|
||||||
@ -1519,7 +1509,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
|
|||||||
} else if (!nasm_strnicmp(p, "absolute=", 9)) {
|
} else if (!nasm_strnicmp(p, "absolute=", 9)) {
|
||||||
seg->align = SEG_ABS + readnum(p + 9, &rn_error);
|
seg->align = SEG_ABS + readnum(p + 9, &rn_error);
|
||||||
if (rn_error)
|
if (rn_error)
|
||||||
nasm_error(ERR_NONFATAL, "argument to `absolute' segment"
|
nasm_nonfatal("argument to `absolute' segment"
|
||||||
" attribute should be numeric");
|
" attribute should be numeric");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1544,8 +1534,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
|
|||||||
grp->segs[i] = grp->segs[grp->nindices];
|
grp->segs[i] = grp->segs[grp->nindices];
|
||||||
grp->segs[grp->nindices++].index = seg->obj_index;
|
grp->segs[grp->nindices++].index = seg->obj_index;
|
||||||
if (seg->grp)
|
if (seg->grp)
|
||||||
nasm_error(ERR_WARNING,
|
nasm_warn("segment `%s' is already part of"
|
||||||
"segment `%s' is already part of"
|
|
||||||
" a group: first one takes precedence",
|
" a group: first one takes precedence",
|
||||||
seg->name);
|
seg->name);
|
||||||
else
|
else
|
||||||
@ -1620,7 +1609,7 @@ obj_directive(enum directive directive, char *value, int pass)
|
|||||||
for (grp = grphead; grp; grp = grp->next) {
|
for (grp = grphead; grp; grp = grp->next) {
|
||||||
obj_idx++;
|
obj_idx++;
|
||||||
if (!strcmp(grp->name, v)) {
|
if (!strcmp(grp->name, v)) {
|
||||||
nasm_error(ERR_NONFATAL, "group `%s' defined twice", v);
|
nasm_nonfatal("group `%s' defined twice", v);
|
||||||
return DIRR_ERROR;
|
return DIRR_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1660,8 +1649,7 @@ obj_directive(enum directive directive, char *value, int pass)
|
|||||||
grp->segs[grp->nentries++] = grp->segs[grp->nindices];
|
grp->segs[grp->nentries++] = grp->segs[grp->nindices];
|
||||||
grp->segs[grp->nindices++].index = seg->obj_index;
|
grp->segs[grp->nindices++].index = seg->obj_index;
|
||||||
if (seg->grp)
|
if (seg->grp)
|
||||||
nasm_error(ERR_WARNING,
|
nasm_warn("segment `%s' is already part of"
|
||||||
"segment `%s' is already part of"
|
|
||||||
" a group: first one takes precedence",
|
" a group: first one takes precedence",
|
||||||
seg->name);
|
seg->name);
|
||||||
else
|
else
|
||||||
@ -1725,7 +1713,7 @@ obj_directive(enum directive directive, char *value, int pass)
|
|||||||
impname = q;
|
impname = q;
|
||||||
|
|
||||||
if (!*extname || !*libname)
|
if (!*extname || !*libname)
|
||||||
nasm_error(ERR_NONFATAL, "`import' directive requires symbol name"
|
nasm_nonfatal("`import' directive requires symbol name"
|
||||||
" and library name");
|
" and library name");
|
||||||
else {
|
else {
|
||||||
struct ImpDef *imp;
|
struct ImpDef *imp;
|
||||||
@ -1773,7 +1761,7 @@ obj_directive(enum directive directive, char *value, int pass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!*intname) {
|
if (!*intname) {
|
||||||
nasm_error(ERR_NONFATAL, "`export' directive requires export name");
|
nasm_nonfatal("`export' directive requires export name");
|
||||||
return DIRR_OK;
|
return DIRR_OK;
|
||||||
}
|
}
|
||||||
if (!*extname) {
|
if (!*extname) {
|
||||||
@ -1797,16 +1785,14 @@ obj_directive(enum directive directive, char *value, int pass)
|
|||||||
bool err = false;
|
bool err = false;
|
||||||
flags |= EXPDEF_MASK_PARMCNT & readnum(v + 5, &err);
|
flags |= EXPDEF_MASK_PARMCNT & readnum(v + 5, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
nasm_error(ERR_NONFATAL,
|
nasm_nonfatal("value `%s' for `parm' is non-numeric", v + 5);
|
||||||
"value `%s' for `parm' is non-numeric", v + 5);
|
|
||||||
return DIRR_ERROR;
|
return DIRR_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool err = false;
|
bool err = false;
|
||||||
ordinal = readnum(v, &err);
|
ordinal = readnum(v, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
nasm_error(ERR_NONFATAL,
|
nasm_nonfatal("unrecognised export qualifier `%s'", v);
|
||||||
"unrecognised export qualifier `%s'", v);
|
|
||||||
return DIRR_ERROR;
|
return DIRR_ERROR;
|
||||||
}
|
}
|
||||||
flags |= EXPDEF_FLAG_ORDINAL;
|
flags |= EXPDEF_FLAG_ORDINAL;
|
||||||
@ -2092,7 +2078,7 @@ static void obj_write_file(void)
|
|||||||
/* acbp |= 0x00 */ ;
|
/* acbp |= 0x00 */ ;
|
||||||
else if (seg->align >= 4096) {
|
else if (seg->align >= 4096) {
|
||||||
if (seg->align > 4096)
|
if (seg->align > 4096)
|
||||||
nasm_error(ERR_NONFATAL, "segment `%s' requires more alignment"
|
nasm_nonfatal("segment `%s' requires more alignment"
|
||||||
" than OBJ format supports", seg->name);
|
" than OBJ format supports", seg->name);
|
||||||
acbp |= 0xC0; /* PharLap extension */
|
acbp |= 0xC0; /* PharLap extension */
|
||||||
} else if (seg->align >= 256) {
|
} else if (seg->align >= 256) {
|
||||||
@ -2127,7 +2113,7 @@ static void obj_write_file(void)
|
|||||||
|
|
||||||
if (grp->nindices != grp->nentries) {
|
if (grp->nindices != grp->nentries) {
|
||||||
for (i = grp->nindices; i < grp->nentries; i++) {
|
for (i = grp->nindices; i < grp->nentries; i++) {
|
||||||
nasm_error(ERR_NONFATAL, "group `%s' contains undefined segment"
|
nasm_nonfatal("group `%s' contains undefined segment"
|
||||||
" `%s'", grp->name, grp->segs[i].name);
|
" `%s'", grp->name, grp->segs[i].name);
|
||||||
nasm_free(grp->segs[i].name);
|
nasm_free(grp->segs[i].name);
|
||||||
grp->segs[i].name = NULL;
|
grp->segs[i].name = NULL;
|
||||||
@ -2350,7 +2336,7 @@ static void obj_write_file(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!seg)
|
if (!seg)
|
||||||
nasm_error(ERR_NONFATAL, "entry point is not in this module");
|
nasm_nonfatal("entry point is not in this module");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user