Merge remote-tracking branch 'github/nasm-2.15.xx' into debug-macros

Resolved Conflicts:
	asm/assemble.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2020-07-09 21:13:50 -07:00
commit e24b7c3504
13 changed files with 170 additions and 45 deletions

View file

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2019 The NASM Authors - All Rights Reserved
* Copyright 1996-2020 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@ -352,8 +352,10 @@ static void debug_macro_out(const struct out_data *data)
*/
static void out(struct out_data *data)
{
static int32_t lineno = 0; /* static!!! */
static const char *lnfname = NULL;
static struct last_debug_info {
struct src_location where;
int32_t segment;
} dbg;
union {
uint8_t b[8];
uint64_t q;
@ -412,15 +414,19 @@ static void out(struct out_data *data)
}
/*
* this call to src_get determines when we call the
* debug-format-specific "linenum" function
* it updates lineno and lnfname to the current values
* returning 0 if "same as last time", -2 if lnfname
* changed, and the amount by which lineno changed,
* if it did. thus, these variables must be static
* If the source location or output segment has changed,
* let the debug backend know. Some backends really don't
* like being given a NULL filename as can happen if we
* use -Lb and expand a macro, so filter out that case.
*/
if (src_get(&lineno, &lnfname) && lnfname)
dfmt->linenum(lnfname, lineno, data->segment);
data->where = src_where();
if (data->where.filename &&
(!src_location_same(data->where, dbg.where) |
(data->segment != dbg.segment))) {
dbg.where = data->where;
dbg.segment = data->segment;
dfmt->linenum(dbg.where.filename, dbg.where.lineno, data->segment);
}
if (asize > amax) {
if (data->type == OUT_RELADDR || (data->flags & OUT_SIGNED)) {

View file

@ -43,6 +43,18 @@ struct src_location {
const char *filename;
int32_t lineno;
};
/*
* Comparing the *pointer value* of filenames is valid, because the
* filename hash system guarantees that each unique filename string is
* permanently allocated in exactly one location.
*/
static inline bool
src_location_same(struct src_location here, struct src_location there)
{
return here.filename == there.filename && here.lineno == there.lineno;
}
struct src_location_stack {
struct src_location l;
struct src_location_stack *up, *down;

View file

@ -1,9 +1,9 @@
dnl --------------------------------------------------------------------------
dnl PA_ADD_CFLAGS(variable, flag [,actual_flag])
dnl PA_ADD_CFLAGS(variable, flag [,actual_flag [,success [,failure]]]])
dnl
dnl Attempt to add the given option to xFLAGS, if it doesn't break
dnl compilation. If the option to be tested is different than the
dnl option that should actually be added, add the option to be
dnl actually added as a second argument.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_ADD_CFLAGS], [PA_ADD_FLAGS(CFLAGS, [$1], [$2])])
AC_DEFUN([PA_ADD_CFLAGS], [PA_ADD_FLAGS(CFLAGS, [$1], [$2], [$3], [$4])])

View file

@ -1,5 +1,5 @@
dnl --------------------------------------------------------------------------
dnl PA_ADD_FLAGS(variable, flag [,actual_flag])
dnl PA_ADD_FLAGS(variable, flag [,actual_flag [,success [,failure]]])
dnl
dnl Attempt to add the given option to CPPFLAGS, if it doesn't break
dnl compilation. If the option to be tested is different than the
@ -15,6 +15,8 @@ AC_DEFUN([PA_ADD_FLAGS],
[AC_MSG_RESULT([yes])
$1="$pa_add_flags__old_flags ifelse([$3],[],[$2],[$3])"
AC_DEFINE(PA_SYM([$1_],[$2]), 1,
[Define to 1 if compiled with the `$2' compiler flag])],
[Define to 1 if compiled with the `$2' compiler flag])
$4],
[AC_MSG_RESULT([no])
$1="$pa_add_flags__old_flags"])])
$1="$pa_add_flags__old_flags"
$5])])

View file

@ -1,9 +1,9 @@
dnl --------------------------------------------------------------------------
dnl PA_ADD_LDFLAGS(variable, flag [,actual_flag])
dnl PA_ADD_LDFLAGS(variable, flag [,actual_flag [,success [,failure]]]])
dnl
dnl Attempt to add the given option to xFLAGS, if it doesn't break
dnl compilation. If the option to be tested is different than the
dnl option that should actually be added, add the option to be
dnl actually added as a second argument.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_ADD_LDFLAGS], [PA_ADD_FLAGS(LDFLAGS, [$1], [$2])])
AC_DEFUN([PA_ADD_LDFLAGS], [PA_ADD_FLAGS(LDFLAGS, [$1], [$2], [$3], [$4])])

