all: remove need for -fcommon

Use `extern` where appropriate so that we can remove `-fcommon`
on macOS and others.  On macOS, `-fcommon` generates a number of
linker warnings.

I've tested building on macOS, Linux, FreeBSD, NetBSD, OpenBSD
and illumos.  I am not in a position to test on AIX or other
more esoteric platforms, however.
This commit is contained in:
Dan Cross
2025-07-23 06:47:21 -04:00
parent 1e6e30e91e
commit 156e745be9
39 changed files with 330 additions and 184 deletions

4
bin/9c
View File

@@ -23,7 +23,7 @@ usegcc()
-Wno-deprecated-declarations \
-fno-omit-frame-pointer \
-fsigned-char \
-fcommon \
-fno-common \
-std=gnu11 \
"
# want to put -fno-optimize-sibling-calls here but
@@ -85,7 +85,7 @@ useclang()
-Wno-unused-but-set-variable \
-fsigned-char \
-fno-caret-diagnostics \
-fcommon \
-fno-common \
"
cflags="$cflags -g"
cflags="$cflags $CC9FLAGS"

View File

@@ -15,8 +15,6 @@ Conform *map;
static void addprotofile(char *new, char *old, Dir *d, void *a);
void usage(void);
char *argv0;
void
usage(void)
{

View File

@@ -60,7 +60,6 @@
#endif
int debug;
char *argv0;
char *aname = "";
void fusedispatch(void*);
Channel *fusechan;

View File

@@ -209,19 +209,19 @@ struct Timer
#define Extern extern
#endif
Extern Font *font;
extern Font *font;
Extern Mousectl *mousectl;
Extern Mouse *mouse;
Extern Keyboardctl *keyboardctl;
Extern Display *display;
extern Display *display;
Extern Image *view;
Extern Screen *wscreen;
Extern Cursor boxcursor;
Extern Cursor crosscursor;
Extern Cursor sightcursor;
Extern Cursor whitearrow;
Extern Cursor query;
Extern Cursor *corners[9];
extern Cursor boxcursor;
extern Cursor crosscursor;
extern Cursor sightcursor;
extern Cursor whitearrow;
extern Cursor query;
extern Cursor *corners[9];
Extern Image *background;
Extern Image *lightgrey;
Extern Image *red;

View File

@@ -47,14 +47,14 @@ Extern Node* code;
Extern int na;
Extern int wtflag;
Extern Regs* acidregs;
Extern Regs* correg;
Extern Map* cormap;
Extern Map* symmap;
extern Regs* correg;
extern Map* cormap;
extern Map* symmap;
Extern Lsym* hash[Hashsize];
Extern long dogc;
Extern Rplace* ret;
Extern char* symfil;
Extern char* corfil;
extern char* symfil;
extern char* corfil;
Extern int gotint;
Extern long flen;
Extern Gc* gcl;
@@ -66,8 +66,8 @@ Extern Node* fomt;
Extern List* tracelist;
Extern int initialising;
Extern int quiet;
Extern Fhdr* corhdr;
Extern Fhdr* symhdr;
extern Fhdr* corhdr;
extern Fhdr* symhdr;
extern void (*expop[])(Node*, Node*);
#define expr(n, r) (r)->store.comt=0; (*expop[(unsigned char)((n)->op)])(n, r);

62
src/cmd/acme/dat.c Normal file
View File

@@ -0,0 +1,62 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <thread.h>
#include <cursor.h>
#include <mouse.h>
#include <keyboard.h>
#include <frame.h>
#include <fcall.h>
#include <plumb.h>
#include <libsec.h>
#include "dat.h"
uint globalincref;
uint seq;
uint maxtab; /* size of a tab, in units of the '0' character */
Mouse *mouse;
Mousectl *mousectl;
Keyboardctl *keyboardctl;
Reffont reffont;
Image *modbutton;
Image *colbutton;
Image *button;
Image *but2col;
Image *but3col;
Row row;
int timerpid;
Disk *disk;
Text *seltext;
Text *argtext;
Text *mousetext; /* global because Text.close needs to clear it */
Text *typetext; /* global because Text.close needs to clear it */
Text *barttext; /* shared between mousetask and keyboardthread */
int bartflag;
Window *activewin;
Column *activecol;
Rectangle nullrect;
int fsyspid;
char *cputype;
char *objtype;
char *acmeshell;
//char *fontnames[2];
extern char wdir[]; /* must use extern because no dimension given */
int globalautoindent;
int dodollarsigns;
Channel *cplumb; /* chan(Plumbmsg*) */
Channel *cwait; /* chan(Waitmsg) */
Channel *ccommand; /* chan(Command*) */
Channel *ckill; /* chan(Rune*) */
Channel *cxfidalloc; /* chan(Xfid*) */
Channel *cxfidfree; /* chan(Xfid*) */
Channel *cnewwindow; /* chan(Channel*) */
Channel *mouseexit0; /* chan(int) */
Channel *mouseexit1; /* chan(int) */
Channel *cexit; /* chan(int) */
Channel *cerr; /* chan(char*) */
Channel *cedit; /* chan(int) */
Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */
QLock editoutlk;

View File

@@ -509,53 +509,53 @@ enum /* editing */
Collecting
};
uint globalincref;
uint seq;
uint maxtab; /* size of a tab, in units of the '0' character */
extern uint globalincref;
extern uint seq;
extern uint maxtab; /* size of a tab, in units of the '0' character */
Display *display;
Image *screen;
Font *font;
Mouse *mouse;
Mousectl *mousectl;
Keyboardctl *keyboardctl;
Reffont reffont;
Image *modbutton;
Image *colbutton;
Image *button;
Image *but2col;
Image *but3col;
Cursor boxcursor;
Cursor2 boxcursor2;
Row row;
int timerpid;
Disk *disk;
Text *seltext;
Text *argtext;
Text *mousetext; /* global because Text.close needs to clear it */
Text *typetext; /* global because Text.close needs to clear it */
Text *barttext; /* shared between mousetask and keyboardthread */
int bartflag;
int swapscrollbuttons;
Window *activewin;
Column *activecol;
Buffer snarfbuf;
Rectangle nullrect;
int fsyspid;
char *cputype;
char *objtype;
char *home;
char *acmeshell;
char *fontnames[2];
Image *tagcols[NCOL];
Image *textcols[NCOL];
extern Display *display;
extern Image *screen;
extern Font *font;
extern Mouse *mouse;
extern Mousectl *mousectl;
extern Keyboardctl *keyboardctl;
extern Reffont reffont;
extern Image *modbutton;
extern Image *colbutton;
extern Image *button;
extern Image *but2col;
extern Image *but3col;
extern Cursor boxcursor;
extern Cursor2 boxcursor2;
extern Row row;
extern int timerpid;
extern Disk *disk;
extern Text *seltext;
extern Text *argtext;
extern Text *mousetext; /* global because Text.close needs to clear it */
extern Text *typetext; /* global because Text.close needs to clear it */
extern Text *barttext; /* shared between mousetask and keyboardthread */
extern int bartflag;
extern int swapscrollbuttons;
extern Window *activewin;
extern Column *activecol;
extern Buffer snarfbuf;
extern Rectangle nullrect;
extern int fsyspid;
extern char *cputype;
extern char *objtype;
extern char *home;
extern char *acmeshell;
extern char *fontnames[2];
extern Image *tagcols[NCOL];
extern Image *textcols[NCOL];
extern char wdir[]; /* must use extern because no dimension given */
int editing;
int erroutfd;
int messagesize; /* negotiated in 9P version setup */
int globalautoindent;
int dodollarsigns;
char* mtpt;
extern int editing;
extern int erroutfd;
extern int messagesize; /* negotiated in 9P version setup */
extern int globalautoindent;
extern int dodollarsigns;
extern char* mtpt;
enum
{
@@ -563,20 +563,20 @@ enum
Kscrollonedown = KF|0x21
};
Channel *cplumb; /* chan(Plumbmsg*) */
Channel *cwait; /* chan(Waitmsg) */
Channel *ccommand; /* chan(Command*) */
Channel *ckill; /* chan(Rune*) */
Channel *cxfidalloc; /* chan(Xfid*) */
Channel *cxfidfree; /* chan(Xfid*) */
Channel *cnewwindow; /* chan(Channel*) */
Channel *mouseexit0; /* chan(int) */
Channel *mouseexit1; /* chan(int) */
Channel *cexit; /* chan(int) */
Channel *cerr; /* chan(char*) */
Channel *cedit; /* chan(int) */
Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */
extern Channel *cplumb; /* chan(Plumbmsg*) */
extern Channel *cwait; /* chan(Waitmsg) */
extern Channel *ccommand; /* chan(Command*) */
extern Channel *ckill; /* chan(Rune*) */
extern Channel *cxfidalloc; /* chan(Xfid*) */
extern Channel *cxfidfree; /* chan(Xfid*) */
extern Channel *cnewwindow; /* chan(Channel*) */
extern Channel *mouseexit0; /* chan(int) */
extern Channel *mouseexit1; /* chan(int) */
extern Channel *cexit; /* chan(int) */
extern Channel *cerr; /* chan(char*) */
extern Channel *cedit; /* chan(int) */
extern Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */
QLock editoutlk;
extern QLock editoutlk;
#define STACK 65536

