Skip to content

Commit

Permalink
[OpenMP] generate the Windows import library that imports by name rather
Browse files Browse the repository at this point in the history
than ordinal

This check-in changes the OpenMP build script to generate the Windows
import library that imports by name rather than ordinal to reduce
ordinals order dependency and promote runtime flavors compatibility
going forward. The existing ordinals ordering is preserved to maintain
backward compatibility.

Differential Revision: https://reviews.llvm.org/D143431
  • Loading branch information
Vadim Paretsky (Intel Americas Inc) committed Feb 13, 2023
1 parent 96267b6 commit 06d9bf5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion openmp/runtime/cmake/LibompMicroTests.cmake
Expand Up @@ -40,7 +40,7 @@
# get library location
if(WIN32)
get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY)
get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ${LIBOMP_IMP_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY)
get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ompimp ARCHIVE_OUTPUT_DIRECTORY)
if(NOT LIBOMPIMP_OUTPUT_DIRECTORY)
set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
Expand Down
53 changes: 24 additions & 29 deletions openmp/runtime/src/CMakeLists.txt
Expand Up @@ -250,10 +250,6 @@ if(WIN32)
set_source_files_properties(thirdparty/ittnotify/ittnotify_static.cpp PROPERTIES COMPILE_DEFINITIONS "UNICODE")

# Create Windows import library
# the import library is "re-linked" to include kmp_import.cpp which prevents
# linking of both Visual Studio OpenMP and newly built OpenMP
set_source_files_properties(kmp_import.cpp PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_CXXFLAGS}")

# On debug LIBOMP_IMP_LIB_FILE should be LIBOMP_IMP_LIB_FILE_DBG = ${LIBOMP_DEFAULT_LIB_NAME_DBG}${CMAKE_STATIC_LIBRARY_SUFFIX}
# ${LIBOMP_DEFAULT_LIB_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX}
# and the ARCHIVE_OUTPUT_NAME of ompdbg should be ${LIBOMP_DEFAULT_LIB_NAME_DBG}${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
Expand All @@ -276,36 +272,35 @@ if(WIN32)
ARCHIVE_OUTPUT_NAME ${LIBOMP_GENERATED_IMP_LIB_FILENAME}
)

if(MSVC)
# Get generated import library from creating omp
get_target_property(LIBOMP_IMPORT_LIB_DIRECTORY omp ARCHIVE_OUTPUT_DIRECTORY)
if(LIBOMP_IMPORT_LIB_DIRECTORY)
set(LIBOMP_GENERATED_IMP_LIB ${LIBOMP_IMPORT_LIB_DIRECTORY}/${LIBOMP_GENERATED_IMP_LIB_FILENAME})
else()
set(LIBOMP_GENERATED_IMP_LIB ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_GENERATED_IMP_LIB_FILENAME})
endif()
set_source_files_properties(${LIBOMP_GENERATED_IMP_LIB} PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE)
# Create new import library that is just the previously created one + kmp_import.cpp
add_library(ompimp STATIC ${LIBOMP_GENERATED_IMP_LIB} kmp_import.cpp)
set_target_properties(ompimp PROPERTIES
PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}"
LINKER_LANGUAGE C
)
add_dependencies(ompimp omp) # ensure generated import library is created first
set(LIBOMP_IMP_LIB_TARGET ompimp)
else()
set(LIBOMP_IMP_LIB_TARGET omp)
endif()

# Create def file to designate exported functions
# Create def files to designate exported functions
libomp_get_gdflags(LIBOMP_GDFLAGS) # generate-def.pl flags (Windows only)
libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)
set(LIBOMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.def)
set(LIBOMPIMP_GENERATED_DEF_FILE_IMP ${LIBOMP_LIB_NAME}.imp.def)
add_custom_command(
OUTPUT ${LIBOMP_LIB_NAME}.def
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS}
-o ${LIBOMP_LIB_NAME}.def ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
# one with ordinals to use for building the runtime dll to maintain backwads compatible exports order
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE}
-o ${LIBOMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
# one without ordinals to use for building the import library to remove ordinal dependency going forward
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE} -D NOORDINALS
-o ${LIBOMPIMP_GENERATED_DEF_FILE_IMP} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
)

# Regenerate the import library to import by name, not ordinal
add_library(ompimp STATIC ${LIBOMP_SOURCE_FILES})
set_target_properties(ompimp PROPERTIES
PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}"
LINKER_LANGUAGE C
)
set_target_properties(ompimp PROPERTIES STATIC_LIBRARY_OPTIONS
"${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE_IMP}"
)
add_dependencies(ompimp libomp-needed-headers)


endif()

# Building the Fortran module files
Expand Down Expand Up @@ -362,7 +357,7 @@ add_dependencies(libomp-micro-tests libomp-test-deps)
# We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}
if(WIN32)
install(TARGETS omp RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
install(TARGETS ompimp ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
# Create aliases (regular copies) of the library for backwards compatibility
set(LIBOMP_ALIASES "libiomp5md")
foreach(alias IN LISTS LIBOMP_ALIASES)
Expand Down
16 changes: 11 additions & 5 deletions openmp/runtime/tools/generate-def.pl
Expand Up @@ -128,12 +128,16 @@ (\%)

}; # sub process

sub generate_output(\%$) {
sub generate_output(\%$\%) {

my ( $entries, $output ) = @_;
my ( $entries, $output, $defs ) = @_;
my $lib = %$defs {'NAME'};
my $bulk;

$bulk = "EXPORTS\n";
if (defined($lib)) {
$bulk = sprintf("NAME %s\n", $lib);
}
$bulk .= sprintf("EXPORTS\n");
foreach my $entry ( sort( keys( %$entries ) ) ) {
if ( not $entries->{ $entry }->{ obsolete } ) {
$bulk .= sprintf( " %-40s ", $entry );
Expand All @@ -142,7 +146,9 @@ (\%$)
if ( $ordinal eq "DATA" ) {
$bulk .= "DATA";
} else {
$bulk .= "\@" . $ordinal;
if (not %$defs {'NOORDINALS'}) {
$bulk .= "\@" . $ordinal;
}
}; # if
}; # if
$bulk .= "\n";
Expand Down Expand Up @@ -193,7 +199,7 @@ (\%$)

my %data = parse_input( $input, %defs );
%data = process( %data );
generate_output( %data, $output );
generate_output( %data, $output, %defs );
exit( 0 );

__END__
Expand Down

0 comments on commit 06d9bf5

Please sign in to comment.