Skip to content

Commit 631e688

Browse files
author
Sergei Ianovich
committed
CMake: link gost.so statically to its caller
If any executable loads `gost.so`, the executable already either has `libcrypto.so` loaded or is statically linked against `libcrypto.a`. Anyway it already has all libcrypto (and libssl) symbols present. Without this patch `gost.so` is linked against `libcrypto,so`. As a result, a diamond dependency is introduced. If `gost.so` is then loaded by an executable which is statically linked against libcrypto, `ld` will insist on loading `libcripto.so`, despite the executable already having all necessary symbols. When the executable is statically linked, shared objects for libcrypto and libssl are usually not built, `ls` won't find them, and the caller will crush. The patch removes this unnecessary link dependency in `gost.so`, allowing it to be used by executables which are statically linked against libcrypto.
1 parent bd6c4f8 commit 631e688

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

CMakeLists.txt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ set_tests_properties(ciphers-with-provider
248248

249249
# test_curves is an internals testing program, it doesn't need a test env
250250
add_executable(test_curves test_curves.c)
251-
target_link_libraries(test_curves gost_core gost_err)
251+
target_link_libraries(test_curves gost_core gost_err OpenSSL::Crypto)
252252
add_test(NAME curves COMMAND test_curves)
253253

254254
add_executable(test_params test_params.c)
@@ -287,12 +287,12 @@ set_tests_properties(context-with-provider
287287
# test_keyexpimp is an internals testing program, it doesn't need a test env
288288
add_executable(test_keyexpimp test_keyexpimp.c)
289289
#target_compile_definitions(test_keyexpimp PUBLIC -DOPENSSL_LOAD_CONF)
290-
target_link_libraries(test_keyexpimp gost_core gost_err)
290+
target_link_libraries(test_keyexpimp gost_core gost_err OpenSSL::Crypto)
291291
add_test(NAME keyexpimp COMMAND test_keyexpimp)
292292

293293
# test_gost89 is an internals testing program, it doesn't need a test env
294294
add_executable(test_gost89 test_gost89.c)
295-
target_link_libraries(test_gost89 gost_core gost_err)
295+
target_link_libraries(test_gost89 gost_core gost_err OpenSSL::Crypto)
296296
add_test(NAME gost89 COMMAND test_gost89)
297297

298298
if(NOT SKIP_PERL_TESTS)
@@ -313,7 +313,7 @@ endif()
313313

314314
if(NOT MSVC)
315315
add_executable(sign benchmark/sign.c)
316-
target_link_libraries(sign gost_core gost_err ${CLOCK_GETTIME_LIB})
316+
target_link_libraries(sign gost_core gost_err ${CLOCK_GETTIME_LIB} OpenSSL::Crypto)
317317
endif()
318318

319319
# All that may need to load just built engine will have path to it defined.
@@ -333,10 +333,15 @@ set_property(TARGET ${BINARY_TESTS_TARGETS} APPEND PROPERTY COMPILE_DEFINITIONS
333333

334334
add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
335335
set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
336-
target_link_libraries(gost_core PRIVATE OpenSSL::Crypto)
336+
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR MSVC)
337+
target_link_libraries(gost_core PRIVATE OpenSSL::Crypto)
338+
endif()
339+
337340
add_library(gost_err STATIC ${GOST_ERR_SOURCE_FILES})
338341
set_target_properties(gost_err PROPERTIES POSITION_INDEPENDENT_CODE ON)
339-
target_link_libraries(gost_err PRIVATE OpenSSL::Crypto)
342+
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR MSVC)
343+
target_link_libraries(gost_err PRIVATE OpenSSL::Crypto)
344+
endif()
340345

341346
# The GOST engine in module form
342347
add_library(gost_engine MODULE ${GOST_ENGINE_SOURCE_FILES})
@@ -353,7 +358,7 @@ set_target_properties(lib_gost_engine PROPERTIES
353358
COMPILE_DEFINITIONS "BUILDING_ENGINE_AS_LIBRARY"
354359
PUBLIC_HEADER gost-engine.h
355360
OUTPUT_NAME "gost")
356-
target_link_libraries(lib_gost_engine PRIVATE gost_core gost_err)
361+
target_link_libraries(lib_gost_engine PRIVATE gost_core gost_err OpenSSL::Crypto)
357362
endif()
358363

359364
# The GOST provider uses this
@@ -386,14 +391,14 @@ set(GOST_SUM_SOURCE_FILES
386391
)
387392

388393
add_executable(gostsum ${GOST_SUM_SOURCE_FILES})
389-
target_link_libraries(gostsum gost_core gost_err)
394+
target_link_libraries(gostsum gost_core gost_err OpenSSL::Crypto)
390395

391396
set(GOST_12_SUM_SOURCE_FILES
392397
gost12sum.c
393398
)
394399

395400
add_executable(gost12sum ${GOST_12_SUM_SOURCE_FILES})
396-
target_link_libraries(gost12sum gost_core gost_err)
401+
target_link_libraries(gost12sum gost_core gost_err OpenSSL::Crypto)
397402

398403
set_source_files_properties(tags PROPERTIES GENERATED true)
399404
add_custom_target(tags

0 commit comments

Comments
 (0)