WHOLE_ARCHIVE portability

Hello,

Does anyone perhaps know how portable is the WHOLE_ARCHIVE feature when linking static libraries and where it could cause issues? It uses the linker flags such as --whole-archive,
/WHOLEARCHIVE etc.

target_link_libraries(app PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,foo>)

Or is it still better to go with OBJECT libraries instead and linking target objects separately?

Because it seems to me there is quite common issue, where linking a project STATIC library into executable doesn’t add unused objects to the final binary. For example, if they are used only in some SHARED library later on (which is loaded dynamically to the executable), or when linking other STATIC libraries created during the build to the main project STATIC library. In such cases, the whole archive feature would be very useful.

In other words, from a linker and compiler point of view, is there any difference in the produced binary between this:

add_library(foo STATIC foo.c ...)
add_executable(app app.c ...)
target_link_libraries(app PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,foo>)

and this:

add_library(foo OBJECT foo.c ...)
add_executable(app app.c ...)
target_link_libraries(app PRIVATE foo)

Thank you for any idea or pointer here.