ref: 263d99100408f467fbe6a06dad26e11789c9d603
parent: cca317cd8fc13ca96666ab889680cec67b9efd98
parent: 2c7a34994ed9fcb63465f8e86de7b70b3a48f6f5
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Feb 10 13:27:57 EST 2019
Merge branch 'master' of ssh://simple-cc.org:/var/gitrepos/scc
--- a/doc/scc.1
+++ b/doc/scc.1
@@ -3,7 +3,7 @@
scc \- simple C compiler with magic
.SH SYNOPSIS
.B scc
-.RB [ \-cdgkqQsw ]
+.RB [ \-cdgkqQsWw ]
.RB [ \-M | \-E | \-S ]
.RB [ \-D
.IR def[=val] ] ...
@@ -23,8 +23,6 @@
.IR level ]
.RB [ \-t
.IR sys ]
-.RB [ \-W
-.IR warn ]
.RB sourcefile ...
.SH DESCRIPTION
.B scc
@@ -117,12 +115,11 @@
.I define
by the -D parameter.
.TP
-.B \-w
-Do show warning messages.
+.B \-W
+Show warning messages.
.TP
-.BI \-W " warnings"
-This option only activates -w and is otherwise ignored for compatibility
-reasons.
+.B \-w
+Do not show warning messages (default).
.SH ENVIRONMENT VARIABLES
Certain environment variables control the behaviour of scc.
.TP
--- a/include/scc/scc/scc.h
+++ b/include/scc/scc/scc.h
@@ -39,3 +39,4 @@
extern int lunpack(unsigned char *src, char *fmt, ...);
extern int bpack(unsigned char *dst, char *fmt, ...);
extern int bunpack(unsigned char *src, char *fmt, ...);
+extern unsigned genhash(char *name);
--- a/src/cmd/Makefile
+++ b/src/cmd/Makefile
@@ -12,36 +12,36 @@
$(BINDIR)/objcopy \
$(BINDIR)/addr2line \
-LIBS = -lmach
DIRS = as ld scc
+LIBMACH = $(LIBDIR)/libmach.a
+LIBSCC = $(LIBDIR)/libscc.a
+
all: $(TARGET) $(DIRS)
$(DIRS): FORCE
@+cd $@ && $(MAKE)
-$(TARGET): $(LIBDIR)/libmach.a
+$(BINDIR)/nm: nm.o $(LIBMACH) $(LIBSCC)
+ $(CC) $(SCC_LDFLAGS) nm.o -lmach -lscc -o $@
-$(BINDIR)/nm: nm.o
- $(CC) $(SCC_LDFLAGS) nm.o -lmach -o $@
+$(BINDIR)/strip: strip.o $(LIBMACH) $(LIBSCC)
+ $(CC) $(SCC_LDFLAGS) strip.o -lmach -lscc -o $@
-$(BINDIR)/strip: strip.o
- $(CC) $(SCC_LDFLAGS) strip.o -lmach -o $@
+$(BINDIR)/size: size.o $(LIBMACH) $(LIBSCC)
+ $(CC) $(SCC_LDFLAGS) size.o -lmach -lscc -o $@
-$(BINDIR)/size: size.o
- $(CC) $(SCC_LDFLAGS) size.o -lmach -o $@
+$(BINDIR)/ranlib: ranlib.o $(DRIVER).o $(LIBMACH) $(LIBSCC)
+ $(CC) $(SCC_LDFLAGS) ranlib.o $(DRIVER).o -lmach -lscc -o $@
-$(BINDIR)/ranlib: ranlib.o $(DRIVER).o
- $(CC) $(SCC_LDFLAGS) ranlib.o $(DRIVER).o -lmach -o $@
-
-$(BINDIR)/objdump: objdump.o
+$(BINDIR)/objdump: objdump.o $(LIBMACH)
$(CC) $(SCC_LDFLAGS) objdump.o -lmach -o $@
-$(BINDIR)/objcopy: objcopy.o
+$(BINDIR)/objcopy: objcopy.o $(LIBMACH)
$(CC) $(SCC_LDFLAGS) objcopy.o -lmach -o $@
-$(BINDIR)/addr2line: addr2line.o
- $(CC) $(SCC_LDFLAGS) addr2line.o -lmach -o $@
+$(BINDIR)/addr2line: addr2line.o $(LIBMACH) $(LIBSCC)
+ $(CC) $(SCC_LDFLAGS) addr2line.o -lmach -lscc -o $@
$(BINDIR)/ar: ar.o $(DRIVER).o
$(CC) $(SCC_LDFLAGS) ar.o $(DRIVER).o -o $@
--- a/src/cmd/as/symbol.c
+++ b/src/cmd/as/symbol.c
@@ -47,12 +47,9 @@
unsigned h;
Symbol *sym, **list;
int c, symtype;
- char *t, *s;
+ char *t;
- h = 0;
- for (s = name; c = *s; ++s)
- h = h*33 ^ c;
- h &= HASHSIZ-1;
+ h = genhash(name) & HASHSIZ-1;
c = toupper(*name);
list = &hashtbl[h];
--- a/src/cmd/ld/Makefile
+++ b/src/cmd/ld/Makefile
@@ -9,10 +9,10 @@
all: $(TARGET)
-$(TARGET): $(LIBDIR)/libscc.a
+$(TARGET): $(LIBDIR)/libscc.a $(LIBDIR)/libscc.a
$(TARGET): $(OBJS)
- $(CC) $(SCC_LDFLAGS) $(OBJS) -lmach -o $@
+ $(CC) $(SCC_LDFLAGS) $(OBJS) -lmach -lscc -o $@
dep: inc-dep
--- a/src/cmd/ld/main.c
+++ b/src/cmd/ld/main.c
@@ -98,10 +98,7 @@
unsigned h;
Symbol *sym;
- h = 0;
- for (s = name; *s; s++)
- h += *s;
- h %= NR_SYMBOL;
+ h = genhash(name) % NR_SYMBOL;
for (sym = symtab[h]; sym; sym = sym->hash) {
if (!strcmp(name, sym->name))
--- a/src/cmd/ranlib.c
+++ b/src/cmd/ranlib.c
@@ -10,6 +10,7 @@
#include <scc/ar.h>
#include <scc/arg.h>
#include <scc/mach.h>
+#include <scc/scc.h>
#include "sys.h"
@@ -52,10 +53,7 @@
char *s;
size_t len;
- h = 0;
- for (s = name; *s; s++)
- h += *s;
- h %= NR_SYMDEF;
+ h = genhash(name) % NR_SYMDEF;
for (dp = htab[h]; dp; dp = dp->next) {
if (!strcmp(dp->name, name))
--- a/src/cmd/scc/cc1/symbol.c
+++ b/src/cmd/scc/cc1/symbol.c
@@ -66,11 +66,10 @@
static Symbol **
hash(char *s, int ns)
{
- unsigned c, h, size;
+ unsigned h, size;
Symbol **tab;
- for (h = 0; c = *s; ++s)
- h = h*33 ^ c;
+ h = genhash(s);
switch (ns) {
case NS_CPP:
--- a/src/cmd/scc/posix/scc.c
+++ b/src/cmd/scc/posix/scc.c
@@ -60,7 +60,8 @@
static char *tmpdir;
static size_t tmpdirln;
static struct items objtmp, objout;
-static int Mflag, Eflag, Sflag, cflag, dflag, kflag, sflag, Qflag = 1; /* TODO: Remove Qflag */
+static int Mflag, Eflag, Sflag, Wflag,
+ cflag, dflag, kflag, sflag, Qflag = 1; /* TODO: Remove Qflag */
static int devnullfd = -1;
extern int failure;
@@ -120,6 +121,8 @@
switch (tool) {
case CC1:
+ if (Wflag)
+ addarg(tool, "-w");
for (n = 0; sysincludes[n]; ++n) {
addarg(tool, "-I");
addarg(tool, sysincludes[n]);
@@ -554,10 +557,11 @@
case 't':
sys = EARGF(usage());
break;
- case 'W':
- EARGF(usage());
case 'w':
- addarg(CC1, "-w");
+ Wflag = 0;
+ break;
+ case 'W':
+ Wflag = 1;
break;
case 'q':
Qflag = 0;
--- a/src/libc/stdlib/atoi.c
+++ b/src/libc/stdlib/atoi.c
@@ -1,5 +1,8 @@
#include <ctype.h>
#include <stdlib.h>
+
+#include "../libc.h"
+
#undef atoi
int
--- a/src/libc/stdlib/atol.c
+++ b/src/libc/stdlib/atol.c
@@ -1,5 +1,8 @@
#include <ctype.h>
#include <stdlib.h>
+
+#include "../libc.h"
+
#undef atol
long
--- a/src/libc/stdlib/atoll.c
+++ b/src/libc/stdlib/atoll.c
@@ -1,5 +1,8 @@
#include <ctype.h>
#include <stdlib.h>
+
+#include "../libc.h"
+
#undef atoll
long long
--- a/src/libc/stdlib/malloc.c
+++ b/src/libc/stdlib/malloc.c
@@ -5,6 +5,7 @@
#include "malloc.h"
#include "../syscall.h"
+#include "../libc.h"
#define MAXADDR ((char *)-1)
#define ERRADDR ((char *)-1)
--- a/src/libmach/objlookup.c
+++ b/src/libmach/objlookup.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <scc/mach.h>
+#include <scc/scc.h>
Objsym *
objlookup(Obj *obj, char *name, int install)
@@ -12,11 +13,7 @@
char *s;
Objsym *sym;
- h = 0;
- for (s = name; *s; s++)
- h += *s;
- h %= NR_SYMHASH;
-
+ h = genhash(name) % NR_SYMHASH;
for (sym = obj->htab[h]; sym; sym = sym->hash) {
if (!strcmp(name, sym->name))
return sym;
--- a/src/libscc/Makefile
+++ b/src/libscc/Makefile
@@ -12,6 +12,7 @@
xstrdup.o \
alloc.o \
casecmp.o \
+ genhash.o
TARGET = $(LIBDIR)/libscc.a
--- /dev/null
+++ b/src/libscc/genhash.c
@@ -1,0 +1,11 @@
+unsigned
+genhash(char *name)
+{
+ unsigned h;
+ char c;
+
+ for (h = 0; c = *name; ++name)
+ h = h*33 ^ c;
+
+ return h;
+}