Skip to content

Commit f55a6fd

Browse files
[mlir] Make sure that aggregate shared libraries define all of their symbols.
We were hitting issues on Linux where this was only being caught at runtime, and different linkers (BFD vs LLD) are differently strict in such situations. Such libraries will also fail to build properly on Windows (but test coverage of that is limited, so it is better to enforce globally). Differential Revision: https://reviews.llvm.org/D131911
1 parent 2819126 commit f55a6fd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

mlir/cmake/modules/AddMLIR.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function(add_mlir_pdll_library target inputFile ofn)
159159
" filepath: \"${LLVM_TARGET_DEFINITIONS_ABSOLUTE}\"\n"
160160
" includes: \"${CMAKE_CURRENT_SOURCE_DIR};${tblgen_includes}\"\n"
161161
)
162-
162+
163163
add_public_tablegen_target(${target})
164164
endfunction()
165165

@@ -490,6 +490,17 @@ function(add_mlir_aggregate name)
490490
${ARG_PUBLIC_LIBS}
491491
)
492492
target_sources(${name} PRIVATE ${_objects})
493+
494+
# Linux defaults to allowing undefined symbols in shared libraries whereas
495+
# many other platforms are more strict. We want these libraries to be
496+
# self contained, and we want any undefined symbols to be reported at
497+
# library construction time, not at library use, so make Linux strict too.
498+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
499+
target_link_options(${name} PRIVATE
500+
"LINKER:-z,defs"
501+
)
502+
endif()
503+
493504
# TODO: Should be transitive.
494505
set_target_properties(${name} PROPERTIES
495506
MLIR_AGGREGATE_EXCLUDE_LIBS "${_embed_libs}")

0 commit comments

Comments
 (0)