Modify build scripts for clang.

Disable -mips16 flag for now.
Fix a few issues and incompatibilities detected by compiler.
This commit is contained in:
Serge
2022-05-25 17:37:37 -07:00
parent 71faeb6c76
commit 9f617eb6fe
17 changed files with 131 additions and 192 deletions

View File

@@ -34,8 +34,9 @@ CONFIG = $(TOPSRC)/tools/configsys/config
all:
$(MAKE) -C tools
$(MAKE) -C src
$(MAKE) -C lib
$(MAKE) -C src install
$(MAKE) -C install
$(MAKE) kernel
$(MAKE) fs

View File

@@ -23,9 +23,13 @@ LDFLAGS =
LIBS =
# Add system include path
ifeq (,$(wildcard /usr/include/i386-linux-gnu))
CFLAGS += -I/usr/include
ifeq (/usr/include/x86_64-linux-gnu,$(wildcard /usr/include/x86_64-linux-gnu))
CFLAGS += -I/usr/include/x86_64-linux-gnu
else
ifeq (/usr/include/i386-linux-gnu,$(wildcard /usr/include/i386-linux-gnu))
CFLAGS += -I/usr/include/i386-linux-gnu
else
CFLAGS += -I/usr/include
endif
endif
CFLAGS += -I$(TOPSRC)/include

View File

@@ -37,7 +37,7 @@ typedef unsigned size_t;
int bcmp(const void *, const void *, size_t);
void bcopy(const void *, void *, size_t);
void bzero(void *, unsigned long);
void bzero(void *, unsigned int);
int ffs(int);
char *index(const char *, int);
char *rindex(const char *, int);

View File

@@ -9,14 +9,15 @@ TOPSRC = $(shell cd ../..; pwd)
include $(TOPSRC)/target.mk
vpath %.c $(TOPSRC)/src/startup-mips
CFLAGS = -Os -B$(TOPSRC)/lib/ -Wa,-x $(DEFS)
CFLAGS = -v -Os -B$(TOPSRC)/lib/ $(DEFS)
OBJS = ../crt0.o
all: $(OBJS)
../crt0.o: crt0.c
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
$(CC) $(DEFS) $(CFLAGS) -S $< -o crt0.s
$(TOPSRC)/lib/as -x crt0.s -o $@
clean:
rm -f $(OBJS) *~

View File