View File

@@ -19,7 +19,7 @@ char Enoname[] = "no file name given";
Address addr;
File *menu;
Rangeset sel;
extern Rangeset sel;
extern Text* curtext;
Rune *collection;
int ncollection;

View File

@@ -18,7 +18,7 @@ char *srvname;
Window *wbox;
Message mbox;
Message replies;
char *home;
extern char *home;
CFid *plumbsendfd;
CFid *plumbseemailfd;
CFid *plumbshowmailfd;

View File

@@ -25,6 +25,7 @@ OFILES=\
util.$O\
wind.$O\
xfid.$O\
dat.$O\
HFILES=dat.h\
edit.h\

View File

@@ -85,55 +85,55 @@ struct Tim
char tz[4];
};
double converge;
extern double converge;
char flags[128];
int nperiods;
double wlong, awlong, nlat, elev;
double obliq, phi, eps, tobliq;
double dphi, deps;
double day, deld, per;
double eday, capt, capt2, capt3, gst;
double pi, pipi, radian, radsec, deltat;
double erad, glat;
double xms, yms, zms;
double xdot, ydot, zdot;
extern char flags[128];
extern int nperiods;
extern double wlong, awlong, nlat, elev;
extern double obliq, phi, eps, tobliq;
extern double dphi, deps;
extern double day, deld, per;
extern double eday, capt, capt2, capt3, gst;
extern double pi, pipi, radian, radsec, deltat;
extern double erad, glat;
extern double xms, yms, zms;
extern double xdot, ydot, zdot;
double ecc, incl, node, argp, mrad, anom, motion;
extern double ecc, incl, node, argp, mrad, anom, motion;
double lambda, beta, rad, mag, semi;
double alpha, delta, rp, hp;
double ra, decl, semi2;
double lha, decl2, lmb2;
double az, el;
extern double lambda, beta, rad, mag, semi;
extern double alpha, delta, rp, hp;
extern double ra, decl, semi2;
extern double lha, decl2, lmb2;
extern double az, el;
double meday, seday, mhp, salph, sdelt, srad;
extern double meday, seday, mhp, salph, sdelt, srad;
double* cafp;
char* cacp;
extern double* cafp;
extern char* cacp;
double rah, ram, ras, dday, dmin, dsec;
long sao;
double da, dd, px, epoch;
char line[100];
Obj2 osun;
Obj2 omoon;
Obj2 oshad;
Obj2 omerc;
Obj2 ovenus;
Obj2 omars;
Obj2 osat;
Obj2 ouran;
Obj2 onept;
Obj2 oplut;
Obj2 ojup;
Obj2 ostar;
Obj2 ocomet;
Obj3 occ;
Obj2* eobj1;
Obj2* eobj2;
extern double rah, ram, ras, dday, dmin, dsec;
extern long sao;
extern double da, dd, px, epoch;
extern char line[100];
extern Obj2 osun;
extern Obj2 omoon;
extern Obj2 oshad;
extern Obj2 omerc;
extern Obj2 ovenus;
extern Obj2 omars;
extern Obj2 osat;
extern Obj2 ouran;
extern Obj2 onept;
extern Obj2 oplut;
extern Obj2 ojup;
extern Obj2 ostar;
extern Obj2 ocomet;
extern Obj3 occ;
extern Obj2* eobj1;
extern Obj2* eobj2;
char* startab;
extern char* startab;
extern int dmo[];
extern Obj2* objlst[];

