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

Will Hawkins via libcxx-commits libcxx-commits at lists.llvm.org
Wed Apr 17 19:15:53 PDT 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:

I believe that I have addressed this in the latest revision. I added support for error messages to indicate to the user that they might be missing a linker map if they are attempting to run the `generate-cxx-abilist` target without having first built `libcxx`. That solves the chicken-egg problem mentioned above by simply assuming that if the user is building on macOS then they are going to have a linker map file available. 

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


More information about the libcxx-commits mailing list