From d5002ad0acf10e3b6583fb95b64fe31632916c19 Mon Sep 17 00:00:00 2001 From: Serge Date: Wed, 25 May 2022 19:23:39 -0700 Subject: [PATCH] Use LD for linking mips binaries, not CC. Fix a few incompatibilities in C sources. --- src/cmd/adb/Makefile | 2 +- src/cmd/chown/Makefile | 2 +- src/elf32-mips.ld | 4 ++-- src/libc/stdio/feof.c | 2 +- src/libc/stdio/ferror.c | 2 +- src/libc/stdio/fileno.c | 2 +- src/libc/stdio/flsbuf.c | 4 +--- src/libcurses/addch.c | 4 +--- src/libcurses/box.c | 4 +--- src/libcurses/cr_put.c | 2 +- src/libutil/Makefile | 2 +- src/libutil/login.c | 4 ++++ src/libutil/logout.c | 4 ++++ src/libutil/logwtmp.c | 6 +++++- src/libvmf/Makefile | 2 +- src/libvmf/vmf.c | 18 ++++++++++-------- target.mk | 9 ++++----- 17 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/cmd/adb/Makefile b/src/cmd/adb/Makefile index baaff88..be69694 100644 --- a/src/cmd/adb/Makefile +++ b/src/cmd/adb/Makefile @@ -12,7 +12,7 @@ CFLAGS += -DNUM_SYMS_CACHE=50 -Wall -Werror all: adb adb: $(OBJS) - ${CC} ${LDFLAGS} -o adb.elf $(OBJS) ${LIBS} + ${LD} ${LDFLAGS} -o adb.elf $(OBJS) ${LIBS} ${OBJDUMP} -S adb.elf > adb.dis ${SIZE} adb.elf ${ELF2AOUT} adb.elf $@ && rm adb.elf diff --git a/src/cmd/chown/Makefile b/src/cmd/chown/Makefile index 2ada367..3a1c17b 100644 --- a/src/cmd/chown/Makefile +++ b/src/cmd/chown/Makefile @@ -10,7 +10,7 @@ MANSRC = chown.8 all: chown $(MAN) chown: ${OBJS} - ${CC} ${LDFLAGS} -o chown.elf ${OBJS} ${LIBS} + ${LD} ${LDFLAGS} -o chown.elf ${OBJS} ${LIBS} ${OBJDUMP} -S chown.elf > chown.dis ${SIZE} chown.elf ${ELF2AOUT} chown.elf $@ && rm chown.elf diff --git a/src/elf32-mips.ld b/src/elf32-mips.ld index 8cf668f..f3443a6 100644 --- a/src/elf32-mips.ld +++ b/src/elf32-mips.ld @@ -1,9 +1,9 @@ /* * Linker script for user executables. */ -OUTPUT_FORMAT("elf32-littlemips", "elf32-bigmips", +/* OUTPUT_FORMAT("elf32-littlemips", "elf32-bigmips", "elf32-littlemips") -OUTPUT_ARCH(mips) +OUTPUT_ARCH(mips) */ ENTRY(_start) /* Required by Microchip C32 linker */ diff --git a/src/libc/stdio/feof.c b/src/libc/stdio/feof.c index 5376dba..202504d 100644 --- a/src/libc/stdio/feof.c +++ b/src/libc/stdio/feof.c @@ -10,5 +10,5 @@ int feof(fp) register FILE *fp; { - return feof(fp); + return (fp->_flag & _IOEOF) != 0; } diff --git a/src/libc/stdio/ferror.c b/src/libc/stdio/ferror.c index 16d7925..5f69d0c 100644 --- a/src/libc/stdio/ferror.c +++ b/src/libc/stdio/ferror.c @@ -10,5 +10,5 @@ int ferror(fp) register FILE *fp; { - return ferror(fp); + return (fp->_flag & _IOERR) != 0; } diff --git a/src/libc/stdio/fileno.c b/src/libc/stdio/fileno.c index c7e1abb..a349e3e 100644 --- a/src/libc/stdio/fileno.c +++ b/src/libc/stdio/fileno.c @@ -10,5 +10,5 @@ int fileno(fp) register FILE *fp; { - return fileno(fp); + return fp->_file; } diff --git a/src/libc/stdio/flsbuf.c b/src/libc/stdio/flsbuf.c index 5f462fd..b8673f7 100644 --- a/src/libc/stdio/flsbuf.c +++ b/src/libc/stdio/flsbuf.c @@ -9,9 +9,7 @@ #include #include -int _flsbuf(c, iop) - unsigned char c; - register FILE *iop; +int _flsbuf(unsigned char c, register FILE *iop) { register char *base; register int n, rn; diff --git a/src/libcurses/addch.c b/src/libcurses/addch.c index cc5a0e8..e645947 100644 --- a/src/libcurses/addch.c +++ b/src/libcurses/addch.c @@ -37,9 +37,7 @@ set_ch(win, y, x, ch) /* * This routine adds the character to the current position */ -int waddch(win, c) - WINDOW *win; - char c; +int waddch(WINDOW *win, char c) { int x, y; int newx; diff --git a/src/libcurses/box.c b/src/libcurses/box.c index 6efe365..b18cc46 100644 --- a/src/libcurses/box.c +++ b/src/libcurses/box.c @@ -11,9 +11,7 @@ * */ void -box(win, vert, hor) - WINDOW *win; - char vert, hor; +box(WINDOW *win, char vert, char hor) { int i; int endy, endx; diff --git a/src/libcurses/cr_put.c b/src/libcurses/cr_put.c index 58bcd71..036c042 100644 --- a/src/libcurses/cr_put.c +++ b/src/libcurses/cr_put.c @@ -155,7 +155,7 @@ plod(cnt) } else */ - j = outcol - destcol; + j = outcol - destcol; /* * If we will later need a \n which will turn into a \r\n by * the system or the terminal, then don't bother to try to \r. diff --git a/src/libutil/Makefile b/src/libutil/Makefile index a2cc517..6286f46 100644 --- a/src/libutil/Makefile +++ b/src/libutil/Makefile @@ -17,7 +17,7 @@ TOPSRC = $(shell cd ../..; pwd) include $(TOPSRC)/target.mk -CFLAGS += ${DEFS} +CFLAGS += ${DEFS} -Werror SRCS = login.c logout.c logwtmp.c OBJS = login.o logout.o logwtmp.o diff --git a/src/libutil/login.c b/src/libutil/login.c index c48e6bc..3fcdc7b 100644 --- a/src/libutil/login.c +++ b/src/libutil/login.c @@ -19,6 +19,10 @@ #include #include #include +#include +#include + +int ttyslot(void); void login(ut) diff --git a/src/libutil/logout.c b/src/libutil/logout.c index 85361be..e757e0e 100644 --- a/src/libutil/logout.c +++ b/src/libutil/logout.c @@ -18,11 +18,15 @@ #include #include #include +#include #include #include +#include +#include typedef struct utmp UTMP; +int logout(line) register char *line; { diff --git a/src/libutil/logwtmp.c b/src/libutil/logwtmp.c index dd979d3..f8abf2d 100644 --- a/src/libutil/logwtmp.c +++ b/src/libutil/logwtmp.c @@ -20,7 +20,10 @@ #include #include #include +#include +#include +void logwtmp(line, name, host) char *line, *name, *host; { @@ -30,7 +33,8 @@ logwtmp(line, name, host) time_t time(); char *strncpy(); - if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) + fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0); + if (fd < 0) return; if (!fstat(fd, &buf)) { (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line)); diff --git a/src/libvmf/Makefile b/src/libvmf/Makefile index f02a15e..21abab7 100644 --- a/src/libvmf/Makefile +++ b/src/libvmf/Makefile @@ -15,7 +15,7 @@ MANSRC = vmf.3 CTAGS = ctags #DEFS = -DNOSCCS -#CFLAGS = -O $(DEFS) +CFLAGS = -O -Werror TAGSFILE = tags all: ../libvmf.a $(MAN) diff --git a/src/libvmf/vmf.c b/src/libvmf/vmf.c index 55bbaea..1435a9e 100644 --- a/src/libvmf/vmf.c +++ b/src/libvmf/vmf.c @@ -10,7 +10,7 @@ * been reduced to two write() statements. * 3.0 08Sep93 5. Polish it up for use in 'ld.c' (2.11BSD). * Release into the Public Domain. - * -------------------------------------------------- + * -------------------------------------------------- */ #include @@ -20,12 +20,14 @@ #include #include #include +#include +#include /* * Choose ONE and only one of the following swap policies */ -/* #define LRU /* Least Recently Used */ -/* #define PERC 3 /* Percolation */ +// #define LRU /* Least Recently Used */ +// #define PERC 3 /* Percolation */ #define LRS /* Least Recently Swapped */ #ifndef DEBUG @@ -107,13 +109,13 @@ vmmapseg(vspace, segno) /* look for segment in memory */ for (s = (struct vseg *)seghead[0].fwd; s->s_segno != segno || s->s_vspace != vspace; - s = (struct vseg *)s->s_link.fwd) + s = (struct vseg *)s->s_link.fwd) { if (s == (struct vseg *)seghead) { /* not in memory */ int status; - for (s = (struct vseg *)s->s_link.back; s->s_lock_count != 0; + for (s = (struct vseg *)s->s_link.back; s->s_lock_count != 0; s = (struct vseg *)s->s_link.back) { if (s == (struct vseg *)seghead) @@ -196,7 +198,7 @@ swap(seg, iofunc) /* used only from this file */ if (lseek(v->v_fd, file_address, L_SET) == -1L) return(-2); - switch ((*iofunc)(v->v_fd, seg->s_cinfo, BYTESPERSEG)) + switch ((*iofunc)(v->v_fd, seg->s_cinfo, BYTESPERSEG)) { case BYTESPERSEG: return(0); @@ -330,9 +332,9 @@ vmclose(vs) vmflush(); /* invalidate all segments associated with that file */ for (s = (struct vseg *)seghead[0].fwd; s != (struct vseg *)seghead; - s = (struct vseg *)s->s_link.fwd) + s = (struct vseg *)s->s_link.fwd) { - if (s->s_vspace == vs) + if (s->s_vspace == vs) { s->s_segno = NOSEGNO; s->s_vspace = NULL; diff --git a/target.mk b/target.mk index 8c39bf6..9b51b0e 100644 --- a/target.mk +++ b/target.mk @@ -39,10 +39,10 @@ ifeq ($(LLVMBIN),) endif CC = $(LLVMBIN)clang -target mipsel -mcpu=mips32r2 -mabi=o32 -mfloat-abi=soft \ - -nostdinc -fomit-frame-pointer -finline-hint-functions -I$(TOPSRC)/include \ + -fomit-frame-pointer -finline-hint-functions -I$(TOPSRC)/include \ -Wno-builtin-requires-header CXX = $(LLVMBIN)clang++ -target mipsel -mcpu=mips32r2 -mabi=o32 -mfloat-abi=soft \ - -nostdinc -fomit-frame-pointer -finline-hint-functions -I$(TOPSRC)/include + -fomit-frame-pointer -finline-hint-functions -I$(TOPSRC)/include LD = $(LLVMBIN)ld.lld -m elf32ltsmip AR = $(LLVMBIN)llvm-ar RANLIB = $(LLVMBIN)llvm-ranlib @@ -57,10 +57,9 @@ TAGSFILE = tags MANROFF = nroff -man -h -Tascii ELF2AOUT = $(TOPSRC)/tools/elf2aout/elf2aout -CFLAGS = -Os +CFLAGS = -Os -nostdinc -LDFLAGS = -N -nostartfiles -fno-dwarf2-cfi-asm -T$(TOPSRC)/src/elf32-mips.ld \ - $(TOPSRC)/src/crt0.o -L$(TOPSRC)/src +LDFLAGS = -T$(TOPSRC)/src/elf32-mips.ld $(TOPSRC)/src/crt0.o -L$(TOPSRC)/src LIBS = -lc # Enable mips16e instruction set by default