@@ -262,7 +262,7 @@ bad1: (void)lseek(rfd, (off_t)r_off, SEEK_SET);
void symobj()
{
register RLIB *rp;
char hb[sizeof(struct ar_hdr) + 1];
char hb[sizeof(struct ar_hdr) + 1 + 64];
long ransize, baseoff;
/* Rewind the archive, leaving the magic number. */

View File

@@ -19,7 +19,8 @@ execlp(name, argv)
static char *
execat(s1, s2, si)
register char *s1, *s2;
register char *s1;
const char *s2;
char *si;
{
register char *s;

View File

@@ -85,7 +85,7 @@ vsyslog(pri, fmt, ap)
}
/* Check priority against setlogmask values. */
if (! LOG_MASK(LOG_PRI(pri)) && LogMask)
if (LOG_MASK(LOG_PRI(pri)) == 0 && LogMask)
return;
saved_errno = errno;
@@ -161,7 +161,7 @@ vsyslog(pri, fmt, ap)
if (pid == -1)
return;
if (pid == 0) {
fd = open(_PATH_CONSOLE, O_WRONLY, 0);
fd = open(_PATH_CONSOLE, O_WRONLY, 0);
p = index(tbuf, '>') + 1;
(void)write(fd, p, cnt - (p - tbuf));
(void)close(fd);

View File

@@ -28,5 +28,5 @@ ualarm(usecs, reload)
if (setitimer(ITIMER_REAL, &new, &old) == 0)
return (old.it_value.tv_sec * USPS + old.it_value.tv_usec);
/* else */
return (-1);
return (-1);
}

View File

@@ -62,7 +62,7 @@ typedef struct fd_set {
#ifndef KERNEL
#ifndef CROSS
void bzero(void *, unsigned long);
void bzero(void *, unsigned int);
#endif
/* According to POSIX.1-2001 */

View File

@@ -5,18 +5,17 @@
#
include ../gcc-config.mk
AS = ${MIPS_GCC_PREFIX}as ${DEBUG} -mips32r2 -EL
CC = ${MIPS_GCC_PREFIX}gcc ${DEBUG} -mips32r2 -EL -nostdinc -fno-builtin -Werror -Wall
CPP = ${MIPS_GCC_PREFIX}cpp
LD = ${MIPS_GCC_PREFIX}gcc -mips32r2 -EL
AS = $(LLVMBIN)/clang -target mipsel -mcpu=mips32r2 ${DEBUG}
CC = -mabi=o32 -mfloat-abi=soft \
-nostdinc -fshort-double -fomit-frame-pointer -finline-hint-functions -I$(TOPSRC)/include
CC = $(LLVMBIN)/clang -target mipsel -mcpu=mips32r2 -mabi=o32 -mfloat-abi=soft \
${DEBUG} -nostdinc -fno-builtin -Werror -Wall
CPP = $(LLVMBIN)/clang-cpp
LD = /usr/lib/llvm-12/bin/ld.lld -m elf32ltsmip
LDFLAGS = -nostdlib -T ../${LDSCRIPT} -Wl,-Map=$(basename $@).map
SIZE = ${MIPS_GCC_PREFIX}size
OBJCOPY = ${MIPS_GCC_PREFIX}objcopy
OBJDUMP = ${MIPS_GCC_PREFIX}objdump
ifneq (${MIPS_GCC_FORMAT},)
LDFLAGS += -Wl,--oformat=${MIPS_GCC_FORMAT}
endif
SIZE = $(LLVMBIN)/llvm-size
OBJCOPY = $(LLVMBIN)/llvm-objcopy
OBJDUMP = $(LLVMBIN)/llvm-objdump
# sources are located via $S relative to the compilation directory
S = ../..

View File

@@ -1,81 +1,33 @@
# chipKIT PIC32 compiler from UECIDE
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Use UECIDE package from http://uecide.org/download
ifndef MIPS_GCC_PREFIX
ifdef UECIDE
ifeq ($(UECIDE)/compilers/pic32-tools-452/bin/pic32-gcc,$(wildcard $(UECIDE)/compilers/pic32-tools-452/bin/pic32-gcc))
MIPS_GCC_PREFIX = $(UECIDE)/compilers/pic32-tools-452/bin/pic32-
MIPS_GCC_FORMAT = elf32-tradlittlemips
endif
endif
# Clang compiler on Linux
# ~~~~~~~~~~~~~~~~~~~~~~~
# Install by:
# sudo apt install clang-12
# Newer versions are also OK.
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/lib/llvm-12/bin/clang))
endif
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/lib/llvm-13/bin/clang))
endif
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/lib/llvm-14/bin/clang))
endif
# chipKIT PIC32 compiler on Linux
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Download from https://github.com/jasonkajita/chipKIT-cxx/downloads
# and unzip to /usr/local.
# Need to copy pic32-tools/pic32mx/include/stdarg.h
# to pic32-tools/lib/gcc/pic32mx/4.5.1/include.
# MPLABX C32 compiler doesn't support some functionality
# we need, so use chipKIT compiler by default.
ifndef MIPS_GCC_PREFIX
ifeq (/usr/local/pic32-tools/bin/pic32-gcc,$(wildcard /usr/local/pic32-tools/bin/pic32-gcc))
MIPS_GCC_PREFIX = /usr/local/pic32-tools/bin/pic32-
MIPS_GCC_FORMAT = elf32-tradlittlemips
endif
# Clang compiler on MacOS
# ~~~~~~~~~~~~~~~~~~~~~~~
# Install by:
# brew install clang@12
# Newer versions are also OK.
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@12/12.*/bin/clang-12))
endif
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@13/13.*/bin/clang-13))
endif
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@14/14.*/bin/clang-14))
endif
# Generic MIPS toolchain
# ~~~~~~~~~~~~~~~~~~~~~~
# You can build it from sources, as described on page
# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips
ifndef MIPS_GCC_PREFIX
ifeq (/usr/local/mips-gcc-4.8.1/bin/mips-elf-gcc,$(wildcard /usr/local/mips-gcc-4.8.1/bin/mips-elf-gcc))
MIPS_GCC_PREFIX = /usr/local/mips-gcc-4.8.1/bin/mips-elf-
endif
endif
# Generic MIPS toolchain on *BSD
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# You can build it from sources, as described on page
# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips
# Maybe you can install it from packages one day too.
ifndef MIPS_GCC_PREFIX
ifeq (/usr/local/mips-elf/bin/mips-elf-gcc,$(wildcard /usr/local/mips-elf/bin/mips-elf-gcc))
MIPS_GCC_PREFIX = /usr/local/mips-elf/bin/mips-elf-
endif
endif
# Mentor Sourcery CodeBench Lite toolchain
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ifndef MIPS_GCC_PREFIX
# Download a Linux binary package from
# https://sourcery.mentor.com/GNUToolchain/release2641
ifeq (/usr/local/mips-2013.11/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2013.11/bin/mips-sde-elf-gcc))
MIPS_GCC_PREFIX = /usr/local/mips-2013.11/bin/mips-sde-elf-
MIPS_GCC_FORMAT = elf32-tradlittlemips
endif
endif
ifndef MIPS_GCC_PREFIX
# Download a Linux binary package from
# https://sourcery.mentor.com/GNUToolchain/release2774
ifeq (/usr/local/mips-2014.05/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2014.05/bin/mips-sde-elf-gcc))
MIPS_GCC_PREFIX = /usr/local/mips-2014.05/bin/mips-sde-elf-
MIPS_GCC_FORMAT = elf32-tradlittlemips
endif
endif
# Imagination Codescape MIPS SDK Essentials
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Download a Linux binary package from:
# http://community.imgtec.com/developers/mips/tools/codescape-mips-sdk/download-codescape-mips-sdk-essentials/
ifndef MIPS_GCC_ROOT
ifeq (/opt/imgtec/Toolchains/mips-mti-elf/2015.01-7,$(wildcard /opt/imgtec/Toolchains/mips-mti-elf/2015.01-7))
MIPS_GCC_ROOT = /opt/imgtec/Toolchains/mips-mti-elf/2015.01-7
MIPS_GCC_FORMAT = elf32-tradlittlemips
endif
endif
ifndef MIPS_GCC_PREFIX
$(error Unable to locate any GCC MIPS toolchain!)
ifeq ($(LLVMBIN),)
$(error Unable to find any CLANG toolchain!)
endif