View File

@@ -1,5 +1,53 @@
#include "astro.h"
double converge;
char flags[128];
int nperiods;
double wlong, awlong, nlat, elev;
double obliq, phi, eps, tobliq;
double dphi, deps;
double day, deld, per;
double eday, capt, capt2, capt3, gst;
double pi, pipi, radian, radsec, deltat;
double erad, glat;
double xms, yms, zms;
double xdot, ydot, zdot;
double ecc, incl, node, argp, mrad, anom, motion;
double lambda, beta, rad, mag, semi;
double alpha, delta, rp, hp;
double ra, decl, semi2;
double lha, decl2, lmb2;
double az, el;
double meday, seday, mhp, salph, sdelt, srad;
double* cafp;
char* cacp;
double rah, ram, ras, dday, dmin, dsec;
long sao;
double da, dd, px, epoch;
char line[100];
Obj2 osun;
Obj2 omoon;
Obj2 oshad;
Obj2 omerc;
Obj2 ovenus;
Obj2 omars;
Obj2 osat;
Obj2 ouran;
Obj2 onept;
Obj2 oplut;
Obj2 ojup;
Obj2 ostar;
Obj2 ocomet;
Obj3 occ;
Obj2* eobj1;
Obj2* eobj2;
char* herefile;
int

View File

