Skip to content

Commit

Permalink
mkdef on Linux for 3.0
Browse files Browse the repository at this point in the history
Signed-off-by: Fs <[email protected]>
  • Loading branch information
Fs committed Jan 28, 2024
1 parent 81b7a47 commit 0650677
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 23 deletions.
10 changes: 10 additions & 0 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,16 @@ if (WIN32)
ARCHIVE_OUTPUT_NAME libcrypto
)
endif()
elseif ( ( CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang" ) AND NOT APPLE )
add_custom_command(
OUTPUT crypto.ld
COMMAND "${CMAKE_COMMAND}" -DNUMFILE="${CMAKE_SOURCE_DIR}/openssl/util/libcrypto.num" -DLIBRARY_FILE="${LIBCRYPTO_RUNTIME_OUTPUT_NAME}" -DBINARY_DIR="${CMAKE_BINARY_DIR}" -DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/crypto.ld" -DPLATFORM=ELF -P "${CMAKE_CURRENT_SOURCE_DIR}/mkdef.cmake"
MAIN_DEPENDENCY "${CMAKE_SOURCE_DIR}/openssl/util/libcrypto.num"
DEPENDS mkdef.cmake
)
add_custom_target(crypto_map SOURCES crypto.ld)
add_dependencies(crypto crypto_map)
target_link_options(crypto PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_BINARY_DIR}/crypto.ld")
endif()
set_target_properties(crypto PROPERTIES
SOVERSION 3
Expand Down
85 changes: 62 additions & 23 deletions crypto/mkdef.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# -DLIBRARY_FILE=LIBEAY32 / SSLEAY32
# -DBINARY_DIR=<output-directory>
# -DOUTPUT_FILE=output.def
# -DPLATFORM=<platform> - currently only WIN32 is recognized, other possible value maybe "VMS" / "VOS" / "__FreeBSD__"...
# -DPLATFORM=<platform> - currently only "_WIN32" and "ELF" are recognized, other possible value maybe "VMS" / "VOS" / "__FreeBSD__"...
# -P <this cmake>

# Depends on CMake 3.17 which is the version CMake supports load_cache in CMake -P mode
Expand All @@ -26,7 +26,7 @@ foreach(CONTENT_ITEM IN LISTS NUMFILE_CONTENT)
if (CMAKE_MATCH_4 STREQUAL "EXIST")
set("CONTENT_ITEM_${I}_SYMBOL" "${CMAKE_MATCH_1}")
set("CONTENT_ITEM_${I}_PLACE" "${CMAKE_MATCH_2}")
# set("CONTENT_ITEM_${I}_VERSION" "${CMAKE_MATCH_3}") # Useless on Windows
set("CONTENT_ITEM_${I}_VERSION" "${CMAKE_MATCH_3}")
set("CONTENT_ITEM_${I}_PLATFORM" "${CMAKE_MATCH_5}")
# set("CONTENT_ITEM_${I}_TYPE" "${CMAKE_MATCH_6}") # Useless on Windows
set("CONTENT_ITEM_${I}_CONDITION" "${CMAKE_MATCH_7}")
Expand Down Expand Up @@ -146,43 +146,36 @@ endwhile()
# The needed symbols should be unique now!
set(I 0)
set(SYMBOLS)
set(VERSIONS)
while (I LESS CONTENT_LENGTH)
if (NOT DEFINED CONTENT_ITEM_${I}_SUPPRESS)
if (NOT "${CONTENT_ITEM_${I}_SYMBOL}" IN_LIST SYMBOLS)
set("PLACE_FOR_${CONTENT_ITEM_${I}_SYMBOL}" "${CONTENT_ITEM_${I}_PLACE}")
set("VERSION_FOR_${CONTENT_ITEM_${I}_SYMBOL}" "${CONTENT_ITEM_${I}_VERSION}")
list(APPEND SYMBOLS "${CONTENT_ITEM_${I}_SYMBOL}")
list(APPEND VERSIONS "${CONTENT_ITEM_${I}_VERSION}")
else()
message(WARNING "Duplicated symbol: ${CONTENT_ITEM_${I}_SYMBOL}. The one with place ${CONTENT_ITEM_${I}_PLACE} is ignored.")
endif()
endif()
math(EXPR I "${I} + 1")
endwhile()
list(SORT SYMBOLS)
list(SORT VERSIONS)
list(REMOVE_DUPLICATES VERSIONS)

# Finally generate the output file
# S: symbol
# SL: length of the symbol
# WL: length of the whitespaces
# W: whitespaces
set(EXPORT_TABLE)
foreach (S IN LISTS SYMBOLS)
string(LENGTH "${S}" SL)
math(EXPR WL "40 - ${SL}")
if (WL LESS 1)
set(WL 1)
endif()
string(REPEAT " " "${WL}" W)
string(APPEND EXPORT_TABLE " ${S}
if (PLATFORM STREQUAL "_WIN32")
set(EXPORT_TABLE)
foreach (S IN LISTS SYMBOLS)
string(APPEND EXPORT_TABLE " ${S}
")
unset(SL)
unset(WL)
unset(W)
endforeach()
endforeach()

if (NOT DEFINED OUTPUT_FILE)
message(NOTICE "${EXPORT_TABLE}")
else()
file(WRITE "${OUTPUT_FILE}" "; Generated by mkdef.cmake
if (NOT DEFINED OUTPUT_FILE)
message(NOTICE "${EXPORT_TABLE}")
else()
file(WRITE "${OUTPUT_FILE}" "; Generated by mkdef.cmake
; Definition file for the DLL version of the ${LIBRARY_FILE} library from OpenSSL
;
LIBRARY ${LIBRARY_FILE}
Expand All @@ -191,4 +184,50 @@ EXPORTS
${EXPORT_TABLE}
")
endif()
elseif (PLATFORM STREQUAL "ELF")
set(EXPORT_TABLE)
list(LENGTH VERSIONS VERSIONS_LENGTH)
math(EXPR VERSION_LENGTH1 "${VERSIONS_LENGTH} - 1")
set(I 0)
while (I LESS VERSIONS_LENGTH)
list(GET VERSIONS "${I}" VERSION_C)
if (NOT VERSION_C STREQUAL "*")
string(APPEND EXPORT_TABLE "OPENSSL_${VERSION_C} ")
endif()
string(APPEND EXPORT_TABLE "{
global:
")
foreach (S IN LISTS SYMBOLS)
if (VERSION_FOR_${S} STREQUAL VERSION_C)
string(APPEND EXPORT_TABLE " ${S};
")
endif()
endforeach()

if (I EQUAL VERSION_LENGTH1)
string(APPEND EXPORT_TABLE " local: *;
")
endif()

string(APPEND EXPORT_TABLE "}")

if (I GREATER 0)
math(EXPR I1 "${I} - 1")
list(GET VERSIONS "${I1}" VERSION_C1)
string(APPEND EXPORT_TABLE " OPENSSL_${VERSION_C1}")
endif()

string(APPEND EXPORT_TABLE ";
")

math(EXPR I "${I} + 1")
endwhile()

if (NOT DEFINED OUTPUT_FILE)
message(NOTICE "${EXPORT_TABLE}")
else()
file(WRITE "${OUTPUT_FILE}" "${EXPORT_TABLE}")
endif()
endif()
11 changes: 11 additions & 0 deletions engines/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ if (OPENSSL_HW AND OPENSSL_ENGINE AND BUILD_SHARED_LIBS AND OPENSSL_DYNAMIC_ENGI
target_link_libraries(${_ENGINE}
PUBLIC crypto
)
if ( NOT WIN32 AND ( CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang" ) AND NOT APPLE )
add_custom_command(
OUTPUT ${_ENGINE}.ld
COMMAND "${CMAKE_COMMAND}" -DNUMFILE="${CMAKE_SOURCE_DIR}/openssl/util/engines.num" -DLIBRARY_FILE="${_ENGINE}" -DBINARY_DIR="${CMAKE_BINARY_DIR}" -DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/${_ENGINE}.ld" -DPLATFORM=ELF -P "${CMAKE_CURRENT_SOURCE_DIR}/../crypto/mkdef.cmake"
MAIN_DEPENDENCY "${CMAKE_SOURCE_DIR}/openssl/util/engines.num"
DEPENDS ../crypto/mkdef.cmake
)
add_custom_target(${_ENGINE}_map SOURCES ${_ENGINE}.ld)
add_dependencies(${_ENGINE} ${_ENGINE}_map)
target_link_options(${_ENGINE} PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_BINARY_DIR}/${_ENGINE}.ld")
endif()
if (_OPTION STREQUAL "loader")
target_compile_definitions(${_ENGINE} PRIVATE OPENSSL_NO_PROVIDER_CODE)
endif()
Expand Down
12 changes: 12 additions & 0 deletions providers/legacy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ set_target_properties(legacy PROPERTIES
PREFIX ""
)

if ( OPENSSL_MODULE AND NOT WIN32 AND ( CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang" ) AND NOT APPLE )
add_custom_command(
OUTPUT legacy.ld
COMMAND "${CMAKE_COMMAND}" -DNUMFILE="${CMAKE_SOURCE_DIR}/openssl/util/providers.num" -DLIBRARY_FILE="legacy" -DBINARY_DIR="${CMAKE_BINARY_DIR}" -DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/legacy.ld" -DPLATFORM=ELF -P "${CMAKE_CURRENT_SOURCE_DIR}/../../crypto/mkdef.cmake"
MAIN_DEPENDENCY "${CMAKE_SOURCE_DIR}/openssl/util/providers.num"
DEPENDS ../../crypto/mkdef.cmake
)
add_custom_target(legacy_map SOURCES legacy.ld)
add_dependencies(legacy legacy_map)
target_link_options(legacy PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_BINARY_DIR}/legacy.ld")
endif()

target_include_directories(legacy
PRIVATE ${CMAKE_SOURCE_DIR}/openssl/providers/implementations/include
${CMAKE_SOURCE_DIR}/openssl/providers/common/include
Expand Down
10 changes: 10 additions & 0 deletions ssl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ if (WIN32)
ARCHIVE_OUTPUT_NAME libssl
)
endif()
elseif ( ( CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang" ) AND NOT APPLE )
add_custom_command(
OUTPUT ssl.ld
COMMAND "${CMAKE_COMMAND}" -DNUMFILE="${CMAKE_SOURCE_DIR}/openssl/util/libssl.num" -DLIBRARY_FILE="${LIBCRYPTO_RUNTIME_OUTPUT_NAME}" -DBINARY_DIR="${CMAKE_BINARY_DIR}" -DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/ssl.ld" -DPLATFORM=ELF -P "${CMAKE_CURRENT_SOURCE_DIR}/../crypto/mkdef.cmake"
MAIN_DEPENDENCY "${CMAKE_SOURCE_DIR}/openssl/util/libssl.num"
DEPENDS ../crypto/mkdef.cmake
)
add_custom_target(ssl_map SOURCES ssl.ld)
add_dependencies(ssl ssl_map)
target_link_options(ssl PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_BINARY_DIR}/ssl.ld")
endif()
set_target_properties(ssl PROPERTIES
SOVERSION 3
Expand Down

0 comments on commit 0650677

Please sign in to comment.