114
target.mk
View File

@@ -4,88 +4,50 @@ RELEASE = 0.0
BUILD = $(shell git rev-list HEAD --count)
VERSION = $(RELEASE)-$(BUILD)
# chipKIT PIC32 compiler from UECIDE
ifdef UECIDE
ifndef GCCPREFIX
ifeq ($(UECIDE)/compilers/pic32-tools-452/bin/pic32-gcc,$(wildcard $(UECIDE)/compilers/pic32-tools-452/bin/pic32-gcc))
GCCPREFIX = ${UECIDE}/compilers/pic32-tools-452/bin/pic32-
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
INCLUDES = -I${UECIDE}/compilers/pic32-tools-452/lib/gcc/pic32mx/4.5.2/include
endif
# Clang compiler on Linux
# ~~~~~~~~~~~~~~~~~~~~~~~
# Install by:
# sudo apt install clang-12
# Newer versions are also OK.
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/lib/llvm-12/bin/clang))
endif
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/lib/llvm-13/bin/clang))
endif
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/lib/llvm-14/bin/clang))
endif
# chipKIT PIC32 compiler on Linux
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Download from https://github.com/jasonkajita/chipKIT-cxx/downloads
# and unzip to /usr/local.
# Need to copy pic32-tools/pic32mx/include/stdarg.h
# to pic32-tools/lib/gcc/pic32mx/4.5.1/include.
# MPLABX C32 compiler doesn't support some functionality
# we need, so use chipKIT compiler by default.
ifndef GCCPREFIX
ifeq (/usr/local/pic32-tools/bin/pic32-gcc,$(wildcard /usr/local/pic32-tools/bin/pic32-gcc))
GCCPREFIX = /usr/local/pic32-tools/bin/pic32-
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
INCLUDES = -I/usr/local/pic32-tools/lib/gcc/pic32mx/4.5.1/include
# Clang compiler on MacOS
# ~~~~~~~~~~~~~~~~~~~~~~~
# Install by:
# brew install clang@12
# Newer versions are also OK.
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@12/12.*/bin/clang-12))
endif
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@13/13.*/bin/clang-13))
endif
ifeq ($(LLVMBIN),)
LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@14/14.*/bin/clang-14))
endif
# Generic MIPS toolchain
# ~~~~~~~~~~~~~~~~~~~~~~
# You can build it from sources, as described on page
# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips
ifndef GCCPREFIX
ifeq (/usr/local/mips-gcc-4.8.1/bin/mips-elf-gcc,$(wildcard /usr/local/mips-gcc-4.8.1/bin/mips-elf-gcc))
GCCPREFIX = /usr/local/mips-gcc-4.8.1/bin/mips-elf-
LDFLAGS =
INCLUDES =
endif
ifeq ($(LLVMBIN),)
$(error Unable to find any CLANG toolchain!)
endif
# Generic MIPS toolchain on *BSD
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# You can build it from sources, as described on page
# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips
# Maybe you can install it from packages one day too.
ifndef GCCPREFIX
ifeq (/usr/local/mips-elf/bin/mips-elf-gcc,$(wildcard /usr/local/mips-elf/bin/mips-elf-gcc))
GCCPREFIX = /usr/local/mips-elf/bin/mips-elf-
LDFLAGS =
INCLUDES =
endif
endif
# Mentor Sourcery CodeBench Lite toolchain
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# You can download a Linux or Windows binary package from
# https://sourcery.mentor.com/GNUToolchain/release2641
ifndef GCCPREFIX
ifeq (/usr/local/mips-2013.11/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2013.11/bin/mips-sde-elf-gcc))
GCCPREFIX = /usr/local/mips-2013.11/bin/mips-sde-elf-
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
INCLUDES =
endif
endif
ifndef GCCPREFIX
ifeq (/usr/local/mips-2014.05/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2014.05/bin/mips-sde-elf-gcc))
GCCPREFIX = /usr/local/mips-2014.05/bin/mips-sde-elf-
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
INCLUDES =
endif
endif
ifndef GCCPREFIX
$(error Unable to locate any GCC MIPS toolchain!)
endif
CC = $(GCCPREFIX)gcc -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES)
CXX = $(GCCPREFIX)g++ -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES)
LD = $(GCCPREFIX)ld
AR = $(GCCPREFIX)ar
RANLIB = $(GCCPREFIX)ranlib
SIZE = $(GCCPREFIX)size
OBJDUMP = $(GCCPREFIX)objdump -mmips:isa32r2
CC = $(LLVMBIN)clang -target mipsel -mcpu=mips32r2 -mabi=o32 -mfloat-abi=soft \
-nostdinc -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
LD = $(LLVMBIN)ld.lld -m elf32ltsmip
AR = $(LLVMBIN)llvm-ar
RANLIB = $(LLVMBIN)llvm-ranlib
SIZE = $(LLVMBIN)llvm-size
OBJDUMP = $(LLVMBIN)llvm-objdump --mcpu=mips32r2
AS = $(CC) -x assembler-with-cpp -c
YACC = byacc
LEX = flex
@@ -97,9 +59,9 @@ ELF2AOUT = $(TOPSRC)/tools/elf2aout/elf2aout
CFLAGS = -Os
LDFLAGS += -N -nostartfiles -fno-dwarf2-cfi-asm -T$(TOPSRC)/src/elf32-mips.ld \
LDFLAGS = -N -nostartfiles -fno-dwarf2-cfi-asm -T$(TOPSRC)/src/elf32-mips.ld \
$(TOPSRC)/src/crt0.o -L$(TOPSRC)/src
LIBS = -lc
# Enable mips16e instruction set by default
CFLAGS += -mips16
#CFLAGS += -mips16

