From 7bc92dcbfccc38e3fa02b715e039a0b22f5d9be8 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 2 Apr 2026 01:47:52 +0200 Subject: [PATCH] Enforce --no-undefined linker flag and fix libpng LoongArch LSX build Add -Wl,--no-undefined to the default linker flags for Linux and Android in gn/skia/BUILD.gn config("default"). This causes the linker to reject shared libraries with unresolved symbols at build time, rather than producing binaries that crash at runtime with symbol lookup errors. macOS (ld64) and Windows (MSVC) already enforce this by default; Linux and Android were the only platforms that silently allowed it. This immediately exposed a latent bug in the libpng build: when cross-compiling for loongarch64, the compiler defines __loongarch_sx which causes pngpriv.h to set PNG_LOONGARCH_LSX_OPT=1 and route PNG_FILTER_OPTIMIZATIONS to png_init_filter_functions_lsx(). The ARM (NEON) and x86 (SSE2) SIMD sources were already included in the GN build, but the LoongArch equivalents were missing. Add them. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- gn/skia/BUILD.gn | 6 +++++- third_party/libpng/BUILD.gn | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gn/skia/BUILD.gn b/gn/skia/BUILD.gn index 29d21b529c52..211af644c569 100644 --- a/gn/skia/BUILD.gn +++ b/gn/skia/BUILD.gn @@ -204,7 +204,10 @@ config("default") { if (is_android) { cflags += [ "--sysroot=$ndk/toolchains/llvm/prebuilt/$ndk_host/sysroot" ] - ldflags += [ "-static-libstdc++" ] + ldflags += [ + "-static-libstdc++", + "-Wl,--no-undefined", + ] } if (is_tizen) { @@ -366,6 +369,7 @@ config("default") { if (is_linux) { libs += [ "pthread" ] + ldflags += [ "-Wl,--no-undefined" ] } if (is_mac) { diff --git a/third_party/libpng/BUILD.gn b/third_party/libpng/BUILD.gn index 330268986070..41339cf9e108 100644 --- a/third_party/libpng/BUILD.gn +++ b/third_party/libpng/BUILD.gn @@ -55,5 +55,12 @@ if (skia_use_system_libpng) { "../externals/libpng/intel/intel_init.c", ] } + + if (current_cpu == "loongarch64") { + sources += [ + "../externals/libpng/loongarch/filter_lsx_intrinsics.c", + "../externals/libpng/loongarch/loongarch_lsx_init.c", + ] + } } }