From c10f994e1be378f0660c4856b5ae25f506458077 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 11 Apr 2019 18:19:24 +0200 Subject: [PATCH] ARROW-2796: [C++] Simplify version script used for linking Also use it for Arrow sublibraries: libarrow_flight.so, libarrow_python.so, libarrow_cuda.so. --- cpp/src/arrow/CMakeLists.txt | 3 +- cpp/src/arrow/flight/CMakeLists.txt | 2 + cpp/src/arrow/gpu/CMakeLists.txt | 2 +- cpp/src/arrow/python/CMakeLists.txt | 2 +- cpp/src/arrow/symbols.map | 73 +++---------------- .../scripts/check_arrow_visibility.sh | 12 ++- 6 files changed, 26 insertions(+), 68 deletions(-) diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index c04570464c3..86f3bfb2209 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -239,8 +239,9 @@ if(NOT APPLE AND NOT MSVC) # Localize thirdparty symbols using a linker version script. This hides them # from the client application. The OS X linker does not support the # version-script option. - set(ARROW_SHARED_LINK_FLAGS + set(ARROW_VERSION_SCRIPT_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map") + set(ARROW_SHARED_LINK_FLAGS ${ARROW_VERSION_SCRIPT_FLAGS}) endif() set(ARROW_ALL_SRCS ${ARROW_SRCS}) diff --git a/cpp/src/arrow/flight/CMakeLists.txt b/cpp/src/arrow/flight/CMakeLists.txt index c9c1e4dfcd1..8b9e4d04ee8 100644 --- a/cpp/src/arrow/flight/CMakeLists.txt +++ b/cpp/src/arrow/flight/CMakeLists.txt @@ -90,6 +90,8 @@ add_arrow_lib(arrow_flight DEPENDENCIES flight_grpc_gen metadata_fbs + SHARED_LINK_FLAGS + ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt SHARED_LINK_LIBS arrow_shared ${ARROW_FLIGHT_STATIC_LINK_LIBS} diff --git a/cpp/src/arrow/gpu/CMakeLists.txt b/cpp/src/arrow/gpu/CMakeLists.txt index 334904dc8a0..caef952a061 100644 --- a/cpp/src/arrow/gpu/CMakeLists.txt +++ b/cpp/src/arrow/gpu/CMakeLists.txt @@ -46,7 +46,7 @@ add_arrow_lib(arrow_cuda DEPENDENCIES metadata_fbs SHARED_LINK_FLAGS - "" + ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt SHARED_LINK_LIBS arrow_shared ${ARROW_CUDA_SHARED_LINK_LIBS} diff --git a/cpp/src/arrow/python/CMakeLists.txt b/cpp/src/arrow/python/CMakeLists.txt index 6f618367ed4..8df447b6a24 100644 --- a/cpp/src/arrow/python/CMakeLists.txt +++ b/cpp/src/arrow/python/CMakeLists.txt @@ -80,7 +80,7 @@ add_arrow_lib(arrow_python DEPENDENCIES ${ARROW_PYTHON_DEPENDENCIES} SHARED_LINK_FLAGS - "" + ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt SHARED_LINK_LIBS ${ARROW_PYTHON_SHARED_LINK_LIBS} STATIC_LINK_LIBS diff --git a/cpp/src/arrow/symbols.map b/cpp/src/arrow/symbols.map index 9b24ab4e372..0149f9515d6 100644 --- a/cpp/src/arrow/symbols.map +++ b/cpp/src/arrow/symbols.map @@ -23,71 +23,20 @@ # those symbols. # See https://github.com/apache/arrow/pull/1953#issuecomment-386057063 std::__once*; + # The leading asterisk is required for symbols such as + # "typeinfo for arrow::SomeClass". + # Unfortunately this will also catch template specializations + # (from e.g. STL or Flatbuffers) involving Arrow types. + *arrow::*; }; + # Also export C-level helpers + arrow_*; + pyarrow_*; # Symbols marked as 'local' are not exported by the DSO and thus may not - # be used by client applications. + # be used by client applications. Everything except the above falls here. + # This ensures we hide symbols of static dependencies. local: - # devtoolset / static-libstdc++ symbols - __cxa_*; - __once_proxy; + *; - # Static libraries that are linked in e.g. the manylinux1 build - # Brotli compression library - Brotli*; - # zlib - adler32*; - crc32*; - deflate*; - inflate*; - get_crc_table; - zcalloc; - zcfree; - zError; - zlibCompileFlags; - zlibVersion; - _tr_*; - # bz2 - BZ2_*; - # lz4 - LZ4_*; - LZ4F_*; - # zstandard - ZSTD_*; - ZSTDv*; - HUF_*; - HUFv*; - FSE_*; - FSEv*; - ZBUFFv*; - ZSTDMT*; - POOL_*; - HIST_*; - ERR_getErrorString; - # jemalloc - je_arrow_*; - # uriparser - uri*; - # ORC destructors - _ZThn8_N3orc*; - # Protobuf symbols that aren't hidden by the C++ section below - # (destructors, vtables, other stuff) - *N6google8protobuf*; - - extern "C++" { - # devtoolset or -static-libstdc++ - the Red Hat devtoolset statically - # links c++11 symbols into binaries so that the result may be executed on - # a system with an older libstdc++ which doesn't include the necessary - # c++11 symbols. - std::*; - - # Statically linked C++ dependencies - boost::*; - double_conversion::*; - google::*; - # glog - *MakeCheckOpValueString*; - orc::*; - snappy::*; - }; }; diff --git a/python/manylinux1/scripts/check_arrow_visibility.sh b/python/manylinux1/scripts/check_arrow_visibility.sh index 477da658d91..ed464e0779a 100755 --- a/python/manylinux1/scripts/check_arrow_visibility.sh +++ b/python/manylinux1/scripts/check_arrow_visibility.sh @@ -16,14 +16,20 @@ # specific language governing permissions and limitations # under the License. -nm -D -C /arrow-dist/lib/libarrow.so > nm_arrow.log -grep ' T ' nm_arrow.log | grep -v arrow > visible_symbols.log +nm --demangle --dynamic /arrow-dist/lib/libarrow.so > nm_arrow.log -if [[ `cat visible_symbols.log | wc -l` -eq 2 ]] +# Filter out Arrow symbols and see if anything remains. +# '_init' and '_fini' symbols may or not be present, we don't care. +# (note we must ignore the grep exit status when no match is found) +grep ' T ' nm_arrow.log | grep -v -E '(arrow|\b_init\b|\b_fini\b)' | cat - > visible_symbols.log + +if [[ -f visible_symbols.log && `cat visible_symbols.log | wc -l` -eq 0 ]] then exit 0 fi +echo "== Unexpected symbols exported by libarrow.so ==" cat visible_symbols.log +echo "================================================" exit 1