[Flang] Fix BUILD_SHARED_LIBS build (#155422)
In contrast to linking a static library, when linking a shared library
all referenced symbols must be available in either the objects files,
static libraries, or shared libraries passed to the linker command line
and cannot be deferred to when building the executable.
Fixes #150027
Same fix as included in #152223, but with only the changes necessary to
fix #150027 (which is unrelated to GCC 15)