Skip to content

Commit

Permalink
Fix symbol visibility issues on Linux for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanEngelen committed Jul 19, 2023
1 parent 89f43fd commit fde0bf8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ if(NOT WIN32 AND NOT CYGWIN)
# weak symbol Y means the weak symbol cannot be overridden at runtime. This was likely caused by
# different translation units being compiled with different visibility settings."
# See LLVM's cmake/modules/HandleLLVMOptions.cmake.
# For plugins, we shouldn't apply this flag because it hides the inline methods of e.g. Visitor.
check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
if (${SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG})
if (${SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG} AND NOT LDC_ENABLE_PLUGINS)
append("-fvisibility-inlines-hidden" LDC_CXXFLAGS)
endif()
endif()
Expand Down Expand Up @@ -683,10 +684,13 @@ if(LDC_ENABLE_PLUGINS)

if(LINKER_ACCEPTS_EXPORT_DYNAMIC_FLAG)
set(LDC_LINKERFLAG_LIST "${LDC_LINKERFLAG_LIST};-Wl,--export-dynamic")
else()
message(WARNING "Linker does not accept --export-dynamic, user plugins may give missing symbol errors upon load")
endif()
endif()
endif()
message(STATUS "-- Building LDC with plugin support (LDC_ENABLE_PLUGINS): ${LDC_ENABLE_PLUGINS}")
message(STATUS "-- Linking LDC with flags: ${ALTERNATIVE_MALLOC_O};${LDC_LINKERFLAG_LIST}")

build_d_executable(
"${LDC_EXE}"
Expand Down
5 changes: 3 additions & 2 deletions cmake/Modules/BuildDExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function(build_d_executable target_name output_exe d_src_files compiler_args lin
# Compile all D modules to a single object.
set(object_file ${PROJECT_BINARY_DIR}/obj/${target_name}${CMAKE_CXX_OUTPUT_EXTENSION})
# Default to -linkonce-templates with LDMD host compiler, to speed-up optimization.
if("${D_COMPILER_ID}" STREQUAL "LDMD")
# Note: for plugin support we need the symbols to be global, don't use -linkonce-templates.
if("${D_COMPILER_ID}" STREQUAL "LDMD" AND NOT LDC_ENABLE_PLUGINS)
set(dflags -linkonce-templates ${dflags})
endif()
add_custom_command(
Expand Down Expand Up @@ -105,7 +106,7 @@ function(build_d_executable target_name output_exe d_src_files compiler_args lin

add_custom_command(
OUTPUT ${output_exe}
COMMAND ${D_COMPILER} ${dflags} -of${output_exe} ${objects_args} ${dep_libs} ${translated_linker_args}
COMMAND ${D_COMPILER} ${dflags} -of${output_exe} ${objects_args} ${dep_libs} ${translated_linker_args} -fvisibility=public
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ${target_name}_d_objects ${object_files} ${link_deps}
)
Expand Down
11 changes: 5 additions & 6 deletions tests/plugins/lit.local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ if (config.plugins_supported):
config.substitutions.append( ('%plugin_compile_flags', " ".join(plugin_compile_flags) ) )

# Set feature that tells us that the just-built LDC is ABI compatible with the host D compiler
# Be conservative: only set it when host LDC and just-built LDC have identical versions
# For our tets, the required ABI compatibility is OK since LDC 1.18 (interface ptr).
# If the compiler is built not by LDC but another compiler, then assume the ABI to be incompatible.
command = [config.ldc2_bin, '--version']
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
text1 = p.stdout.readline() # Ex.: "LDC - the LLVM D compiler (1.33.0-git-716f627)"
text2 = p.stdout.readline() # Ex.: " based on DMD v2.103.1 and LLVM 14.0.0"
text3 = p.stdout.readline() # Ex.: " built with LDC - the LLVM D compiler (1.33.0-beta2)"
m = re.compile('LDC - the LLVM D compiler \((.*)\)').match(text1)
ldc_version = m.group(1)
m3 = re.compile(' built with.* \((.*)\)').match(text3)
host_version = m3.group(1)
if (ldc_version == host_version):
host_version = re.compile(' built with LDC.* \((1\.[0-9]+).*\)').match(text3).group(1)
print(host_version)
if (float(host_version) > 1.1799):
config.available_features.add('ABI_compatible_with_host_D')


0 comments on commit fde0bf8

Please sign in to comment.