[libcxxabi] Use an explicit list to export symbols from the dylib

Reviewers: EricWF

Subscribers: mgorny, christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D63345

git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@364586 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/itanium-base.exp b/lib/itanium-base.exp
new file mode 100644
index 0000000..ff0f812
--- /dev/null
+++ b/lib/itanium-base.exp
@@ -0,0 +1,373 @@
+# Typeinfos for fundamental types
+__ZTIa
+__ZTIb
+__ZTIc
+__ZTId
+__ZTIDh
+__ZTIDi
+__ZTIDn
+__ZTIDs
+__ZTIDu
+__ZTIe
+__ZTIf
+__ZTIg
+__ZTIh
+__ZTIi
+__ZTIj
+__ZTIl
+__ZTIm
+__ZTIn
+__ZTIo
+__ZTIPa
+__ZTIPb
+__ZTIPc
+__ZTIPd
+__ZTIPDh
+__ZTIPDi
+__ZTIPDn
+__ZTIPDs
+__ZTIPDu
+__ZTIPe
+__ZTIPf
+__ZTIPg
+__ZTIPh
+__ZTIPi
+__ZTIPj
+__ZTIPKa
+__ZTIPKb
+__ZTIPKc
+__ZTIPKd
+__ZTIPKDh
+__ZTIPKDi
+__ZTIPKDn
+__ZTIPKDs
+__ZTIPKDu
+__ZTIPKe
+__ZTIPKf
+__ZTIPKg
+__ZTIPKh
+__ZTIPKi
+__ZTIPKj
+__ZTIPKl
+__ZTIPKm
+__ZTIPKn
+__ZTIPKo
+__ZTIPKs
+__ZTIPKt
+__ZTIPKv
+__ZTIPKw
+__ZTIPKx
+__ZTIPKy
+__ZTIPl
+__ZTIPm
+__ZTIPn
+__ZTIPo
+__ZTIPs
+__ZTIPt
+__ZTIPv
+__ZTIPw
+__ZTIPx
+__ZTIPy
+__ZTIs
+__ZTIt
+__ZTIv
+__ZTIw
+__ZTIx
+__ZTIy
+
+# Typeinfo names for fundamental types
+__ZTSa
+__ZTSb
+__ZTSc
+__ZTSd
+__ZTSDh
+__ZTSDi
+__ZTSDn
+__ZTSDs
+__ZTSDu
+__ZTSe
+__ZTSf
+__ZTSg
+__ZTSh
+__ZTSi
+__ZTSj
+__ZTSl
+__ZTSm
+__ZTSn
+__ZTSo
+__ZTSPa
+__ZTSPb
+__ZTSPc
+__ZTSPd
+__ZTSPDh
+__ZTSPDi
+__ZTSPDn
+__ZTSPDs
+__ZTSPDu
+__ZTSPe
+__ZTSPf
+__ZTSPg
+__ZTSPh
+__ZTSPi
+__ZTSPj
+__ZTSPKa
+__ZTSPKb
+__ZTSPKc
+__ZTSPKd
+__ZTSPKDh
+__ZTSPKDi
+__ZTSPKDn
+__ZTSPKDs
+__ZTSPKDu
+__ZTSPKe
+__ZTSPKf
+__ZTSPKg
+__ZTSPKh
+__ZTSPKi
+__ZTSPKj
+__ZTSPKl
+__ZTSPKm
+__ZTSPKn
+__ZTSPKo
+__ZTSPKs
+__ZTSPKt
+__ZTSPKv
+__ZTSPKw
+__ZTSPKx
+__ZTSPKy
+__ZTSPl
+__ZTSPm
+__ZTSPn
+__ZTSPo
+__ZTSPs
+__ZTSPt
+__ZTSPv
+__ZTSPw
+__ZTSPx
+__ZTSPy
+__ZTSs
+__ZTSt
+__ZTSv
+__ZTSw
+__ZTSx
+__ZTSy
+
+# Typeinfos for types from libc++abi
+__ZTIN10__cxxabiv116__enum_type_infoE
+__ZTIN10__cxxabiv116__shim_type_infoE
+__ZTIN10__cxxabiv117__array_type_infoE
+__ZTIN10__cxxabiv117__class_type_infoE
+__ZTIN10__cxxabiv117__pbase_type_infoE
+__ZTIN10__cxxabiv119__pointer_type_infoE
+__ZTIN10__cxxabiv120__function_type_infoE
+__ZTIN10__cxxabiv120__si_class_type_infoE
+__ZTIN10__cxxabiv121__vmi_class_type_infoE
+__ZTIN10__cxxabiv123__fundamental_type_infoE
+__ZTIN10__cxxabiv129__pointer_to_member_type_infoE
+
+# Typeinfo names for types from libc++abi
+__ZTSN10__cxxabiv116__enum_type_infoE
+__ZTSN10__cxxabiv116__shim_type_infoE
+__ZTSN10__cxxabiv117__array_type_infoE
+__ZTSN10__cxxabiv117__class_type_infoE
+__ZTSN10__cxxabiv117__pbase_type_infoE
+__ZTSN10__cxxabiv119__pointer_type_infoE
+__ZTSN10__cxxabiv120__function_type_infoE
+__ZTSN10__cxxabiv120__si_class_type_infoE
+__ZTSN10__cxxabiv121__vmi_class_type_infoE
+__ZTSN10__cxxabiv123__fundamental_type_infoE
+__ZTSN10__cxxabiv129__pointer_to_member_type_infoE
+
+# Typeinfos for std:: exception types
+__ZTISt10bad_typeid
+__ZTISt11logic_error
+__ZTISt11range_error
+__ZTISt12domain_error
+__ZTISt12length_error
+__ZTISt12out_of_range
+__ZTISt13bad_exception
+__ZTISt13runtime_error
+__ZTISt14overflow_error
+__ZTISt15underflow_error
+__ZTISt16invalid_argument
+__ZTISt20bad_array_new_length
+__ZTISt8bad_cast
+__ZTISt9bad_alloc
+__ZTISt9exception
+__ZTISt9type_info
+
+# Typeinfo names for std:: exception types
+__ZTSSt10bad_typeid
+__ZTSSt11logic_error
+__ZTSSt11range_error
+__ZTSSt12domain_error
+__ZTSSt12length_error
+__ZTSSt12out_of_range
+__ZTSSt13bad_exception
+__ZTSSt13runtime_error
+__ZTSSt14overflow_error
+__ZTSSt15underflow_error
+__ZTSSt16invalid_argument
+__ZTSSt20bad_array_new_length
+__ZTSSt8bad_cast
+__ZTSSt9bad_alloc
+__ZTSSt9exception
+__ZTSSt9type_info
+
+# Vtables for libc++abi types
+__ZTVN10__cxxabiv116__enum_type_infoE
+__ZTVN10__cxxabiv116__shim_type_infoE
+__ZTVN10__cxxabiv117__array_type_infoE
+__ZTVN10__cxxabiv117__class_type_infoE
+__ZTVN10__cxxabiv117__pbase_type_infoE
+__ZTVN10__cxxabiv119__pointer_type_infoE
+__ZTVN10__cxxabiv120__function_type_infoE
+__ZTVN10__cxxabiv120__si_class_type_infoE
+__ZTVN10__cxxabiv121__vmi_class_type_infoE
+__ZTVN10__cxxabiv123__fundamental_type_infoE
+__ZTVN10__cxxabiv129__pointer_to_member_type_infoE
+
+# Vtables for std:: exception types
+__ZTVSt10bad_typeid
+__ZTVSt11logic_error
+__ZTVSt11range_error
+__ZTVSt12domain_error
+__ZTVSt12length_error
+__ZTVSt12out_of_range
+__ZTVSt13bad_exception
+__ZTVSt13runtime_error
+__ZTVSt14overflow_error
+__ZTVSt15underflow_error
+__ZTVSt16invalid_argument
+__ZTVSt20bad_array_new_length
+__ZTVSt8bad_cast
+__ZTVSt9bad_alloc
+__ZTVSt9exception
+__ZTVSt9type_info
+
+# Itanium C++ ABI requirements
+___cxa_allocate_dependent_exception
+___cxa_allocate_exception
+___cxa_bad_cast
+___cxa_bad_typeid
+___cxa_begin_catch
+___cxa_call_unexpected
+___cxa_current_exception_type
+___cxa_current_primary_exception
+___cxa_decrement_exception_refcount
+___cxa_deleted_virtual
+___cxa_demangle
+___cxa_end_catch
+___cxa_free_dependent_exception
+___cxa_free_exception
+___cxa_get_exception_ptr
+___cxa_get_globals
+___cxa_get_globals_fast
+___cxa_guard_abort
+___cxa_guard_acquire
+___cxa_guard_release
+___cxa_increment_exception_refcount
+___cxa_pure_virtual
+___cxa_rethrow
+___cxa_rethrow_primary_exception
+___cxa_throw
+___cxa_throw_bad_array_new_length
+___cxa_uncaught_exception
+___cxa_uncaught_exceptions
+___cxa_vec_cctor
+___cxa_vec_cleanup
+___cxa_vec_ctor
+___cxa_vec_delete
+___cxa_vec_delete2
+___cxa_vec_delete3
+___cxa_vec_dtor
+___cxa_vec_new
+___cxa_vec_new2
+___cxa_vec_new3
+___dynamic_cast
+___cxa_terminate_handler
+___cxa_unexpected_handler
+___cxa_new_handler
+
+# ::what() functions for std:: exception types
+__ZNKSt10bad_typeid4whatEv
+__ZNKSt11logic_error4whatEv
+__ZNKSt13bad_exception4whatEv
+__ZNKSt13runtime_error4whatEv
+__ZNKSt20bad_array_new_length4whatEv
+__ZNKSt8bad_cast4whatEv
+__ZNKSt9bad_alloc4whatEv
+__ZNKSt9exception4whatEv
+
+# Default constructors and destructors for std:: exception types
+__ZNSt10bad_typeidC1Ev
+__ZNSt10bad_typeidC2Ev
+__ZNSt10bad_typeidD0Ev
+__ZNSt10bad_typeidD1Ev
+__ZNSt10bad_typeidD2Ev
+__ZNSt11logic_errorD0Ev
+__ZNSt11logic_errorD1Ev
+__ZNSt11logic_errorD2Ev
+__ZNSt11range_errorD0Ev
+__ZNSt11range_errorD1Ev
+__ZNSt11range_errorD2Ev
+__ZNSt12domain_errorD0Ev
+__ZNSt12domain_errorD1Ev
+__ZNSt12domain_errorD2Ev
+__ZNSt12length_errorD0Ev
+__ZNSt12length_errorD1Ev
+__ZNSt12length_errorD2Ev
+__ZNSt12out_of_rangeD0Ev
+__ZNSt12out_of_rangeD1Ev
+__ZNSt12out_of_rangeD2Ev
+__ZNSt13bad_exceptionD0Ev
+__ZNSt13bad_exceptionD1Ev
+__ZNSt13bad_exceptionD2Ev
+__ZNSt13runtime_errorD0Ev
+__ZNSt13runtime_errorD1Ev
+__ZNSt13runtime_errorD2Ev
+__ZNSt14overflow_errorD0Ev
+__ZNSt14overflow_errorD1Ev
+__ZNSt14overflow_errorD2Ev
+__ZNSt15underflow_errorD0Ev
+__ZNSt15underflow_errorD1Ev
+__ZNSt15underflow_errorD2Ev
+__ZNSt16invalid_argumentD0Ev
+__ZNSt16invalid_argumentD1Ev
+__ZNSt16invalid_argumentD2Ev
+__ZNSt20bad_array_new_lengthC1Ev
+__ZNSt20bad_array_new_lengthC2Ev
+__ZNSt20bad_array_new_lengthD0Ev
+__ZNSt20bad_array_new_lengthD1Ev
+__ZNSt20bad_array_new_lengthD2Ev
+__ZNSt8bad_castC1Ev
+__ZNSt8bad_castC2Ev
+__ZNSt8bad_castD0Ev
+__ZNSt8bad_castD1Ev
+__ZNSt8bad_castD2Ev
+__ZNSt9bad_allocC1Ev
+__ZNSt9bad_allocC2Ev
+__ZNSt9bad_allocD0Ev
+__ZNSt9bad_allocD1Ev
+__ZNSt9bad_allocD2Ev
+__ZNSt9exceptionD0Ev
+__ZNSt9exceptionD1Ev
+__ZNSt9exceptionD2Ev
+__ZNSt9type_infoD0Ev
+__ZNSt9type_infoD1Ev
+__ZNSt9type_infoD2Ev
+
+# Other std:: functions implemented in libc++abi
+__ZSt10unexpectedv
+__ZSt13get_terminatev
+__ZSt13set_terminatePFvvE
+__ZSt14get_unexpectedv
+__ZSt14set_unexpectedPFvvE
+__ZSt15get_new_handlerv
+__ZSt15set_new_handlerPFvvE
+__ZSt9terminatev
+
+# Misc
+__ZN10__cxxabiv119__getExceptionClassEPK17_Unwind_Exception
+__ZN10__cxxabiv119__setExceptionClassEP17_Unwind_Exceptiony
+__ZN10__cxxabiv121__isOurExceptionClassEPK17_Unwind_Exception
diff --git a/lib/new-delete.exp b/lib/new-delete.exp
new file mode 100644
index 0000000..086d2fe
--- /dev/null
+++ b/lib/new-delete.exp
@@ -0,0 +1,20 @@
+__Znwm
+__ZnwmRKSt9nothrow_t
+__ZnwmSt11align_val_t
+__ZnwmSt11align_val_tRKSt9nothrow_t
+__ZdaPv
+__ZdaPvm
+__ZdaPvmSt11align_val_t
+__ZdaPvRKSt9nothrow_t
+__ZdaPvSt11align_val_t
+__ZdaPvSt11align_val_tRKSt9nothrow_t
+__ZdlPv
+__ZdlPvm
+__ZdlPvmSt11align_val_t
+__ZdlPvRKSt9nothrow_t
+__ZdlPvSt11align_val_t
+__ZdlPvSt11align_val_tRKSt9nothrow_t
+__Znam
+__ZnamRKSt9nothrow_t
+__ZnamSt11align_val_t
+__ZnamSt11align_val_tRKSt9nothrow_t
diff --git a/lib/personality-sjlj.exp b/lib/personality-sjlj.exp
new file mode 100644
index 0000000..be0bfac
--- /dev/null
+++ b/lib/personality-sjlj.exp
@@ -0,0 +1 @@
+___gxx_personality_sj0
diff --git a/lib/personality-v0.exp b/lib/personality-v0.exp
new file mode 100644
index 0000000..610e4e3
--- /dev/null
+++ b/lib/personality-v0.exp
@@ -0,0 +1 @@
+___gxx_personality_v0
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 77f0098..45d4d02 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -147,6 +147,12 @@
   string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
 endif()
 
+if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$")
+  set(LIBCXXABI_USE_SJLJ_EXCEPTIONS ON)
+else()
+  set(LIBCXXABI_USE_SJLJ_EXCEPTIONS OFF)
+endif()
+
 # Build the shared library.
 if (LIBCXXABI_ENABLE_SHARED)
   add_library(cxxabi_shared SHARED ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
@@ -181,6 +187,21 @@
   if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
     list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
   endif()
+
+  # -exported_symbols_list is only available on Apple platforms
+  if (APPLE)
+    target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-base.exp")
+
+    if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
+      target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/new-delete.exp")
+    endif()
+
+    if (LIBCXXABI_USE_SJLJ_EXCEPTIONS)
+      target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-sjlj.exp")
+    else()
+      target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
+    endif()
+  endif()
 endif()
 
 # Build the static library.