@@ -212,20 +212,6 @@ if (LIBCXX_ENABLE_SHARED)
212
212
cxx_add_common_build_flags (cxx_shared )
213
213
cxx_set_common_defines (cxx_shared )
214
214
215
- # Link against LLVM libunwind
216
- # Note that we do need to link against libunwind directly to ensure that the correct
217
- # dependencies are recorded when creating a linker script.
218
- # TODO: Look into modifying the linker script creation to recursively consider interface libraries
219
- if (LIBCXXABI_USE_LLVM_UNWINDER )
220
- if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY )
221
- # libunwind is already included in libc++abi
222
- elseif (TARGET unwind_shared OR HAVE_LIBUNWIND )
223
- target_link_libraries (cxx_shared PUBLIC unwind_shared )
224
- else ()
225
- target_link_libraries (cxx_shared PUBLIC unwind )
226
- endif ()
227
- endif ()
228
-
229
215
# Link against libc++abi
230
216
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY )
231
217
target_link_libraries (cxx_shared PRIVATE libcxx-abi-shared-objects )
@@ -254,8 +240,30 @@ if (LIBCXX_ENABLE_SHARED)
254
240
255
241
# Generate a linker script in place of a libc++.so symlink.
256
242
if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT )
257
- include (DefineLinkerScript )
258
- define_linker_script (cxx_shared )
243
+ set (link_libraries )
244
+
245
+ set (imported_libname "$<TARGET_PROPERTY:libcxx-abi-shared,IMPORTED_LIBNAME>" )
246
+ set (output_name "$<TARGET_PROPERTY:libcxx-abi-shared,OUTPUT_NAME>" )
247
+ string (APPEND link_libraries "${CMAKE_LINK_LIBRARY_FLAG} $<IF:$<BOOL:${imported_libname} >,${imported_libname} ,${output_name} >" )
248
+
249
+ # TODO: Move to the same approach as above for the unwind library
250
+ if (LIBCXXABI_USE_LLVM_UNWINDER )
251
+ if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY )
252
+ # libunwind is already included in libc++abi
253
+ elseif (TARGET unwind_shared OR HAVE_LIBUNWIND )
254
+ string (APPEND link_libraries " ${CMAKE_LINK_LIBRARY_FLAG} $<TARGET_PROPERTY:unwind_shared,OUTPUT_NAME>" )
255
+ else ()
256
+ string (APPEND link_libraries " ${CMAKE_LINK_LIBRARY_FLAG} unwind" )
257
+ endif ()
258
+ endif ()
259
+
260
+ set (linker_script "INPUT($<TARGET_SONAME_FILE_NAME:cxx_shared> ${link_libraries} )" )
261
+ add_custom_command (TARGET cxx_shared POST_BUILD
262
+ COMMAND "${CMAKE_COMMAND} " -E remove "$<TARGET_LINKER_FILE:cxx_shared>"
263
+ COMMAND "${CMAKE_COMMAND} " -E echo "${linker_script} " > "$<TARGET_LINKER_FILE:cxx_shared>"
264
+ COMMENT "Generating linker script: '${linker_script} ' as file $<TARGET_LINKER_FILE:cxx_shared>"
265
+ VERBATIM
266
+ )
259
267
endif ()
260
268
261
269
list (APPEND LIBCXX_BUILD_TARGETS "cxx_shared" )
0 commit comments