From 9c595b6bb40487da41068bef43e0526a1f07f618 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 7 Mar 2017 19:44:21 -0800 Subject: [PATCH] Fix global variables without declarations Global variables need to be declared in a header file; "extern" in C files should be used extremely rarely (it is OK at least for now for macro tables as they are generally only ever used in one specific location, but otherwise, no.) In a few cases the global variables were actually function-local! Signed-off-by: H. Peter Anvin --- asm/labels.c | 4 ++-- asm/nasm.c | 8 +++----- include/labels.h | 6 +++++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/asm/labels.c b/asm/labels.c index 132b6e00..cf9acdd1 100644 --- a/asm/labels.c +++ b/asm/labels.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2016 The NASM Authors - All Rights Reserved + * Copyright 1996-2017 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -108,7 +108,7 @@ struct permts { /* permanent text storage */ char data[PERMTS_SIZE]; /* ... the data block itself */ }; -extern int64_t global_offset_changed; /* defined in nasm.c */ +uint64_t global_offset_changed; /* counter for global offset changes */ static struct hash_table ltab; /* labels hash table */ static union label *ldata; /* all label data blocks */ diff --git a/asm/nasm.c b/asm/nasm.c index fb5e9541..9e3c2344 100644 --- a/asm/nasm.c +++ b/asm/nasm.c @@ -114,10 +114,6 @@ static int cmd_sb = 16; /* by default */ iflag_t cpu; static iflag_t cmd_cpu; -int64_t global_offset_changed; /* referenced in labels.c */ -int64_t prev_offset_changed; -int32_t stall_count; - struct location location; bool in_absolute; /* Flag we are in ABSOLUTE seg */ struct location absolute; /* Segment/offset inside ABSOLUTE */ @@ -1218,6 +1214,8 @@ static void assemble_file(char *fname, StrList **depend_ptr) int64_t offs; int pass_max; int sb; + uint64_t prev_offset_changed; + unsigned int stall_count = 0; /* Make sure we make forward progress... */ if (cmd_sb == 32 && iflag_ffs(&cmd_cpu) < IF_386) nasm_fatal(0, "command line: 32-bit segment size requires a higher cpu"); @@ -1476,7 +1474,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) if (terminate_after_phase) break; - if ((stall_count > 997) || (passn >= pass_max)) { + if ((stall_count > 997U) || (passn >= pass_max)) { /* We get here if the labels don't converge * Example: FOO equ FOO + 1 */ diff --git a/include/labels.h b/include/labels.h index 4da608e4..5ffdff60 100644 --- a/include/labels.h +++ b/include/labels.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * Copyright 1996-2017 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -38,6 +38,8 @@ #ifndef LABELS_H #define LABELS_H +#include "compiler.h" + extern char lprefix[PREFIX_MAX]; extern char lpostfix[PREFIX_MAX]; @@ -53,4 +55,6 @@ int init_labels(void); void cleanup_labels(void); char *local_scope(char *label); +extern uint64_t global_offset_changed; + #endif /* LABELS_H */ -- 2.11.4.GIT