Skip to content

Commit

Permalink
icc, -O3, DISABLE_CALLCC, hardening flags, make deps
Browse files Browse the repository at this point in the history
add all make deps
make: icc fixes, add LDFLAGS for LINK, harden LDFLAGS
    now with -Wl,-z,relro -Wl,-z,now. faster and more secure initial startup
enable hardening flags
    -pedantic not yet, as it fails to accept casting void* function ptrs
    -Wl,--as-needed -D_FORTIFY_SOURCE=2 (detects jit stack smashing better)
    -fstack-protector-all
    fix minor pedantic issues
renable -O3, only frontends and callcc with -O0
add DISABLE_CALLCC for emcc
    javascript cross-compiler cannot do assembler
  • Loading branch information
Reini Urban committed Oct 4, 2013
1 parent 8e1e4bf commit 032ea07
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 63 deletions.
54 changes: 43 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
.SUFFIXES: .y .c .i .o .opic .textile .html
.PHONY: all pn static usage config clean doc rebuild test bench tarball dist release install grammar

SRC = core/asm.c core/ast.c core/callcc.c core/compile.c core/contrib.c core/file.c core/gc.c core/internal.c core/lick.c core/load.c core/mt19937ar.c core/number.c core/objmodel.c core/primitive.c core/string.c core/syntax.c core/table.c core/vm.c
SRC = core/asm.c core/ast.c core/compile.c core/contrib.c core/file.c core/gc.c core/internal.c core/lick.c core/load.c core/mt19937ar.c core/number.c core/objmodel.c core/primitive.c core/string.c core/syntax.c core/table.c core/vm.c
GREGCFLAGS = -O3 -DNDEBUG

# bootstrap config.inc with make -f config.mak
include config.inc

ifneq (${DISABLE_CALLCC},1)
SRC += core/callcc.c
endif
ifeq (${JIT_X86},1)
SRC += core/vm-x86.c
else
Expand Down Expand Up @@ -36,6 +39,10 @@ OBJ_GC_BENCH = test/api/gc-bench.o
PLIBS = lib/libpotion${DLL} lib/potion/readline${LOADEXT}
DOC = doc/start.textile doc/glossary.textile
DOCHTML = ${DOC:.textile=.html}
OBJS = .o
ifneq (${FPIC},)
OBJS += ${OPIC}
endif

CAT = /bin/cat
ECHO = /bin/echo
Expand Down Expand Up @@ -122,16 +129,43 @@ tools/greg.c: tools/greg.y tools/greg.h tools/compile.c tools/tree.c
${MV} tools/greg-new ${GREG}; \
fi

core/callcc.o: core/callcc.c core/config.h
@${ECHO} CC $@ +frame-pointer
@${CC} -c ${CFLAGS} -fno-omit-frame-pointer ${INCS} -o $@ $<

core/callcc.opic: core/callcc.c core/config.h
@${ECHO} CC $@ +frame-pointer
@${CC} -c ${CFLAGS} ${FPIC} -fno-omit-frame-pointer ${INCS} -o $@ $<

core/callcc.o: core/callcc.c core/config.h core/internal.h
@${ECHO} CC $@ -O0 +frame-pointer
@${CC} -c ${CFLAGS} -O0 -fno-omit-frame-pointer ${INCS} -o $@ $<
core/callcc.opic: core/callcc.c core/config.h core/internal.h
@${ECHO} CC $@ -O0 +frame-pointer
@${CC} -c ${CFLAGS} -O0 ${FPIC} -fno-omit-frame-pointer ${INCS} -o $@ $<
core/potion.o: core/potion.c core/config.h core/potion.h core/internal.h
@${ECHO} CC $@ -O0
@${CC} -c ${CFLAGS} -O0 -fno-omit-frame-pointer ${INCS} -o $@ $<
ifneq (${FPIC},)
core/potion.${OPIC}: core/potion.c core/config.h core/potion.h core/internal.h
@${ECHO} CC $@ -O0
@${CC} -c ${CFLAGS} -O0 ${FPIC} -fno-omit-frame-pointer ${INCS} -o $@ $<
endif
core/vm.o core/vm.opic: core/vm-dis.c core/config.h

core/potion.h: core/config.h
core/table.h: core/potion.h core/internal.h core/khash.h
$(foreach o,${OBJS},core/asm${o} ): core/asm.c core/config.h core/potion.h core/internal.h core/opcodes.h core/asm.h
$(foreach o,${OBJS},core/ast${o} ): core/ast.c core/config.h core/potion.h core/internal.h core/ast.h
$(foreach o,${OBJS},core/compile${o} ): core/compile.c core/config.h core/potion.h core/internal.h core/ast.h core/opcodes.h core/asm.h
$(foreach o,${OBJS},core/contrib${o} ): core/contrib.c core/config.h
$(foreach o,${OBJS},core/file${o} ): core/file.c core/config.h core/potion.h core/internal.h core/table.h
$(foreach o,${OBJS},core/gc${o} ): core/gc.c core/config.h core/potion.h core/internal.h core/table.h core/khash.h core/gc.h
$(foreach o,${OBJS},core/internal${o} ): core/internal.c core/config.h core/potion.h core/internal.h core/table.h core/gc.h
$(foreach o,${OBJS},core/lick${o} ): core/lick.c core/config.h core/potion.h core/internal.h
$(foreach o,${OBJS},core/load${o} ): core/load.c core/config.h core/potion.h core/internal.h core/table.h
$(foreach o,${OBJS},core/mt19937ar${o} ): core/mt19937ar.c
$(foreach o,${OBJS},core/number${o} ): core/number.c core/config.h core/potion.h core/internal.h
$(foreach o,${OBJS},core/objmodel${o} ): core/objmodel.c core/config.h core/potion.h core/internal.h core/table.h core/khash.h core/asm.h
$(foreach o,${OBJS},core/primitive${o} ): core/primitive.c core/config.h core/potion.h core/internal.h
$(foreach o,${OBJS},core/string${o} ): core/string.c core/config.h core/potion.h core/internal.h core/table.h core/khash.h
$(foreach o,${OBJS},core/table${o} ): core/table.c core/config.h core/potion.h core/internal.h core/khash.h core/table.h
$(foreach o,${OBJS},core/vm${o} ): core/vm.c core/vm-dis.c core/config.h core/potion.h core/internal.h core/opcodes.h core/khash.h core/table.h
$(foreach o,${OBJS},core/vm-ppc${o} ): core/vm-ppc.c core/config.h core/potion.h core/internal.h core/opcodes.h
$(foreach o,${OBJS},core/vm-x86${o} ): core/vm-x86.c core/config.h core/potion.h core/internal.h core/opcodes.h core/khash.h core/table.h

%.i: %.c core/config.h
@${ECHO} CPP $@
@${CC} -c ${CFLAGS} ${INCS} -o $@ -E -c $<
Expand Down Expand Up @@ -219,8 +253,6 @@ check: test
test: bin/potion${EXE} test/api/potion-test${EXE} test/api/gc-test${EXE}
@${ECHO}; \
${ECHO} running potion API tests; \
LD_LIBRARY_PATH=`pwd`/lib:$LD_LIBRARY_PATH \
export LD_LIBRARY_PATH; \
test/api/potion-test; \
count=0; failed=0; pass=0; \
while [ $$pass -lt 3 ]; do \
Expand Down
81 changes: 68 additions & 13 deletions config.mak
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# create config.inc and core/config.h
PREFIX = /usr/local
CC = $(shell tools/config.sh compiler)
WARNINGS = -Wall -Werror -Wno-switch -Wno-return-type -Wno-unused-label
CFLAGS = -D_GNU_SOURCE
# -pedantic not yet
WARNINGS = -Wall -Werror -Wno-variadic-macros -Wno-pointer-arith -Wno-return-type
CFLAGS = -D_GNU_SOURCE -fno-strict-aliasing -D_FORTIFY_SOURCE=2
INCS = -Icore
LIBPTH = -Llib
RPATH = -Wl,-rpath=$(shell pwd)/lib
RPATH_INSTALL = -Wl,-rpath=\$${PREFIX}/lib
LIBS = -lm
LDFLAGS ?=
LDDLLFLAGS = -shared -fpic
AR ?= ar
DEBUG ?= 0
Expand All @@ -18,6 +20,7 @@ JIT = 0
EXE =
APPLE = 0
CYGWIN = 0
RUNPRE = ./

CAT = /bin/cat
ECHO = /bin/echo
Expand All @@ -32,7 +35,7 @@ ifneq (${JIT_TARGET},)
endif

ifeq (${JIT},1)
#ifeq (${JIT_TARGET},X86)
ifeq (${JIT_TARGET},X86)
ifneq (${DEBUG},0)
# http://udis86.sourceforge.net/ x86 16,32,64 bit
# port install udis86
Expand Down Expand Up @@ -79,26 +82,63 @@ endif
endif
endif
endif
endif

# JIT with -O still fails callcc tests
ifneq (${JIT},1)
# JIT with -O still fails some tests
#ifneq (${JIT},1)
ifeq (${DEBUG},0)
DEBUGFLAGS += -O3
endif
#endif

