Skip to content

Commit c74b874

Browse files
gen_context: Don't include library config files
Before this commit, gen_context.c both included libsecp256k1-config.h and basic-config.h: The former only to obtain ECMULT_GEN_PREC_BITS and the latter to obtain a basic working configuration to be able to use the library. This was inelegant and confusing: It meant that basic-config.h needs to #undef all the macros defined in libsecp256k1-config.h. Moreover, it meant that basic-config.h cannot define ECMULT_GEN_PREC_BITS, essentially making this file specific for use in gen_context.c. After this commit, gen_context.c does not include any configuration file. Now, ECMULT_GEN_PREC_BITS is expected to be passed via the command line and make will do this. Moreover, basic-config.h is not necessary anymore for the modules used in gen_context.c because 79f1f7a made the preprocessor detect all the relevant config options. On the way, we remove an unused #define in basic-config.h.
1 parent 1e5d50f commit c74b874

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

Makefile.am

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
128128

129129
gen_context_OBJECTS = gen_context.o
130130
gen_context_BIN = gen_context$(BUILD_EXEEXT)
131-
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
132-
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
131+
gen_context_CPPFLAGS = -DECMULT_GEN_PREC_BITS=$(ECMULT_GEN_PREC_BITS)
132+
133+
$(gen_context_OBJECTS): src/gen_context.c
134+
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(gen_context_CPPFLAGS) -c $< -o $@
133135

134136
$(gen_context_BIN): $(gen_context_OBJECTS)
135137
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@

configure.ac

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ fi
315315
case $set_ecmult_gen_precision in
316316
2|4|8)
317317
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
318+
AC_SUBST(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision)
318319
;;
319320
*)
320321
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])

src/basic-config.h

-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99

1010
#ifdef USE_BASIC_CONFIG
1111

12-
#undef USE_ASM_X86_64
13-
#undef USE_ECMULT_STATIC_PRECOMPUTATION
14-
#undef USE_EXTERNAL_ASM
15-
#undef USE_EXTERNAL_DEFAULT_CALLBACKS
16-
#undef USE_FORCE_WIDEMUL_INT64
17-
#undef USE_FORCE_WIDEMUL_INT128
18-
#undef ECMULT_WINDOW_SIZE
19-
20-
#define USE_WIDEMUL_64 1
2112
#define ECMULT_WINDOW_SIZE 15
2213

2314
#endif /* USE_BASIC_CONFIG */

src/gen_context.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
66

7-
/* Autotools creates libsecp256k1-config.h, of which ECMULT_GEN_PREC_BITS is needed.
8-
ifndef guard so downstream users can define their own if they do not use autotools. */
9-
#if !defined(ECMULT_GEN_PREC_BITS)
10-
#include "libsecp256k1-config.h"
11-
#endif
12-
#define USE_BASIC_CONFIG 1
13-
#include "basic-config.h"
14-
157
#include "include/secp256k1.h"
168
#include "assumptions.h"
179
#include "util.h"
@@ -20,6 +12,12 @@
2012
#include "group_impl.h"
2113
#include "ecmult_gen_impl.h"
2214

15+
/* It is tempting to include basic-config.h for a basic config to make the above
16+
modules work. But these modules currently do not need a config, except
17+
ECMULT_GEN_PREC_BITS, which we except to be passed on the compiler command
18+
line directly. We don't include basic-config.h because this file would
19+
attempt to redefine ECMULT_GEN_PREC_BITS. */
20+
2321
static void default_error_callback_fn(const char* str, void* data) {
2422
(void)data;
2523
fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);

0 commit comments

Comments
 (0)