Skip to content

Commit 9440c18

Browse files
committed
merge bitcoin#29180: remove use of BUILD_BITCOIN_INTERNAL macro in sha256
1 parent 68f6bea commit 9440c18

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/Makefile.am

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ LIBBITCOIN_WALLET_TOOL=libbitcoin_wallet_tool.a
7373
endif
7474

7575
LIBBITCOIN_CRYPTO = $(LIBBITCOIN_CRYPTO_BASE)
76+
if USE_ASM
77+
LIBBITCOIN_CRYPTO_SSE4 = crypto/libbitcoin_crypto_sse4.la
78+
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_SSE4)
79+
endif
7680
if ENABLE_SSE41
7781
LIBBITCOIN_CRYPTO_SSE41 = crypto/libbitcoin_crypto_sse41.la
7882
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_SSE41)
@@ -642,6 +646,10 @@ libbitcoin_wallet_tool_a_SOURCES = \
642646
$(BITCOIN_CORE_H)
643647

644648
# crypto primitives library
649+
650+
# crypto_base contains the unspecialized (unoptimized) versions of our
651+
# crypto functions. Functions that require custom compiler flags and/or
652+
# runtime opt-in are omitted.
645653
crypto_libbitcoin_crypto_base_la_CPPFLAGS = $(AM_CPPFLAGS) $(PIC_FLAGS)
646654

647655
# Specify -static in both CXXFLAGS and LDFLAGS so libtool will only build a
@@ -684,9 +692,12 @@ crypto_libbitcoin_crypto_base_la_SOURCES = \
684692
crypto/siphash.cpp \
685693
crypto/siphash.h
686694

687-
if USE_ASM
688-
crypto_libbitcoin_crypto_base_la_SOURCES += crypto/sha256_sse4.cpp
689-
endif
695+
# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and
696+
# CXXFLAGS above
697+
crypto_libbitcoin_crypto_sse4_la_LDFLAGS = $(AM_LDFLAGS) -static
698+
crypto_libbitcoin_crypto_sse4_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static
699+
crypto_libbitcoin_crypto_sse4_la_CPPFLAGS = $(AM_CPPFLAGS)
700+
crypto_libbitcoin_crypto_sse4_la_SOURCES = crypto/sha256_sse4.cpp
690701

691702
# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and
692703
# CXXFLAGS above
@@ -1001,7 +1012,7 @@ libdashconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_bas
10011012

10021013
libdashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
10031014
libdashconsensus_la_LIBADD = $(LIBDASHBLS) $(LIBSECP256K1) $(GMP_LIBS)
1004-
libdashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL
1015+
libdashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL -DDISABLE_OPTIMIZED_SHA256
10051016
libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/dashbls/include -isystem$(srcdir)/dashbls/depends/relic/include -isystem$(srcdir)/dashbls/depends/minialloc/include
10061017
libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/immer
10071018
libdashconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

src/crypto/sha256.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
#include <assert.h>
99
#include <string.h>
1010

11+
#if !defined(DISABLE_OPTIMIZED_SHA256)
1112
#include <compat/cpuid.h>
1213

13-
#if defined(__linux__) && defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
14+
#if defined(__linux__) && defined(ENABLE_ARM_SHANI)
1415
#include <sys/auxv.h>
1516
#include <asm/hwcap.h>
1617
#endif
1718

18-
#if defined(MAC_OSX) && defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
19+
#if defined(MAC_OSX) && defined(ENABLE_ARM_SHANI)
1920
#include <sys/types.h>
2021
#include <sys/sysctl.h>
2122
#endif
@@ -58,6 +59,7 @@ namespace sha256d64_arm_shani
5859
{
5960
void Transform_2way(unsigned char* out, const unsigned char* in);
6061
}
62+
#endif // DISABLE_OPTIMIZED_SHA256
6163

6264
// Internal implementation code.
6365
namespace
@@ -567,6 +569,7 @@ bool SelfTest() {
567569
return true;
568570
}
569571

572+
#if !defined(DISABLE_OPTIMIZED_SHA256)
570573
#if defined(USE_ASM) && (defined(__x86_64__) || defined(__amd64__) || defined(__i386__))
571574
/** Check whether the OS has enabled AVX registers. */
572575
bool AVXEnabled()
@@ -576,6 +579,7 @@ bool AVXEnabled()
576579
return (a & 6) == 6;
577580
}
578581
#endif
582+
#endif // DISABLE_OPTIMIZED_SHA256
579583
} // namespace
580584

581585

@@ -588,6 +592,7 @@ std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implem
588592
TransformD64_4way = nullptr;
589593
TransformD64_8way = nullptr;
590594

595+
#if !defined(DISABLE_OPTIMIZED_SHA256)
591596
#if defined(USE_ASM) && defined(HAVE_GETCPUID)
592597
bool have_sse4 = false;
593598
bool have_xsave = false;
@@ -616,7 +621,7 @@ std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implem
616621
}
617622
}
618623

619-
#if defined(ENABLE_X86_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
624+
#if defined(ENABLE_X86_SHANI)
620625
if (have_x86_shani) {
621626
Transform = sha256_x86_shani::Transform;
622627
TransformD64 = TransformD64Wrapper<sha256_x86_shani::Transform>;
@@ -633,21 +638,21 @@ std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implem
633638
TransformD64 = TransformD64Wrapper<sha256_sse4::Transform>;
634639
ret = "sse4(1way)";
635640
#endif
636-
#if defined(ENABLE_SSE41) && !defined(BUILD_BITCOIN_INTERNAL)
641+
#if defined(ENABLE_SSE41)
637642
TransformD64_4way = sha256d64_sse41::Transform_4way;
638643
ret += ",sse41(4way)";
639644
#endif
640645
}
641646

642-
#if defined(ENABLE_AVX2) && !defined(BUILD_BITCOIN_INTERNAL)
647+
#if defined(ENABLE_AVX2)
643648
if (have_avx2 && have_avx && enabled_avx) {
644649
TransformD64_8way = sha256d64_avx2::Transform_8way;
645650
ret += ",avx2(8way)";
646651
}
647652
#endif
648653
#endif // defined(USE_ASM) && defined(HAVE_GETCPUID)
649654

650-
#if defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
655+
#if defined(ENABLE_ARM_SHANI)
651656
bool have_arm_shani = false;
652657
if (use_implementation & sha256_implementation::USE_SHANI) {
653658
#if defined(__linux__)
@@ -679,6 +684,7 @@ std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implem
679684
ret = "arm_shani(1way,2way)";
680685
}
681686
#endif
687+
#endif // DISABLE_OPTIMIZED_SHA256
682688

683689
assert(SelfTest());
684690
return ret;

0 commit comments

Comments
 (0)