@@ -4,12 +4,12 @@
#include "defs.h"
#include "fns.h"
char *symfil;
char *corfil;
extern char *symfil;
extern char *corfil;
Map *symmap;
Map *cormap;
Regs *correg;
extern Map *symmap;
extern Map *cormap;
extern Regs *correg;
Map *dotmap;
void

View File

@@ -1,10 +1,10 @@
#define stdout bstdout
char mode; /* '\0', 'e', 'f', 'h' */
char bflag; /* ignore multiple and trailing blanks */
char rflag; /* recurse down directory trees */
char mflag; /* pseudo flag: doing multiple files, one dir */
int anychange;
extern char mode; /* '\0', 'e', 'f', 'h' */
extern char bflag; /* ignore multiple and trailing blanks */
extern char rflag; /* recurse down directory trees */
extern char mflag; /* pseudo flag: doing multiple files, one dir */
extern int anychange;
extern Biobuf stdout;
extern int binary;

View File

@@ -8,6 +8,12 @@
Biobuf stdout;
char mode; /* '\0', 'e', 'f', 'h' */
char bflag; /* ignore multiple and trailing blanks */
char rflag; /* recurse down directory trees */
char mflag; /* pseudo flag: doing multiple files, one dir */
int anychange;
static char *tmp[] = {"/tmp/diff1XXXXXXXXXXX", "/tmp/diff2XXXXXXXXXXX"};
static int whichtmp;
static char *progname;

View File

