================
@@ -137,10 +179,41 @@ function(llvm_update_pch name)
# Set priority so that dependants can reuse the PCH.
math(EXPR pch_priority "${pch_priority} + 1")
set_target_properties(${name} PROPERTIES LLVM_PCH_PRIORITY
${pch_priority})
+ # Record the export mode this PCH was compiled in and the headers it
used,
+ # so a dependant in a different mode can build its own PCH instead of
+ # reusing this one.
+ set_target_properties(${name} PROPERTIES
+ LLVM_PCH_MODE "${pch_mode}"
+ LLVM_PCH_HEADER "${ARG_PRECOMPILE_HEADERS}")
endif()
elseif(pch_reuse AND NOT ARG_DISABLE_PCH_REUSE)
- message(DEBUG "Using PCH ${pch_reuse} for ${name} (prio ${pch_priority})")
- target_precompile_headers(${name} REUSE_FROM ${pch_reuse})
+ get_target_property(reuse_mode ${pch_reuse} LLVM_PCH_MODE)
+ # Mode comparison is the single source of truth. When LLVM export
+ # annotations are off, every LLVM target's mode is uniformly "static" (see
+ # above), so this still reuses as before -- unless an ABI tag (e.g.
clang's)
+ # makes the consumer's mode differ from the provider's.
+ if(pch_mode STREQUAL "${reuse_mode}")
+ # Same export mode: reuse the provider's PCH. Its _PchSym_ object lives
in
+ # the provider, which this target links (the provider was found among our
+ # link dependencies), so it is present in our image.
+ message(DEBUG "Using PCH ${pch_reuse} for ${name} (prio
${pch_priority})")
+ target_precompile_headers(${name} REUSE_FROM ${pch_reuse})
+ else()
+ # Different export mode: the provider's PCH bakes the wrong dllexport/
+ # dllimport state (MSVC warns C4651, then miscompiles). It is also unsafe
+ # to reuse at link time -- with the dylib the provider is reached through
+ # LLVM.dll, so its _PchSym_ object is not in our image (LNK2011). Build
+ # our own PCH from the same header(s): compiled with this target's flags
+ # it matches, and its _PchSym_ lives in this target's own objects.
+ get_target_property(reuse_header ${pch_reuse} LLVM_PCH_HEADER)
+ if(reuse_header)
+ message(DEBUG "Building own ${pch_mode}-mode PCH for ${name}")
+ target_precompile_headers(${name} PRIVATE
+ $<$<COMPILE_LANGUAGE:CXX>:${reuse_header}>)
----------------
Steelskin wrote:
Doh, you are right. Sorry about that!
I am going to spend some more time on this and I'll re-open when I have an
actual fix for the underlying issue.
https://github.com/llvm/llvm-project/pull/208235
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits