Merge pull request #444 from minad/lto add COMPILE_LTO to test link time optimization
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
diff --git a/.travis.yml b/.travis.yml
index a269c4e..d8aa885 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -163,6 +163,10 @@ matrix:
packages:
- clang-4.0
+ # Link time optimization
+ - env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-travis-valgrind'
+ #- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-travis-valgrind'
+
# GCC for the x86-64 architecture with restricted limb sizes
# formerly started with the option "--with-low-mp" to testme.sh
# but testing all three in one run took to long and timed out.
diff --git a/demo/shared.c b/demo/shared.c
index 5ada460..7ef4756 100644
--- a/demo/shared.c
+++ b/demo/shared.c
@@ -3,7 +3,7 @@
void ndraw(const mp_int *a, const char *name)
{
char *buf;
- size_t size;
+ size_t size = 0;
mp_err err;
if ((err = mp_radix_size(a, 10, &size)) != MP_OKAY) {
diff --git a/makefile b/makefile
index a976574..a9633f8 100644
--- a/makefile
+++ b/makefile
@@ -55,7 +55,6 @@ s_mp_zero_buf.o s_mp_zero_digs.o
$(LIBNAME): $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS)
- $(RANLIB) $@
#make a profiled library (takes a while!!!)
#
@@ -77,7 +76,6 @@ profiled_single: pre_gen
rm -f *.o timing
$(CC) $(LTM_CFLAGS) -fbranch-probabilities -c pre_gen/tommath_amalgam.c -o tommath_amalgam.o
$(AR) $(ARFLAGS) $(LIBNAME) tommath_amalgam.o
- ranlib $(LIBNAME)
install: $(LIBNAME)
install -d $(DESTDIR)$(LIBPATH)
diff --git a/makefile.mingw b/makefile.mingw
index 73199df..55da599 100644
--- a/makefile.mingw
+++ b/makefile.mingw
@@ -13,8 +13,7 @@
PREFIX = c:\mingw
CC = gcc
AR = ar
-ARFLAGS = r
-RANLIB = ranlib
+ARFLAGS = rcs
STRIP = strip
CFLAGS = -O2
LDFLAGS =
@@ -69,7 +68,6 @@ $(OBJECTS): $(HEADERS)
#Create libtommath.a
$(LIBMAIN_S): $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS)
- $(RANLIB) $@
#Create DLL + import library libtommath.dll.a
$(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS)
diff --git a/makefile.unix b/makefile.unix
index 6d06cab..859eed4 100644
--- a/makefile.unix
+++ b/makefile.unix
@@ -16,8 +16,7 @@ LIBPATH = $(PREFIX)/lib
INCPATH = $(PREFIX)/include
CC = cc
AR = ar
-ARFLAGS = r
-RANLIB = ranlib
+ARFLAGS = rcs
CFLAGS = -O2
LDFLAGS =
@@ -72,7 +71,6 @@ $(OBJECTS): $(HEADERS)
#Create libtommath.a
$(LIBMAIN_S): $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS)
- $(RANLIB) $@
#Build test_standalone suite
test: demo/shared.o demo/test.o $(LIBMAIN_S)
diff --git a/makefile_include.mk b/makefile_include.mk
index 4b5961c..be53ba7 100644
--- a/makefile_include.mk
+++ b/makefile_include.mk
@@ -36,7 +36,6 @@ endif # CROSS_COMPILE non-empty
LD=$(CROSS_COMPILE)ld
AR=$(CROSS_COMPILE)ar
-RANLIB=$(CROSS_COMPILE)ranlib
ifndef MAKE
# BSDs refer to GNU Make as gmake
@@ -86,6 +85,11 @@ LTM_CFLAGS += -O3 -funroll-loops
LTM_CFLAGS += -fomit-frame-pointer
endif
+ifdef COMPILE_LTO
+LTM_CFLAGS += -flto
+AR = $(subst clang,llvm-ar,$(subst gcc,gcc-ar,$(CC)))
+endif
+
endif # COMPILE_SIZE
ifneq ($(findstring clang,$(CC)),)
diff --git a/testme.sh b/testme.sh
index 6c71ac4..1a03f55 100755
--- a/testme.sh
+++ b/testme.sh
@@ -107,7 +107,7 @@ _make()
{
echo -ne " Compile $1 $2"
suffix=$(echo ${1}${2} | tr ' ' '_')
- CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS $3 $MAKE_OPTIONS > /dev/null 2>gcc_errors_${suffix}.log
+ CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS $3 $MAKE_OPTIONS 2>gcc_errors_${suffix}.log
errcnt=$(wc -l < gcc_errors_${suffix}.log)
if [[ ${errcnt} -gt 1 ]]; then
echo " failed"
@@ -354,7 +354,7 @@ _banner
if [[ "$TEST_VS_MTEST" != "" ]]
then
make clean > /dev/null
- _make "${compilers[0]} ${archflags[0]}" "$CFLAGS" "mtest_opponent"
+ _make "${compilers[0]}" "${archflags[0]} $CFLAGS" "mtest_opponent"
echo
_make "gcc" "$MTEST_RAND" "mtest"
echo
@@ -394,15 +394,15 @@ do
fi
if [[ "$VALGRIND_BIN" != "" ]]
then
- _runvalgrind "$i $a" "$CFLAGS"
+ _runvalgrind "$i" "$a $CFLAGS"
[ "$WITH_LOW_MP" != "1" ] && continue
- _runvalgrind "$i $a" "-DMP_16BIT $CFLAGS"
- _runvalgrind "$i $a" "-DMP_32BIT $CFLAGS"
+ _runvalgrind "$i" "$a -DMP_16BIT $CFLAGS"
+ _runvalgrind "$i" "$a -DMP_32BIT $CFLAGS"
else
- _runtest "$i $a" "$CFLAGS"
+ _runtest "$i" "$a $CFLAGS"
[ "$WITH_LOW_MP" != "1" ] && continue
- _runtest "$i $a" "-DMP_16BIT $CFLAGS"
- _runtest "$i $a" "-DMP_32BIT $CFLAGS"
+ _runtest "$i" "$a -DMP_16BIT $CFLAGS"
+ _runtest "$i" "$a -DMP_32BIT $CFLAGS"
fi
done
done