View file

@ -7,7 +7,8 @@ dnl --------------------------------------------------------------------------
AC_DEFUN([PA_C_TYPEOF],
[AC_CACHE_CHECK([if $CC supports typeof], [pa_cv_typeof],
[pa_cv_typeof=no
for pa_typeof_try in typeof __typeof__ decltype __decltype__; do
for pa_typeof_try in typeof __typeof __typeof__ decltype __decltype __decltype__
do
AS_IF([test $pa_cv_typeof = no],
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT

View file

@ -0,0 +1,39 @@
dnl --------------------------------------------------------------------------
dnl PA_FUNC_SNPRINTF
dnl
dnl See if we have [_]snprintf(), using the proper prototypes in case
dnl it is a builtin of some kind.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_FUNC_SNPRINTF],
[AC_CACHE_CHECK([for sprintf], [pa_cv_func_snprintf],
[pa_cv_func_snprintf=no
for pa_try_func_snprintf in snprintf _snprintf
do
AS_IF([test $pa_cv_func_snprintf = no],
[AC_LINK_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
const char *snprintf_test(int x);
const char *snprintf_test(int x)
{
static char buf[[256]];
size_t sz;
sz = $pa_try_func_snprintf(buf, sizeof buf, "Hello = %d", x);
return (sz < sizeof buf) ? buf : NULL;
}
int main(void) {
puts(snprintf_test(33));
return 0;
}
])],
[pa_cv_func_snprintf=$pa_try_func_snprintf])])
done
])
AS_IF([test $pa_cv_func_snprintf = no],
[],
[AC_DEFINE([HAVE_SNPRINTF], 1,
[Define to 1 if you have some version of the snprintf function.])
AS_IF([test $pa_cv_func_snprintf = snprintf],
[],
[AC_DEFINE_UNQUOTED([snprintf], [$pa_cv_func_snprintf],
[Define if your snprintf function is not named snprintf.])])])])

View file

@ -0,0 +1,50 @@
dnl --------------------------------------------------------------------------
dnl PA_FUNC_VSNPRINTF
dnl
dnl See if we have [_]vsnprintf(), using the proper prototypes in case
dnl it is a builtin of some kind.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_FUNC_VSNPRINTF],
[AC_CACHE_CHECK([for vsnprintf], [pa_cv_func_vsnprintf],
[pa_cv_func_vsnprintf=no
for pa_try_func_vsnprintf in vsnprintf _vsnprintf
do
AS_IF([test $pa_cv_func_vsnprintf = no],
[AC_LINK_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
const char *vsnprintf_test(const char *fmt, va_list va);
const char *vsnprintf_test(const char *fmt, va_list va)
{
static char buf[[256]];
size_t sz;
sz = $pa_try_func_vsnprintf(buf, sizeof buf, fmt, va);
return (sz < sizeof buf) ? buf : NULL;
}
const char *vsnprintf_caller(const char *fmt, ...);
const char *vsnprintf_caller(const char *fmt, ...)
{
const char *what;
va_list va;
va_start(va, fmt);
what = vsnprintf_test(fmt, va);
va_end(va);
return what;
}
int main(void) {
puts(vsnprintf_caller("Hello = %d", 33));
return 0;
}
])],
[pa_cv_func_vsnprintf=$pa_try_func_vsnprintf])])
done
])
AS_IF([test $pa_cv_func_vsnprintf = no],
[],
[AC_DEFINE([HAVE_VSNPRINTF], 1,
[Define to 1 if you have some version of the vsnprintf function.])
AS_IF([test $pa_cv_func_vsnprintf = vsnprintf],
[],
[AC_DEFINE_UNQUOTED([vsnprintf], [$pa_cv_func_vsnprintf],
[Define if your vsnprintf function is not named vsnprintf.])])])])

View file

