[libcxx-commits] [libcxx] [libcxx] Support ABI symbol sizes on macOS (PR #75623)

Will Hawkins via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 30 21:51:19 PST 2024


================
@@ -227,6 +229,21 @@ if (LIBCXX_ENABLE_SHARED)
     target_link_libraries(cxx_shared PUBLIC libcxx-abi-shared)
   endif()
 
+  if (APPLE)
+    # If we are on an Apple platform, let's ask the linker to generate a map
+    # that we can use to determine the size of the abi symbols (see generate-cxx-abilist target).
+    target_link_libraries(cxx_shared PRIVATE "-Wl,-map,${CMAKE_CURRENT_BINARY_DIR}/../lib/abi/linker.map")
+    # Use CMAKE_CONFIGURE_DEPENDS so that CMake will regenerate if/when the map file changes.
+    # Regeneration is important because the addition of the --mapfile option (see lib/abi/CMakeLists.txt)
+    # to generate_abi_list.py depends on the file's existence. Unfortunately, there is a limitation in
+    # CMAKE_CONFIGURE_DEPENDS where regeneration is not triggered when a file that previously did
+    # not exist is generated. As a workaround, "touch" an empty file.
+    if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/../lib/abi/linker.map")
+      file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/../lib/abi/linker.map")
+    endif()
+    set_property(DIRECTORY . APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/../lib/abi/linker.map")
+  endif()
+
----------------
hawkinsw wrote:

@ldionne I think that this is an odd workaround but it is required so that the abi-list-generation process can handle the absence of a map file. That absence might happen because the user deletes it from their build directory or something else. 

If you think that this process is too complicated, we can just change the `EXISTS` check in `lib/abi/CMakeLists.txt` to an Apple-platform test and assume that the map file exists. I am happy either way.

https://github.com/llvm/llvm-project/pull/75623


More information about the libcxx-commits mailing list