ifneq (,$(findstring ccache,${CC}))
WARNINGS = -Wall -Wno-variadic-macros -Wno-pointer-arith -Wno-return-type
CFLAGS += -Qunused-arguments
endif
ifneq ($(shell tools/config.sh "${CC}" clang),0)
CLANG = 1
WARNINGS += -Wno-unused-value
WARNINGS += -Wno-unused-value -Wno-switch -Wno-unused-label
#todo: 64bit => -fPIE and -fpie for the linker
ifeq (${DEBUG},0)
DEFINES += -DCGOTO
DEBUGFLAGS += -finline
endif
else
CFLAGS += -fno-strict-aliasing
ifneq ($(shell ./tools/config.sh "${CC}" icc),0)
ICC = 1
#DEFINES += -DCGOTO
DEBUGFLAGS += -falign-functions=16
# 186: pointless comparison of unsigned integer with zero in PN_TYPECHECK
# 177: label "l414" was declared but never referenced in syntax.c sets fail case
# 188: enumerated type mixed with another type (treating P->flags as int)
WARNINGS += -Wno-sign-compare -Wno-pointer-arith -diag-remark 186,177,188
ifeq (${DEBUG},0)
# -Ofast
DEBUGFLAGS += -finline
else
DEBUGFLAGS += -g3 -gdwarf-3
endif
else
ifneq ($(shell ./tools/config.sh "${CC}" gcc),0)
WARNINGS += -Wno-switch -Wno-unused-label
DEBUGFLAGS += --param ssp-buffer-size=1
ifeq (${DEBUG},0)
DEBUGFLAGS += -finline -falign-functions
DEFINES += -DCGOTO
endif
endif
endif
endif

ifeq (${DEBUG},0)
DEBUGFLAGS += -fno-stack-protector
DEBUGFLAGS += -fstack-protector-all
else
DEFINES += -DDEBUG
STRIP = echo
ifneq (${CLANG},1)
DEBUGFLAGS += -g3 -fstack-protector
DEBUGFLAGS += -g3 -fstack-protector-all
else
DEBUGFLAGS += -g -fstack-protector
DEBUGFLAGS += -g -fstack-protector-all
endif
endif
ifeq (${ASAN},1)
Expand Down Expand Up @@ -126,6 +166,7 @@ ifeq ($(shell tools/config.sh "${CC}" mingw),1)
ifneq (${CROSS},1)
ECHO = echo
CAT = type
RUNPRE =
else
RANLIB = $(shell echo "${CC}" | sed -e "s,-gcc,-ranlib,")
endif
Expand All @@ -142,7 +183,7 @@ ifeq ($(shell tools/config.sh "${CC}" apple),1)
DLL = .dylib
LOADEXT = .bundle
LDDLLFLAGS = -dynamiclib -undefined dynamic_lookup -fpic -Wl,-flat_namespace
LDDLLFLAGS += -install_name @executable_path/../lib/libpotion${DLL}
RDLLFLAGS = -install_name "@executable_path/../lib/libpotion${DLL}"
RPATH =
RPATH_INSTALL =
else
Expand All @@ -155,6 +196,15 @@ endif
endif
endif

ifneq ($(APPLE),1)
ifneq ($(ICC),1)
WARNINGS += -Wno-zero-length-array -Wno-gnu
endif
LDFLAGS += -Wl,--as-needed -Wl,-z,relro -Wl,-z,now
LDDLLFLAGS += $(LDFLAGS)
endif


# let an existing config.inc overwrite everything
include config.inc