@ -23,11 +23,14 @@ export WINELOADER
dnl Get the canonical target system name
AC_CANONICAL_HOST
dnl Checks for programs and enable necessary CC extensions
dnl Enable any available C extensions
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE
AC_PROG_CC
AC_PROG_CC_STDC
PA_ADD_CFLAGS([-std=c17], [], [],
[PA_ADD_CFLAGS([-std=c11], [], [],
[PA_ADD_CFLAGS([-std=c99])])])
dnl If the user did not specify a CFLAGS default, change default
dnl to -O0 for debugging
@ -36,11 +39,6 @@ PA_ARG_DISABLED([optimization],
[pa_no_optimize=true])
dnl Other programs
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_MKDIR_P
pa_no_optimize=false
dnl Compile and link with dwarf debug
@ -65,13 +63,7 @@ PA_ARG_ENABLED([panic-abort],
AH_TEMPLATE(ABORT_ON_PANIC,
[Define to 1 to call abort() on panics (internal errors), for debugging.])
dnl Check for library extension
PA_LIBEXT
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_C_RESTRICT
AC_TYPE_SIZE_T
AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
AH_TEMPLATE(WORDS_BIGENDIAN,
@ -103,10 +95,15 @@ dnl assume all compilers support common, and this will help find those
dnl problems. This also works around an OSX linker problem.
PA_ADD_CFLAGS([-fno-common])
dnl Other C features
PA_C_TYPEOF
dnl Check for library extension
PA_LIBEXT
dnl Look for programs...
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_MKDIR_P
AC_CHECK_PROGS(NROFF, nroff, false)
AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
AC_CHECK_PROGS(XMLTO, xmlto, false)
@ -166,8 +163,21 @@ AC_CHECK_TOOL(AR, ar)
AC_CHECK_TOOL(RANLIB, ranlib, :)
AC_CHECK_TOOL(STRIP, strip)
dnl
dnl NOTE: the tests for header files and library functions use constructs
dnl that create warnings on modern compilers, due to lack of prototypes,
dnl etc. Therefore, do not add the -Werror options before this.
dnl
dnl Tests which may trigger warnings on some compilers
AC_C_CONST
AC_C_INLINE
AC_C_RESTRICT
dnl Checks for header files.
AC_HEADER_STDC
PA_ADD_HEADERS(string.h)
PA_ADD_HEADERS(stdarg.h)
AC_CHECK_HEADERS(inttypes.h)
AC_CHECK_HEADERS(strings.h)
AC_HEADER_STDBOOL
@ -220,9 +230,8 @@ PA_HAVE_FUNC(__builtin_clzll, (0ULL))
PA_HAVE_FUNC(_BitScanReverse, (0))
PA_HAVE_FUNC(_BitScanReverse64, (0))
dnl Functions for which we have replacements available in stdlib/
AC_CHECK_FUNCS([vsnprintf _vsnprintf])
AC_CHECK_FUNCS([snprintf _snprintf])
PA_FUNC_SNPRINTF
PA_FUNC_VSNPRINTF
AC_CHECK_FUNCS([strlcpy])
AC_CHECK_FUNCS([strrchrnul])
@ -388,11 +397,11 @@ PA_ARG_ENABLED([werror],
)
dnl
dnl On some versions of gcc, -Werror=missing-prototypes causes problems
dnl with C99-style external inlines. Test this *after* adding the -Werror
dnl options.
dnl Test compiler features. On some compilers, this can be affected
dnl by -Werror options, so run this *after* those options are added.
dnl
PA_CHECK_BAD_STDC_INLINE
PA_C_TYPEOF
dnl
dnl support ccache

View file

@ -16,9 +16,14 @@ since 2007.
\b Debug information now properly reflect the line numbers of macro
invocations (unless declared \c{.nolist}).
\b Fix alignment of sections in the \c{coff}/\c{win32}/\c{win64}
output formats when the desired alignment is less than the default
alignment for the section or section type.
\b Fix excessive alignment of sections in the
\c{coff}/\c{win32}/\c{win64} output formats when the user-specified
alignment is less than the default alignment for the section or
section type.
\b Fix explicit token pasting (\c{%+}, \k{concat%+}) for the cases
where one or more parts result from empty token expansion, resulting
in \c{%+} tokens at the beginning or end, or multiple ones in a row.
\b Portability fixes.

View file

@ -138,6 +138,7 @@ struct out_data {
int32_t tsegment; /* Target segment for relocation */
int32_t twrt; /* Relocation with respect to */
int64_t relbase; /* Relative base for OUT_RELADDR */
struct src_location where; /* Source file and line */
};
/*

View file

@ -22,8 +22,8 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
int rv, bytes;
if (size > BUFFER_SIZE) {
nasm_panic("vsnprintf: size (%d) > BUFFER_SIZE (%d)",
size, BUFFER_SIZE);
nasm_panic("vsnprintf: size (%llu) > BUFFER_SIZE (%d)",
(unsigned long long)size, BUFFER_SIZE);
size = BUFFER_SIZE;
}

View file

@ -1 +1 @@
2.15.03rc1
2.15.03rc2