Skip to content

Commit

Permalink
Link libjitterentropy into libcrypto.a (aws#511)
Browse files Browse the repository at this point in the history
When building static FIPS build we were building a separate
`libjitterentropy.a` instead of linking it into `libcrypto.a`.
This hasn't caused any issues in our build and test system because
we had a `target_link_libraries` directive which instructs CMake
to always add `libjitterentropy.a` whenever `libcrypto.a` is linked
to another binary. However, if one tries to compile a program and link
it with `libcrypto.a` directly, the linker will complain about
missing symbol definitions from `libjitterentropy.a` and they will
have to link `libjitterentropy.a` as well. This should not be
a requirement, AWS-LC `libcrypto.a` should be a stand-alone library.
With this change we fix that.
  • Loading branch information
dkostic authored Sep 6, 2022
1 parent 08b279d commit ec233b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
14 changes: 6 additions & 8 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,12 @@ target_compile_definitions(crypto_objects PRIVATE BORINGSSL_IMPLEMENTATION)
add_dependencies(crypto_objects global_target)

function(build_libcrypto name module_source)
add_library(${name} $<TARGET_OBJECTS:crypto_objects> ${CRYPTO_FIPS_OBJECTS} ${module_source})
if(FIPS)
add_library(${name} $<TARGET_OBJECTS:crypto_objects> ${CRYPTO_FIPS_OBJECTS} ${module_source} $<TARGET_OBJECTS:jitterentropy>)
else()
add_library(${name} $<TARGET_OBJECTS:crypto_objects> ${CRYPTO_FIPS_OBJECTS} ${module_source})
endif()

add_dependencies(${name} global_target)

if(FIPS_DELOCATE OR FIPS_SHARED)
Expand All @@ -517,9 +522,6 @@ function(build_libcrypto name module_source)
target_link_libraries(${name} PUBLIC pthread)
endif()

if(FIPS)
target_link_libraries(${name} PRIVATE jitterentropy)
endif()
target_include_directories(${name} SYSTEM PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<INSTALL_INTERFACE:include>)
Expand Down Expand Up @@ -708,10 +710,6 @@ if(BUILD_TESTING)
add_dependencies(${CRYPTO_TEST_EXEC} global_target)

target_link_libraries(${CRYPTO_TEST_EXEC} test_support_lib boringssl_gtest crypto)
if(FIPS)
target_link_libraries(${CRYPTO_TEST_EXEC} jitterentropy)
add_dependencies(${CRYPTO_TEST_EXEC} jitterentropy)
endif()
if(WIN32)
target_link_libraries(${CRYPTO_TEST_EXEC} ws2_32)
endif()
Expand Down
10 changes: 2 additions & 8 deletions third_party/jitterentropy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ if(MSVC)
else()
set(JITTER_COMPILE_FLAGS "-DAWSLC -fwrapv --param ssp-buffer-size=4 -fvisibility=hidden -fPIE -Wcast-align -Wmissing-field-initializers -Wshadow -Wswitch-enum -Wextra -Wall -pedantic -fPIC -O0 -fwrapv -Wconversion")
endif()

set_source_files_properties(${JITTER_SOURCES} PROPERTIES COMPILE_FLAGS ${JITTER_COMPILE_FLAGS})
add_library(jitterentropy STATIC ${JITTER_SOURCES})
add_library(jitterentropy OBJECT ${JITTER_SOURCES})

if(NOT BUILD_SHARED_LIBS)
install(TARGETS jitterentropy
EXPORT crypto-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

0 comments on commit ec233b8

Please sign in to comment.