@@ -1,6 +1,6 @@
typedef struct XFont XFont;
XFont *xfont;
int nxfont;
extern XFont *xfont;
extern int nxfont;
enum {
SubfontSize = 32,

View File

@@ -13,6 +13,9 @@
#include "a.h"
XFont *xfont;
int nxfont;
void
usage(void)
{

View File

@@ -22,7 +22,7 @@ struct Fsys {
Fsys* next;
};
int mempcnt; /* from fossil.c */
extern int mempcnt; /* from fossil.c */
int fsGetBlockSize(Fs *fs);

View File

@@ -15,7 +15,7 @@ Inst *progp; /* next free spot for code generation */
Inst *pc; /* program counter during execution */
Inst *progbase = prog; /* start of current subprogram */
int returning; /* 1 if return stmt seen */
int indef; /* 1 if parsing a func or proc */
extern int indef; /* 1 if parsing a func or proc */
typedef struct Frame { /* proc/func call stack frame */
Symbol *sp; /* symbol table entry */

View File

@@ -30,7 +30,9 @@ enum
ArgMode = 1<<3,
HtmlMode = 1<<4,
MaxLine = 1024
MaxLine = 1024,
MAXIF = 20
};
Rune* L(char*);
@@ -77,7 +79,7 @@ int linefmt(Fmt*);
void nr(Rune*, int);
void _nr(Rune*, Rune*);
void out(Rune*);
void (*outcb)(Rune);
extern void (*outcb)(Rune);
void outhtml(Rune*);
void outrune(Rune);
void outtrap(void);

View File

@@ -6,7 +6,6 @@ enum
MAXRAW = 40,
MAXESC = 60,
MAXLINE = 1024,
MAXIF = 20,
MAXARG = 10
};

View File

@@ -16,9 +16,8 @@
* .if .ie .el
*
*/
int iftrue[20];
int niftrue;
extern int iftrue[MAXIF];
extern int niftrue;
void
startbody(void)

View File

@@ -101,7 +101,8 @@ char *udpaddr = "udp!*!domain";
char *logfile = "dns";
char *dbfile;
char mntpt[Maxpath];
char *LOG;
extern char *LOG;
void
usage(void)

View File

@@ -23,11 +23,12 @@ char mntpt[Maxpath];
ulong now;
int maxage;
uchar ipaddr[IPaddrlen]; /* my ip address */
char *LOG;
char *zonerefreshprogram;
char *tcpaddr;
char *udpaddr;
extern char *LOG;
void
usage(void)
{

View File

@@ -7,10 +7,11 @@
#include "plumber.h"
int debug;
int nports;
char **ports;
int foreground=0;
char *plumbfile;
char *user;
char *home;
char *progname;
Ruleset **rules;
int printerrors=1;

View File

@@ -89,11 +89,11 @@ void makeports(Ruleset*[]);
void printinputstack(void);
int popinput(void);
Ruleset **rules;
char *user;
char *home;
jmp_buf parsejmp;
char *lasterror;
char **ports;
int nports;
int debug;
extern Ruleset **rules;
extern char *user;
extern char *home;
extern jmp_buf parsejmp;
extern char *lasterror;
extern char **ports;
extern int nports;
extern int debug;

View File

@@ -8,6 +8,24 @@
*/
char *argv0="rc";
thread *runq;
code *codebuf; /* compiler output */
int ntrap; /* number of outstanding traps */
int trap[NSIG]; /* number of outstanding traps per type */
int eflagok; /* kludge flag so that -e doesn't exit in startup */
tree *cmdtree;
char *promptstr;
char tok[NTOK];
var *gvar[NVAR]; /* hash for globals */
int mypid;
char **argp;
char **args;
int nerror; /* number of errors encountered during compilation */
int ndot;
int lastc;
int kidpid;
io *err;
void
start(code *c, int pc, var *local)
{

View File

@@ -56,17 +56,17 @@ struct thread{
tree *treenodes; /* tree nodes created by this process */
thread *ret; /* who continues when this finishes */
};
thread *runq;
extern thread *runq;
code *codecopy(code*);
code *codebuf; /* compiler output */
int ntrap; /* number of outstanding traps */
int trap[NSIG]; /* number of outstanding traps per type */
extern code *codebuf; /* compiler output */
extern int ntrap; /* number of outstanding traps */
extern int trap[NSIG]; /* number of outstanding traps per type */
struct builtin{
char *name;
void (*fnc)(void);
};
extern struct builtin Builtin[];
int eflagok; /* kludge flag so that -e doesn't exit in startup */
extern int eflagok; /* kludge flag so that -e doesn't exit in startup */
extern int havefork;
void execcd(void), execwhatis(void), execeval(void), execexec(void);

View File

@@ -10,7 +10,7 @@ struct io{
int fd;
char *bufp, *ebuf, *strp, buf[NBUF];
};
io *err;
extern io *err;
io *openfd(int), *openstr(void), *opencore(char *, int);
int emptybuf(io*);
void pchr(io*, int);

View File

@@ -65,7 +65,7 @@ tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*);
tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*);
tree *simplemung(tree*), *heredoc(tree*);
void freetree(tree*);
tree *cmdtree;
extern tree *cmdtree;
/*
* The first word of any code vector is a reference count.
* Always create a new reference to a code vector by calling codecopy(.).
@@ -76,9 +76,9 @@ union code{
int i;
char *s;
};
char *promptstr;
extern char *promptstr;
#define NTOK 8192
char tok[NTOK];
extern char tok[NTOK];
#define APPEND 1
#define WRITE 2
#define READ 3
@@ -98,7 +98,7 @@ struct var{
};
var *vlook(char*), *gvlook(char*), *newvar(char*, var*);
#define NVAR 521
var *gvar[NVAR]; /* hash for globals */
extern var *gvar[NVAR]; /* hash for globals */
#define new(type) ((type *)emalloc(sizeof(type)))
char *emalloc(long);
void *Malloc(ulong);
@@ -109,7 +109,7 @@ struct here{
char *name;
struct here *next;
};
int mypid;
extern int mypid;
/*
* Glob character escape in strings:
* In a string, GLOB must be followed by *?[ or GLOB.
@@ -128,9 +128,9 @@ int mypid;
#define threebyte(c) ((c&0xf0)==0xe0)
#define fourbyte(c) ((c&0xf8)==0xf0)
char **argp;
char **args;
int nerror; /* number of errors encountered during compilation */
extern char **argp;
extern char **args;
extern int nerror; /* number of errors encountered during compilation */
extern int doprompt; /* is it time for a prompt? */
/*
* Which fds are the reading/writing end of a pipe?
@@ -146,8 +146,8 @@ extern char *Rcmain(), Fdprefix[];
* How many dot commands have we executed?
* Used to ensure that -v flag doesn't print rcmain.
*/
int ndot;
extern int ndot;
char *getstatus(void);
int lastc;
int lastword;
int kidpid;
extern int lastc;
extern int lastword;
extern int kidpid;

View File

@@ -33,7 +33,7 @@ int onwin;
int rows, cols;
int sortlabels;
int showwmnames;
Font *font;
extern Font *font;
Image *lightblue;

View File

@@ -20,7 +20,7 @@ int downloaded;
int dflag;
int Rflag;
char *machine;
char *home;
extern char *home;
int bpipeok;
int termlocked;
char *samterm = SAMTERM;

View File

@@ -5,7 +5,6 @@
static void dodecode(Biobuf*, Pix*, int, int, uchar*);
static int32 getlong(uchar*);
int debug;
Img*
dssread(char *file)

View File

@@ -34,6 +34,11 @@ Record *rec;
Record *orec;
Record *cur;
int nplate;
Plate plate[2000]; /* needs to go to 2000 when the north comes */
int debug;
Gam gam;
char *dir;
int saodb;
int ngcdb;

View File

@@ -303,13 +303,14 @@ struct Img
#define ARCSECONDS_PER_RADIAN (DEG(1)*3600)
#define MILLIARCSEC (1000*60*60)
int nplate;
Plate plate[2000]; /* needs to go to 2000 when the north comes */
double PI_180;
double TWOPI;
double LN2;
int debug;
struct
extern int nplate;
extern Plate plate[2000]; /* needs to go to 2000 when the north comes */
extern double PI_180;
extern double TWOPI;
extern double LN2;
extern int debug;
typedef struct Gam Gam;
struct Gam
{
float min;
float max;
@@ -318,7 +319,8 @@ struct
float mult1;
float mult2;
int neg;
} gam;
};
extern Gam gam;
typedef struct Picture Picture;
struct Picture

View File

@@ -28,7 +28,6 @@ int clean = 0;
int verbose = 0;
long ninput, noutput, nrunes, nerrors;
char *file = "stdin";
char *argv0;
Rune runes[N];
char obuf[UTFmax*N]; /* maximum bloat from N runes */
long tab[NRUNE];

View File

@@ -17,6 +17,7 @@
#include "fns.h"
u32int maxblocksize;
#pragma weak readonly
int readonly;
int findsubpart(Part *part, char *name);

View File

@@ -1,5 +1,6 @@
#include <lib9.h>
#pragma weak argv0
char *argv0;
/*

View File

@@ -690,6 +690,7 @@ threadrwakeup(Rendez *r, int all, ulong pc)
static int threadargc;
static char **threadargv;
#pragma weak mainstacksize
int mainstacksize;
extern int _p9usepwlibrary; /* getgrgid etc. smash the stack - tell _p9dir just say no */
static void