Skip to content

Commit 95f1693

Browse files
authored
Re-enable FFmpeg x86-64 assembly on manylinux (#2089)
* Re-enable FFmpeg x86 assembly on manylinux * Clarify x86-64 assembly scope
1 parent 972610f commit 95f1693

5 files changed

Lines changed: 25 additions & 3 deletions

File tree

.github/actions/build-manylinux-variant/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ runs:
5757
- name: Install system tools (${{ inputs.variant_label }})
5858
shell: bash
5959
run: |
60-
pkgs="git zip unzip pkg-config ninja-build kernel-headers perl-IPC-Cmd perl-Time-Piece"
60+
pkgs="git zip unzip pkg-config ninja-build nasm yasm kernel-headers perl-IPC-Cmd perl-Time-Piece"
6161
if [ "${{ inputs.install_gtk3_devel }}" = "true" ]; then
6262
pkgs="$pkgs gtk3-devel"
6363
fi

packaging/docker/manylinux/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ The full and headless `linux-x64` packages statically link the same FFmpeg build
44

55
The FFmpeg build provides OpenCV's required libraries (`avcodec`, `avformat`, `avutil`, and `swscale`), its built-in decoders, encoders, demuxers, and muxers, and non-secure local and network protocols. RTSP, TCP, UDP, HTTP, local files, and pipes are intended to work. CI exercises H.264-over-RTSP through OpenCV and checks a representative baseline of file formats and codecs in the generated feature inventory.
66

7-
External-library autodetection is disabled. FFmpeg must not silently acquire a dependency merely because the manylinux container adds a development package. The glibc-provided iconv implementation is explicitly enabled and introduces no additional ELF dependency. Hardware acceleration, `libdrm`, `avdevice`, `avfilter`, post-processing, and `swresample` are intentionally excluded because the packaged OpenCV backend does not require them. Assembly remains disabled pending a successful position-independent static link with the current toolchain and a representative H.264 file/RTSP decode benchmark.
7+
External-library autodetection is disabled. FFmpeg must not silently acquire a dependency merely because the manylinux container adds a development package. The glibc-provided iconv implementation is explicitly enabled and introduces no additional ELF dependency. Hardware acceleration, `libdrm`, `avdevice`, `avfilter`, post-processing, and `swresample` are intentionally excluded because the packaged OpenCV backend does not require them.
8+
9+
x86-64 assembly optimizations are enabled. FFmpeg's assembly objects contain direct PC-relative references to global constants that cannot be interposed when their static archives are linked into `libOpenCvSharpExtern.so`. The Linux linker therefore hides symbols from the four private FFmpeg archives with `--exclude-libs`; this resolves those references without exporting FFmpeg's private implementation from the OpenCvSharp native binding.
810

911
TLS is not currently included, so HTTPS and RTSPS are outside the supported feature surface. Adding a TLS backend requires an explicit decision covering license compatibility, CA certificate discovery, binary size, transitive dependencies, manylinux portability, and regression tests.
1012

packaging/docker/manylinux/build_static_deps.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ CONFIGURE_FLAGS=(
5454
--enable-static
5555
--disable-shared
5656
--enable-pic
57-
--disable-asm
5857
--disable-autodetect
5958
--disable-doc
6059
--disable-programs
@@ -89,6 +88,13 @@ mkdir -p "${INVENTORY_DIR}"
8988
echo "[configure-flags]"
9089
printf '%s\n' "${CONFIGURE_FLAGS[@]}"
9190

91+
echo
92+
echo "[assembly]"
93+
for option in inline_asm x86asm; do
94+
value=$(awk -v macro="HAVE_${option^^}" '$1 == "#define" && $2 == macro { print $3 }' config.h)
95+
echo "${option}=${value:-0}"
96+
done
97+
9298
for component in protocol demuxer muxer decoder encoder; do
9399
echo
94100
echo "[${component}s]"

packaging/docker/manylinux/verify_ffmpeg_features.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ if ! grep -qx -- '--disable-autodetect' "${INVENTORY_PATH}"; then
6565
exit 1
6666
fi
6767

68+
if grep -qx -- '--disable-asm' "${INVENTORY_PATH}" ||
69+
! grep -qx -- 'x86asm=1' "${INVENTORY_PATH}"; then
70+
echo "ERROR: FFmpeg x86-64 assembly optimizations are disabled"
71+
exit 1
72+
fi
73+
6874
if grep -Eq '^(gnutls|libtls|mbedtls|openssl|schannel|securetransport)=1$' "${INVENTORY_PATH}"; then
6975
echo "ERROR: an unapproved TLS backend was enabled"
7076
grep -E '^(gnutls|libtls|mbedtls|openssl|schannel|securetransport)=' "${INVENTORY_PATH}"

src/OpenCvSharpExtern/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ if(OpenCV_FOUND)
6464
# 3rd-party dependency (e.g. libatomic.so.1) but whose symbols are never actually
6565
# referenced by the resulting binary. See issue #2065.
6666
target_link_options(OpenCvSharpExtern PRIVATE -Wl,--as-needed)
67+
68+
# FFmpeg's optimized x86-64 assembly uses direct PC-relative references to global
69+
# constants. Keep the statically linked FFmpeg implementation private so those
70+
# references bind locally when producing this shared library. See issue #2085.
71+
foreach(ffmpeg_archive IN ITEMS libavcodec.a libavformat.a libavutil.a libswscale.a)
72+
target_link_options(OpenCvSharpExtern PRIVATE
73+
"-Wl,--exclude-libs,${ffmpeg_archive}")
74+
endforeach()
6775
endif()
6876
endif()
6977

0 commit comments

Comments
 (0)