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 <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2017-03-07 19:44:21 -08:00
parent e28d5ea5d7
commit 9c595b6bb4
3 changed files with 10 additions and 8 deletions

View File

@ -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 */

View File

@ -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
*/

View File

@ -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 */