Build with -Bsymbolic to prevent symbol preemption The CMake build was already using -fvisibility=protected, which has the same effect but uses duplicate symbol entries for internal/external use. Bug: b/148240133 Change-Id: I8069a1b293a6ec0604be32179ed591ffaa645ed7 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/41648 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Tested-by: Nicolas Capens <nicolascapens@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c3a63a..538d360 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -293,8 +293,9 @@ set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--version-script=${DIR}/${TARGET}.lds") set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_DEPENDS "${DIR}/${TARGET}.lds;") - # Don't allow symbols to be overridden by another module. - set_property(TARGET ${TARGET} APPEND_STRING PROPERTY COMPILE_FLAGS " -fvisibility=protected") + # -Bsymbolic binds symbol references to their global definitions within + # a shared object, thereby preventing symbol preemption. + set_property(TARGET ${TARGET} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wl,-Bsymbolic") if(ARCH STREQUAL "mipsel" OR ARCH STREQUAL "mips64el") # MIPS supports sysv hash-style only.
diff --git a/src/Android.bp b/src/Android.bp index 06d3fa7..65debb5 100644 --- a/src/Android.bp +++ b/src/Android.bp
@@ -555,6 +555,12 @@ "-Wno-non-virtual-dtor", ], + ldflags: [ + // -Bsymbolic binds symbol references to their global definitions within + // a shared object, thereby preventing symbol preemption. + "-Wl,-Bsymbolic", + ], + local_include_dirs: [ "Vulkan" ], version_script: "Vulkan/android_vk_swiftshader.lds",
diff --git a/src/Vulkan/BUILD.gn b/src/Vulkan/BUILD.gn index ce7b87a..063704e 100644 --- a/src/Vulkan/BUILD.gn +++ b/src/Vulkan/BUILD.gn
@@ -158,8 +158,12 @@ inputs = [ "vk_swiftshader.lds", ] - ldflags = [ "-Wl,--version-script=" + - rebase_path("vk_swiftshader.lds", root_build_dir) ] + ldflags = [ + # -Bsymbolic binds symbol references to their global definitions within + # a shared object, thereby preventing symbol preemption. + "-Wl,-Bsymbolic", + "-Wl,--version-script=" + + rebase_path("vk_swiftshader.lds", root_build_dir) ] } deps = [