View File

@@ -125,15 +125,15 @@ struct config {
/*
* Config has a global notion of which architecture is being used.
*/
int arch;
char *archname;
extern int arch;
extern char *archname;
#define ARCH_PIC32 1
/*
* For each architecture, a set of CPU's may be specified as supported.
* These and the options (below) are put in the C flags in the makefile.
*/
struct cputype {
extern struct cputype {
char *cpu_name;
struct cputype *cpu_next;
} *cputype;
@@ -143,7 +143,7 @@ struct cputype {
* but which may also specify values for the options.
* A separate set of options may be defined for make-style options.
*/
struct opt {
extern struct opt {
char *op_name;
char *op_value;
struct opt *op_next;
@@ -152,30 +152,30 @@ struct opt {
/*
* Mapping of signal names to pins.
*/
struct signal {
extern struct signal {
char *sig_name;
int sig_pin;
int sig_invert;
struct signal *sig_next;
} *siglist;
char *board;
char *ldscript;
extern char *board;
extern char *ldscript;
int do_trace;
extern int do_trace;
struct device *dtab;
extern struct device *dtab;
char errbuf[80];
int yyline;
extern char errbuf[80];
extern int yyline;
struct file_list *ftab, *conf_list, **confp, *comp_list, **compp;
extern struct file_list *ftab, *conf_list, **confp, *comp_list, **compp;
int zone, hadtz;
int dst;
int debugging;
extern int zone, hadtz;
extern int dst;
extern int debugging;
int maxusers;
extern int maxusers;
#define eq(a,b) (!strcmp(a,b))

View File

@@ -102,6 +102,7 @@
#include "config.h"
#include <ctype.h>
#include <stdio.h>
#include <sys/sysmacros.h>
struct device cur;
struct device *curp = 0;

View File

@@ -38,6 +38,23 @@
#include "y.tab.h"
#include "config.h"
int arch;
char *archname;
struct cputype *cputype;
struct opt *opt, *mkopt;
struct signal *siglist;
char *board;
char *ldscript;
int do_trace;
struct device *dtab;
char errbuf[80];
int yyline;
struct file_list *ftab, *conf_list, **confp, *comp_list, **compp;
int zone, hadtz;
int dst;
int debugging;
int maxusers;
/*
* Config builds a set of files for building a UNIX
* system given a description of the desired system.

View File

@@ -38,6 +38,7 @@
#include <unistd.h>
#include <ctype.h>
#include <sys/sysmacros.h>
void swapconf()
{

View File

@@ -373,7 +373,7 @@ static int load_nand_flash_file (nand_flash_1g_data_t * d)
int i, j = 0;
struct dirent *ent = NULL;
DIR *p_dir;
char file_path[64];
char file_path[1024];
char *file_name;
char block_number[16];
int fd;