Skip to content

Commit ad63bb4

Browse files
build: Prebuild and distribute ecmult_gen table
- Improve Makefile.am for both prebuilt tables files - On the way, tidy EXTRA_DIST: Move the header files to noinst_HEADERS, where they conceptually belong, and add missing SECURITY.md to EXTRA_DIST
1 parent ac49361 commit ad63bb4

5 files changed

+9776
-26
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
src/ecmult_static_pre_g.h linguist-generated
2+
src/ecmult_gen_static_prec_table.h linguist-generated

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ coverage.*.html
4141

4242
src/libsecp256k1-config.h
4343
src/libsecp256k1-config.h.in
44-
src/ecmult_static_context.h
4544
build-aux/config.guess
4645
build-aux/config.sub
4746
build-aux/depcomp

Makefile.am

+27-22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.PHONY: clean-precomp precomp
2+
13
ACLOCAL_AMFLAGS = -I build-aux/m4
24

35
# AM_CFLAGS will be automatically prepended to CFLAGS by Automake when compiling some foo
@@ -52,6 +54,7 @@ noinst_HEADERS += src/hash_impl.h
5254
noinst_HEADERS += src/field.h
5355
noinst_HEADERS += src/field_impl.h
5456
noinst_HEADERS += src/bench.h
57+
noinst_HEADERS += src/basic-config.h
5558
noinst_HEADERS += contrib/lax_der_parsing.h
5659
noinst_HEADERS += contrib/lax_der_parsing.c
5760
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
@@ -125,37 +128,39 @@ exhaustive_tests_LDFLAGS = -static
125128
TESTS += exhaustive_tests
126129
endif
127130

128-
EXTRA_PROGRAMS = gen_ecmult_static_pre_g
131+
### Precomputed tables
132+
EXTRA_PROGRAMS = gen_ecmult_static_pre_g gen_ecmult_gen_static_prec_table
133+
CLEANFILES = $(EXTRA_PROGRAMS)
129134
gen_ecmult_static_pre_g_SOURCES = src/gen_ecmult_static_pre_g.c
130-
# See Automake manual, Section "Errors with distclean"
135+
gen_ecmult_gen_static_prec_table_SOURCES = src/gen_ecmult_gen_static_prec_table.c
136+
137+
# See Automake manual, Section "Errors with distclean".
138+
# We don't list any dependencies for the prebuilt files here because
139+
# otherwise make's decision whether to rebuild them (even in the first
140+
# build by a normal user) depends on mtimes, and thus is very fragile.
141+
# This means that rebuilds of the prebuilt files always need to be
142+
# forced by deleting them, e.g., by invoking `make clean-precomp`.
131143
src/ecmult_static_pre_g.h:
132144
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_static_pre_g$(EXEEXT)
133145
./gen_ecmult_static_pre_g$(EXEEXT)
146+
src/ecmult_gen_static_prec_table.h:
147+
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_gen_static_prec_table$(EXEEXT)
148+
./gen_ecmult_gen_static_prec_table$(EXEEXT)
134149

135-
if USE_ECMULT_STATIC_PRECOMPUTATION
136-
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
137-
138-
gen_ecmult_gen_static_prec_table_OBJECTS = gen_ecmult_gen_static_prec_table.o
139-
gen_ecmult_gen_static_prec_table_BIN = gen_ecmult_gen_static_prec_table$(BUILD_EXEEXT)
140-
$(gen_ecmult_gen_static_prec_table_OBJECTS): src/gen_ecmult_gen_static_prec_table.c src/libsecp256k1-config.h
141-
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
150+
PRECOMP = src/ecmult_gen_static_prec_table.h src/ecmult_static_pre_g.h
151+
noinst_HEADERS += $(PRECOMP)
152+
precomp: $(PRECOMP)
142153

143-
$(gen_ecmult_gen_static_prec_table_BIN): $(gen_ecmult_gen_static_prec_table_OBJECTS)
144-
$(CC_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
154+
# Ensure the prebuilt files will be build first (only if they don't exist,
155+
# e.g., after `make maintainer-clean`).
156+
BUILT_SOURCES = $(PRECOMP)
145157

146-
$(libsecp256k1_la_OBJECTS): src/ecmult_gen_static_prec_table.h
147-
$(tests_OBJECTS): src/ecmult_gen_static_prec_table.h
148-
$(exhaustive_tests_OBJECTS): src/ecmult_gen_static_prec_table.h
149-
$(bench_internal_OBJECTS): src/ecmult_gen_static_prec_table.h
150-
$(bench_ecmult_OBJECTS): src/ecmult_gen_static_prec_table.h
158+
maintainer-clean-local: clean-precomp
151159

152-
src/ecmult_gen_static_prec_table.h: $(gen_ecmult_gen_static_prec_table_BIN)
153-
./$(gen_ecmult_gen_static_prec_table_BIN)
154-
155-
CLEANFILES = $(gen_ecmult_gen_static_prec_table_BIN) src/ecmult_gen_static_prec_table.h
156-
endif
160+
clean-precomp:
161+
rm -f $(PRECOMP)
157162

158-
EXTRA_DIST = autogen.sh src/gen_ecmult_gen_static_prec_table.c src/ecmult_static_pre_g.h src/basic-config.h
163+
EXTRA_DIST = autogen.sh SECURITY.md
159164

160165
if ENABLE_MODULE_ECDH
161166
include src/modules/ecdh/Makefile.am.include

configure.ac

-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ AC_ARG_ENABLE(exhaustive_tests,
125125
[use_exhaustive_tests=$enableval],
126126
[use_exhaustive_tests=yes])
127127

128-
# Force static precomputation. The code handling this will be removed in a later commit.
129-
use_ecmult_static_precomputation=yes
130-
131128
AC_ARG_ENABLE(module_ecdh,
132129
AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation]),
133130
[enable_module_ecdh=$enableval],

0 commit comments

Comments
 (0)