Expand All @@ -172,17 +222,21 @@ config.inc.echo:
@${ECHO} "WARNINGS = ${WARNINGS}"
@${ECHO} "CFLAGS = ${CFLAGS} " "\$$"{DEFINES} "\$$"{DEBUGFLAGS} "\$$"{WARNINGS}
@${ECHO} "INCS = ${INCS}"
@${ECHO} "LDDLLFLAGS = ${LDDLLFLAGS}"
@${ECHO} "LIBPTH = ${LIBPTH}"
@${ECHO} "RPATH = ${RPATH}"
@${ECHO} "RPATH_INSTALL = " ${RPATH_INSTALL}
@${ECHO} "LIBPTH = ${LIBPTH}"
@${ECHO} "LIBS = ${LIBS}"
@${ECHO} "LDFLAGS = ${LDFLAGS}"
@${ECHO} "LDDLLFLAGS = ${LDDLLFLAGS}"
@${ECHO} "STRIP = ${STRIP}"
@${ECHO} "RUNPRE = ${RUNPRE}"
@${ECHO} "CROSS = ${CROSS}"
@${ECHO} "APPLE = ${APPLE}"
@${ECHO} "WIN32 = ${WIN32}"
@${ECHO} "CYGWIN = ${CYGWIN}"
@${ECHO} "CLANG = ${CLANG}"
@${ECHO} "ICC = ${ICC}"
@${ECHO} "GCC = ${GCC}"
@${ECHO} "JIT = ${JIT}"
@test -n ${JIT_TARGET} && ${ECHO} "JIT_${JIT_TARGET} = 1"
@${ECHO} "DEBUG = ${DEBUG}"
Expand All @@ -192,6 +246,7 @@ config.inc.echo:
config.h.echo:
@${ECHO} "#define POTION_CC \"${CC}\""
@${ECHO} "#define POTION_CFLAGS \"${CFLAGS}\""
@${ECHO} "#define POTION_LDFLAGS \"${LDFLAGS}\""
@${ECHO} "#define POTION_MAKE \"${MAKE}\""
@${ECHO} "#define POTION_PREFIX \"${PREFIX}\""
@${ECHO} "#define POTION_EXE \"${EXE}\""
Expand Down
4 changes: 2 additions & 2 deletions core/callcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ PN potion_callcc(Potion *P, PN cl, PN self) {
fprintf(stderr,"P->mem->cstack=0x%lx ", (_PN)sp1);
potion_fatal("stack not 16byte aligned");
}
#elsif defined(DEBUG) && (__WORDSIZE == 64)
if (((_PN)sp1 & 0xF) || (((_PN)sp1 & 0xF) != 8)) {
#elif defined(DEBUG) && (__WORDSIZE == 64)
if (((_PN)sp1 & 0xF) != 0 && ((_PN)sp1 & 0xF) != 8) {
fprintf(stderr,"P->mem->cstack=0x%lx ", (_PN)sp1);
potion_fatal("stack not 8byte aligned");
}
Expand Down
1 change: 1 addition & 0 deletions core/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static inline int NEW_BIRTH_REGION(struct PNMemory *M, void **wb, int sz) {
DEL_BIRTH_REGION();
SET_GEN(birth, newad, sz);
SET_STOREPTR(5 + keeps);
return sz;
}

/** \par
Expand Down
4 changes: 3 additions & 1 deletion core/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ char potion_type_char(PNType type) {
case PN_TSTRINGS: return 'x'; //18
case PN_TERROR: return 'r'; //19
case PN_TCONT: return 'c'; //20
case PN_TUSER: return 'u'; //21
case PN_TDECIMAL: return 'd'; //21
case PN_TUSER: return 'm'; //22
default: return 'm'; //22++
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void potion_load_dylib(Potion *P, const char *filename) {
return;
}
init_func_name = potion_initializer_name(P, filename, strlen(filename));
func = dlsym(handle, init_func_name);
err = dlerror();
func = (void (*)(Potion *))dlsym(handle, init_func_name);
err = (char *)dlerror();
free(init_func_name);
if (err != NULL) {
fprintf(stderr, "** error loading %s: %s\n", filename, err);
Expand Down
2 changes: 2 additions & 0 deletions core/number.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ static PN potion_num_to(Potion *P, PN cl, PN self, PN end, PN block) {
\param end PNNumber (int only)
\param step PNNumber (int only)
\param block PNClosure
\return self PNNumber (normally unused)
\sa potion_num_to. */
static PN potion_num_step(Potion *P, PN cl, PN self, PN end, PN step, PN block) {
long i, j = PN_INT(end), k = PN_INT(step);
for (i = PN_INT(self); i <= j; i += k) {
PN_CLOSURE(block)->method(P, block, P->lobby, PN_NUM(i));
}
return PN_NUM(abs(i - j));
}
/**\memberof PNNumber
"chr" of int only, no UTF-8 multi-byte sequence
Expand Down
4 changes: 3 additions & 1 deletion core/objmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ int potion_sig_arity(Potion *P, PN sig) {
return 0;
else {
potion_fatal("wrong sig type for sig_arity");
return 0;
}
}

Expand Down Expand Up @@ -114,6 +115,7 @@ PN potion_sig_at(Potion *P, PN sig, int index) {
return result;
else {
potion_fatal("wrong sig type for sig_at");
return 0;
}
}

Expand Down Expand Up @@ -221,7 +223,7 @@ PN potion_ivars(Potion *P, PN cl, PN self, PN ivars) {
// since many times these tables are <100 bytes.
PNAsm * volatile asmb = potion_asm_new(P);
P->target.ivars(P, ivars, &asmb);
vt->ivfunc = PN_ALLOC_FUNC(asmb->len);
vt->ivfunc = (PN_IVAR_FUNC)PN_ALLOC_FUNC(asmb->len);
PN_MEMCPY_N(vt->ivfunc, asmb->ptr, u8, asmb->len);
#endif
vt->ivlen = PN_TUPLE_LEN(ivars);
Expand Down

0 comments on commit 032ea07

Please sign in to comment.