Skip to content

Commit cc77fad

Browse files
authored
Merge pull request #444 from minad/lto
add COMPILE_LTO to test link time optimization
2 parents 67e1816 + 3b98e82 commit cc77fad

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ matrix:
163163
packages:
164164
- clang-4.0
165165

166+
# Link time optimization
167+
- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-travis-valgrind'
168+
#- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-travis-valgrind'
169+
166170
# GCC for the x86-64 architecture with restricted limb sizes
167171
# formerly started with the option "--with-low-mp" to testme.sh
168172
# but testing all three in one run took to long and timed out.

demo/shared.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
void ndraw(const mp_int *a, const char *name)
44
{
55
char *buf;
6-
size_t size;
6+
size_t size = 0;
77
mp_err err;
88

99
if ((err = mp_radix_size(a, 10, &size)) != MP_OKAY) {

makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ s_mp_zero_buf.o s_mp_zero_digs.o
5555

5656
$(LIBNAME): $(OBJECTS)
5757
$(AR) $(ARFLAGS) $@ $(OBJECTS)
58-
$(RANLIB) $@
5958

6059
#make a profiled library (takes a while!!!)
6160
#
@@ -77,7 +76,6 @@ profiled_single: pre_gen
7776
rm -f *.o timing
7877
$(CC) $(LTM_CFLAGS) -fbranch-probabilities -c pre_gen/tommath_amalgam.c -o tommath_amalgam.o
7978
$(AR) $(ARFLAGS) $(LIBNAME) tommath_amalgam.o
80-
ranlib $(LIBNAME)
8179

8280
install: $(LIBNAME)
8381
install -d $(DESTDIR)$(LIBPATH)

makefile.mingw

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
PREFIX = c:\mingw
1414
CC = gcc
1515
AR = ar
16-
ARFLAGS = r
17-
RANLIB = ranlib
16+
ARFLAGS = rcs
1817
STRIP = strip
1918
CFLAGS = -O2
2019
LDFLAGS =
@@ -69,7 +68,6 @@ $(OBJECTS): $(HEADERS)
6968
#Create libtommath.a
7069
$(LIBMAIN_S): $(OBJECTS)
7170
$(AR) $(ARFLAGS) $@ $(OBJECTS)
72-
$(RANLIB) $@
7371

7472
#Create DLL + import library libtommath.dll.a
7573
$(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS)

makefile.unix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ LIBPATH = $(PREFIX)/lib
1616
INCPATH = $(PREFIX)/include
1717
CC = cc
1818
AR = ar
19-
ARFLAGS = r
20-
RANLIB = ranlib
19+
ARFLAGS = rcs
2120
CFLAGS = -O2
2221
LDFLAGS =
2322

@@ -72,7 +71,6 @@ $(OBJECTS): $(HEADERS)
7271
#Create libtommath.a
7372
$(LIBMAIN_S): $(OBJECTS)
7473
$(AR) $(ARFLAGS) $@ $(OBJECTS)
75-
$(RANLIB) $@
7674

7775
#Build test_standalone suite
7876
test: demo/shared.o demo/test.o $(LIBMAIN_S)

makefile_include.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ endif # CROSS_COMPILE non-empty
3636

3737
LD=$(CROSS_COMPILE)ld
3838
AR=$(CROSS_COMPILE)ar
39-
RANLIB=$(CROSS_COMPILE)ranlib
4039

4140
ifndef MAKE
4241
# BSDs refer to GNU Make as gmake
@@ -86,6 +85,11 @@ LTM_CFLAGS += -O3 -funroll-loops
8685
LTM_CFLAGS += -fomit-frame-pointer
8786
endif
8887

88+
ifdef COMPILE_LTO
89+
LTM_CFLAGS += -flto
90+
AR = $(subst clang,llvm-ar,$(subst gcc,gcc-ar,$(CC)))
91+
endif
92+
8993
endif # COMPILE_SIZE
9094

9195
ifneq ($(findstring clang,$(CC)),)

testme.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ _make()
107107
{
108108
echo -ne " Compile $1 $2"
109109
suffix=$(echo ${1}${2} | tr ' ' '_')
110-
CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS $3 $MAKE_OPTIONS > /dev/null 2>gcc_errors_${suffix}.log
110+
CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS $3 $MAKE_OPTIONS 2>gcc_errors_${suffix}.log
111111
errcnt=$(wc -l < gcc_errors_${suffix}.log)
112112
if [[ ${errcnt} -gt 1 ]]; then
113113
echo " failed"
@@ -354,7 +354,7 @@ _banner
354354
if [[ "$TEST_VS_MTEST" != "" ]]
355355
then
356356
make clean > /dev/null
357-
_make "${compilers[0]} ${archflags[0]}" "$CFLAGS" "mtest_opponent"
357+
_make "${compilers[0]}" "${archflags[0]} $CFLAGS" "mtest_opponent"
358358
echo
359359
_make "gcc" "$MTEST_RAND" "mtest"
360360
echo
@@ -394,15 +394,15 @@ do
394394
fi
395395
if [[ "$VALGRIND_BIN" != "" ]]
396396
then
397-
_runvalgrind "$i $a" "$CFLAGS"
397+
_runvalgrind "$i" "$a $CFLAGS"
398398
[ "$WITH_LOW_MP" != "1" ] && continue
399-
_runvalgrind "$i $a" "-DMP_16BIT $CFLAGS"
400-
_runvalgrind "$i $a" "-DMP_32BIT $CFLAGS"
399+
_runvalgrind "$i" "$a -DMP_16BIT $CFLAGS"
400+
_runvalgrind "$i" "$a -DMP_32BIT $CFLAGS"
401401
else
402-
_runtest "$i $a" "$CFLAGS"
402+
_runtest "$i" "$a $CFLAGS"
403403
[ "$WITH_LOW_MP" != "1" ] && continue
404-
_runtest "$i $a" "-DMP_16BIT $CFLAGS"
405-
_runtest "$i $a" "-DMP_32BIT $CFLAGS"
404+
_runtest "$i" "$a -DMP_16BIT $CFLAGS"
405+
_runtest "$i" "$a -DMP_32BIT $CFLAGS"
406406
fi
407407
done
408408
done

0 commit comments

Comments
 (0)