Fix SwiftShader's libEGL build under ThinLTO. Linking libEGL.so of the SwiftShader's flavor requires the linker to be too smart (there's a heavy reliance on garbage collecting unused symbols, for which there is no guarantees in the general case). In ThinLTO case, garbage collection is still not as sofisticated, as in other cases, so it fails to link the target complaining about undefined symbols. The workaround is to prevent Clang from splitting the bitcode files in the question into two, and making the GC problem a bit easier. Eventually, ThinLTO might get a better GC, but it might be a good idea to not rely on this feature in the source code. At least, no other targets in Chromium do. BUG=chromium:686980 Change-Id: Ib44f65c4825cc3f6cd24695738a71ca4661f0bfb Reviewed-on: https://swiftshader-review.googlesource.com/9308 Tested-by: Ivan Krasin <krasin@chromium.org> Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libEGL/BUILD.gn b/src/OpenGL/libEGL/BUILD.gn index 71f8b70..7538b6f 100644 --- a/src/OpenGL/libEGL/BUILD.gn +++ b/src/OpenGL/libEGL/BUILD.gn
@@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/toolchain/toolchain.gni") + # Need a separate config to ensure the warnings are added to the end. config("swiftshader_libEGL_private_config") { defines = [ "EGL_EGLEXT_PROTOTYPES" ] @@ -82,6 +84,13 @@ [ "-Wl,--version-script=" + rebase_path("exports.map", root_build_dir) ] } + if (use_thin_lto) { + # https://crbug.com/686980 + # This target relies on the linker to be smart and garbage collect unused symbols. + # It is not the case for LLD + ThinLTO, so we have to use this ugly workaround. + cflags = ["-Xclang", "-fno-lto-unit"] + } + configs -= [ "//build/config/compiler:chromium_code" ] configs += [ "//build/config/compiler:no_chromium_code",