|
| 1 | +# Design: Disable LTO for SVT-AV1 on musl Builds |
| 2 | + |
| 3 | +## Context |
| 4 | + |
| 5 | +SVT-AV1 v2.3.0 enables LTO by default when built with GCC (via `SVT_AV1_LTO` CMake option). This optimization embeds GCC-specific bytecode into the static library. When consumers link against this library, they need a matching GCC LTO plugin version. |
| 6 | + |
| 7 | +Alpine Linux (musl libc) does not ship the GCC LTO plugin by default, and even when installed, version mismatches between build-time and link-time GCC cause failures. |
| 8 | + |
| 9 | +**Constraints:** |
| 10 | +- Must not impact other platforms (darwin, linux-glibc) |
| 11 | +- Must preserve SVT-AV1 performance on platforms where LTO works |
| 12 | +- Must be maintainable alongside existing platform configuration pattern |
| 13 | + |
| 14 | +## Goals / Non-Goals |
| 15 | + |
| 16 | +**Goals:** |
| 17 | +- Enable successful musl builds without requiring LTO plugin |
| 18 | +- Maintain single shared SVT-AV1 recipe |
| 19 | +- Follow existing platform configuration patterns |
| 20 | + |
| 21 | +**Non-Goals:** |
| 22 | +- Disable LTO globally (other codecs/platforms unaffected) |
| 23 | +- Add new build system abstractions |
| 24 | + |
| 25 | +## Decisions |
| 26 | + |
| 27 | +### Decision 1: Use codec-specific CMake variable |
| 28 | + |
| 29 | +**What:** Add `SVTAV1_CMAKE_OPTS` variable that platforms can optionally define. |
| 30 | + |
| 31 | +**Why:** |
| 32 | +- Follows existing pattern (e.g., `LIBVPX_TARGET`, `X264_HOST`, `AOM_TARGET_CPU`) |
| 33 | +- Minimal change to shared recipe |
| 34 | +- Platform-specific without creating recipe duplication |
| 35 | + |
| 36 | +**Alternatives considered:** |
| 37 | +1. **Global `CMAKE_OPTS` modification** - Too broad, affects all CMake codecs |
| 38 | +2. **Platform-specific svt-av1.mk** - Creates duplication, violates DRY |
| 39 | +3. **Conditional in shared recipe** - Adds `ifeq` complexity to shared code |
| 40 | + |
| 41 | +### Decision 2: Default to empty (no-op) |
| 42 | + |
| 43 | +**What:** `SVTAV1_CMAKE_OPTS ?=` defaults to empty in shared recipe. |
| 44 | + |
| 45 | +**Why:** |
| 46 | +- Platforms that don't define it get default SVT-AV1 behavior (LTO enabled) |
| 47 | +- Only musl platform explicitly disables LTO |
| 48 | +- No impact on darwin/linux-glibc builds |
| 49 | + |
| 50 | +## Implementation |
| 51 | + |
| 52 | +### File: `platforms/linuxmusl-x64/config.mk` |
| 53 | + |
| 54 | +Add after codec-specific overrides section: |
| 55 | +```makefile |
| 56 | +# SVT-AV1: Disable LTO on musl (GCC LTO plugin not available by default) |
| 57 | +SVTAV1_CMAKE_OPTS := -DSVT_AV1_LTO=OFF |
| 58 | +``` |
| 59 | + |
| 60 | +### File: `shared/codecs/bsd/svt-av1.mk` |
| 61 | + |
| 62 | +Modify cmake invocation: |
| 63 | +```makefile |
| 64 | +# Default: empty (LTO enabled on most platforms) |
| 65 | +SVTAV1_CMAKE_OPTS ?= |
| 66 | + |
| 67 | +svt-av1.stamp: |
| 68 | + ... |
| 69 | + cd $(SVTAV1_BUILD) && \ |
| 70 | + cmake $(SVTAV1_SRC) \ |
| 71 | + $(CMAKE_OPTS) \ |
| 72 | + $(SVTAV1_CMAKE_OPTS) \ |
| 73 | + -DBUILD_SHARED_LIBS=OFF \ |
| 74 | + ... |
| 75 | +``` |
| 76 | + |
| 77 | +## Risks / Trade-offs |
| 78 | + |
| 79 | +| Risk | Impact | Mitigation | |
| 80 | +|------|--------|------------| |
| 81 | +| Slight performance regression on musl | Low - LTO gains are ~1-5% for encoding | Acceptable for build compatibility | |
| 82 | +| Pattern proliferation | Low - Only needed for SVT-AV1 | Document in CLAUDE.md if more codecs need this | |
| 83 | + |
| 84 | +## Migration Plan |
| 85 | + |
| 86 | +No migration needed - this is a build system fix that doesn't affect API or package structure. |
| 87 | + |
| 88 | +**Rollback:** Remove `SVTAV1_CMAKE_OPTS` from config.mk and revert svt-av1.mk changes. |
| 89 | + |
| 90 | +## Open Questions |
| 91 | + |
| 92 | +None - implementation is straightforward. |
0 commit comments