mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-07-24 10:25:42 -04:00
Remove the --allow-64-bits option and make it a warning
Remove the --allow-64-bits relocation, and instead make it a suppressible warning in the case of a zero-extended relocation, and an error in the case of a sign-extended relocation. Relocations which can be losslessly represented in the output format do not issue any diagnostic at all, as there is no problem in that case. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
0c11e123b2
commit
d24dd5fecc
29
assemble.c
29
assemble.c
@ -1,6 +1,6 @@
|
|||||||
/* ----------------------------------------------------------------------- *
|
/* ----------------------------------------------------------------------- *
|
||||||
*
|
*
|
||||||
* Copyright 1996-2014 The NASM Authors - All Rights Reserved
|
* Copyright 1996-2016 The NASM Authors - All Rights Reserved
|
||||||
* See the file AUTHORS included with the NASM distribution for
|
* See the file AUTHORS included with the NASM distribution for
|
||||||
* the specific copyright holders.
|
* the specific copyright holders.
|
||||||
*
|
*
|
||||||
@ -308,7 +308,8 @@ static void warn_overflow_opd(const struct operand *o, int size)
|
|||||||
/*
|
/*
|
||||||
* This routine wrappers the real output format's output routine,
|
* This routine wrappers the real output format's output routine,
|
||||||
* in order to pass a copy of the data off to the listing file
|
* in order to pass a copy of the data off to the listing file
|
||||||
* generator at the same time.
|
* generator at the same time, flatten unnecessary relocations,
|
||||||
|
* and verify backend compatibility.
|
||||||
*/
|
*/
|
||||||
static void out(int64_t offset, int32_t segto, const void *data,
|
static void out(int64_t offset, int32_t segto, const void *data,
|
||||||
enum out_type type, uint64_t size,
|
enum out_type type, uint64_t size,
|
||||||
@ -317,6 +318,9 @@ static void out(int64_t offset, int32_t segto, const void *data,
|
|||||||
static int32_t lineno = 0; /* static!!! */
|
static int32_t lineno = 0; /* static!!! */
|
||||||
static char *lnfname = NULL;
|
static char *lnfname = NULL;
|
||||||
uint8_t p[8];
|
uint8_t p[8];
|
||||||
|
const int asize = abs((int)size); /* True address size */
|
||||||
|
const int abits = asize << 3; /* Address size in bits */
|
||||||
|
const int amax = maxbits >> 3; /* Maximum address size in bytes */
|
||||||
|
|
||||||
if (type == OUT_ADDRESS && segment == NO_SEG && wrt == NO_SEG) {
|
if (type == OUT_ADDRESS && segment == NO_SEG && wrt == NO_SEG) {
|
||||||
/*
|
/*
|
||||||
@ -325,13 +329,12 @@ static void out(int64_t offset, int32_t segto, const void *data,
|
|||||||
*/
|
*/
|
||||||
uint8_t *q = p;
|
uint8_t *q = p;
|
||||||
|
|
||||||
size = abs((int)size);
|
if (asize > 8) {
|
||||||
if (size > 8) {
|
|
||||||
errfunc(ERR_PANIC, "OUT_ADDRESS with size > 8");
|
errfunc(ERR_PANIC, "OUT_ADDRESS with size > 8");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITEADDR(q, *(int64_t *)data, size);
|
WRITEADDR(q, *(int64_t *)data, asize);
|
||||||
data = p;
|
data = p;
|
||||||
type = OUT_RAWDATA;
|
type = OUT_RAWDATA;
|
||||||
}
|
}
|
||||||
@ -350,6 +353,22 @@ static void out(int64_t offset, int32_t segto, const void *data,
|
|||||||
if (src_get(&lineno, &lnfname))
|
if (src_get(&lineno, &lnfname))
|
||||||
outfmt->current_dfmt->linenum(lnfname, lineno, segto);
|
outfmt->current_dfmt->linenum(lnfname, lineno, segto);
|
||||||
|
|
||||||
|
if (type == OUT_ADDRESS && abits > maxbits) {
|
||||||
|
if (asize < 0) {
|
||||||
|
errfunc(ERR_NONFATAL,
|
||||||
|
"%d-bit signed relocation unsupported by output format %s\n",
|
||||||
|
abits, outfmt->shortname);
|
||||||
|
} else {
|
||||||
|
errfunc(ERR_WARNING | ERR_WARN_ZEXTRELOC,
|
||||||
|
"%d-bit unsigned relocation zeroq-padded from %d bits\n",
|
||||||
|
abits, maxbits);
|
||||||
|
outfmt->output(segto, data, type, amax, segment, wrt);
|
||||||
|
size -= amax;
|
||||||
|
}
|
||||||
|
data = zero_buffer;
|
||||||
|
type = OUT_RAWDATA;
|
||||||
|
}
|
||||||
|
|
||||||
outfmt->output(segto, data, type, size, segment, wrt);
|
outfmt->output(segto, data, type, size, segment, wrt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1010,16 +1010,6 @@ underscore to all global and external variables, as C requires it in
|
|||||||
some, but not all, system calling conventions.
|
some, but not all, system calling conventions.
|
||||||
|
|
||||||
|
|
||||||
\S{opt-allow64bit} The \i\c{--allow-64-bit} Option.
|
|
||||||
|
|
||||||
The \c{--allow-64-bit} option allows using 64-bit instructions in a
|
|
||||||
32-bit or 16-bit output format. This is useful in a few situations,
|
|
||||||
such as when writing code switching from 32-bit to 64-bit mode and
|
|
||||||
linking into a 32-bit module. However, it is important to be aware of
|
|
||||||
the restriction the output format poses on you in terms of
|
|
||||||
relocations. Use with caution!
|
|
||||||
|
|
||||||
|
|
||||||
\S{nasmenv} The \i\c{NASMENV} \i{Environment} Variable
|
\S{nasmenv} The \i\c{NASMENV} \i{Environment} Variable
|
||||||
|
|
||||||
If you define an environment variable called \c{NASMENV}, the program
|
If you define an environment variable called \c{NASMENV}, the program
|
||||||
|
14
nasm.c
14
nasm.c
@ -88,7 +88,6 @@ static int using_debug_info, opt_verbose_info;
|
|||||||
bool tasm_compatible_mode = false;
|
bool tasm_compatible_mode = false;
|
||||||
int pass0, passn;
|
int pass0, passn;
|
||||||
int maxbits = 0;
|
int maxbits = 0;
|
||||||
static bool allow_64_bit = false;
|
|
||||||
int globalrel = 0;
|
int globalrel = 0;
|
||||||
int globalbnd = 0;
|
int globalbnd = 0;
|
||||||
|
|
||||||
@ -169,6 +168,7 @@ static const struct warning {
|
|||||||
{"lock", "lock prefix on unlockable instructions", true},
|
{"lock", "lock prefix on unlockable instructions", true},
|
||||||
{"hle", "invalid hle prefixes", true},
|
{"hle", "invalid hle prefixes", true},
|
||||||
{"bnd", "invalid bnd prefixes", true},
|
{"bnd", "invalid bnd prefixes", true},
|
||||||
|
{"zero-reloc", "relocation zero-extended to match output format", true},
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool want_usage;
|
static bool want_usage;
|
||||||
@ -618,12 +618,10 @@ struct textargs {
|
|||||||
enum text_options {
|
enum text_options {
|
||||||
OPT_PREFIX,
|
OPT_PREFIX,
|
||||||
OPT_POSTFIX,
|
OPT_POSTFIX,
|
||||||
OPT_ALLOW_64_BIT
|
|
||||||
};
|
};
|
||||||
struct textargs textopts[] = {
|
struct textargs textopts[] = {
|
||||||
{"prefix", OPT_PREFIX},
|
{"prefix", OPT_PREFIX},
|
||||||
{"postfix", OPT_POSTFIX},
|
{"postfix", OPT_POSTFIX},
|
||||||
{"allow-64-bit", OPT_ALLOW_64_BIT},
|
|
||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -981,9 +979,7 @@ set_warning:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OPT_ALLOW_64_BIT:
|
|
||||||
allow_64_bit = true;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
|
nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
|
||||||
@ -2101,12 +2097,6 @@ static int get_bits(char *value)
|
|||||||
"cannot specify 64-bit segment on processor below an x86-64");
|
"cannot specify 64-bit segment on processor below an x86-64");
|
||||||
i = 16;
|
i = 16;
|
||||||
}
|
}
|
||||||
if (i != maxbits && !allow_64_bit) {
|
|
||||||
nasm_error(ERR_NONFATAL,
|
|
||||||
"%s output format does not support 64-bit code",
|
|
||||||
ofmt->shortname);
|
|
||||||
i = 16;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
nasm_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL,
|
nasm_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL,
|
||||||
"`%s' is not a valid segment size; must be 16, 32 or 64",
|
"`%s' is not a valid segment size; must be 16, 32 or 64",
|
||||||
|
2
nasm.h
2
nasm.h
@ -1,6 +1,6 @@
|
|||||||
/* ----------------------------------------------------------------------- *
|
/* ----------------------------------------------------------------------- *
|
||||||
*
|
*
|
||||||
* Copyright 1996-2014 The NASM Authors - All Rights Reserved
|
* Copyright 1996-2016 The NASM Authors - All Rights Reserved
|
||||||
* See the file AUTHORS included with the NASM distribution for
|
* See the file AUTHORS included with the NASM distribution for
|
||||||
* the specific copyright holders.
|
* the specific copyright holders.
|
||||||
*
|
*
|
||||||
|
@ -125,7 +125,8 @@ no_return nasm_panic_from_macro(const char *file, int line);
|
|||||||
#define ERR_WARN_LOCK WARN(12) /* bad LOCK prefixes */
|
#define ERR_WARN_LOCK WARN(12) /* bad LOCK prefixes */
|
||||||
#define ERR_WARN_HLE WARN(13) /* bad HLE prefixes */
|
#define ERR_WARN_HLE WARN(13) /* bad HLE prefixes */
|
||||||
#define ERR_WARN_BND WARN(14) /* bad BND prefixes */
|
#define ERR_WARN_BND WARN(14) /* bad BND prefixes */
|
||||||
#define ERR_WARN_MAX 14 /* the highest numbered one */
|
#define ERR_WARN_ZEXTRELOC WARN(15) /* relocation zero-extended */
|
||||||
|
#define ERR_WARN_MAX 15 /* the highest numbered one */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wrappers around malloc, realloc and free. nasm_malloc will
|
* Wrappers around malloc, realloc and free. nasm_malloc will
|
||||||
|
Loading…
x
Reference in New Issue
Block a user