Skip to content

build(audio): link one SDL copy on macOS - #11049

Open
imellag wants to merge 3 commits into
boykopovar:mainfrom
imellag:build/audio-macos-single-sdl
Open

imellag wants to merge 3 commits into
boykopovar:mainfrom
imellag:build/audio-macos-single-sdl

Conversation

@imellag

@imellag imellag commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What

This is mugurc's 63db337cd8 from his macOS series (ci/macos-series-2, listed on #1). mugurc is co-author of the commit. It sits on #10669, whose --exclude-libs lines it moves into the non-Apple branch.

On macOS the Objective-C runtime registers SDL's classes from every copy in the process. libSceAgcDriver, libSceVideoOut, libSceAudioIn and libSceAudioOut each link SDL2 statically, so a relinked game prints, for each of 14 SDL classes and each extra copy, Class SDL_... is implemented in both ... One of the duplicates must be removed or renamed, and the runtime warns this "may cause spurious casting failures and mysterious crashes".

On Apple, libSceAudioIn and libSceAudioOut now link libSceAgcDriver, which holds the process's SDL, instead of their own copy. Linux and Windows are unchanged.

Tested

Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 Release under Rosetta 2 (-DCMAKE_OSX_ARCHITECTURES=x86_64, Ninja, BUILD_TESTING=ON). main alone doesn't build the libraries on macOS, so the tree is main 61fc572cee with #10423, the open macOS build PRs (#10366, #10419, #10552, #7631, #7804, #4630, #10540, #10659, #10660, #10669, #10676), #10889, #10898 and the parts of mugurc's series that #7201 also carries. Planet of Lana (PPSA19450) is relinked with that tree's relinker (--macos --to-rosetta).

Linux and Windows: not built; the change only adds an if(APPLE) branch.

check_conventions.py --base upstream/main passes. pr_overlap.py reports no conflict; it couldn't compare #7201 and #5021 on the two CMake files, because both conflict with main.

#7201 (the whole macOS port) and #5021 (the native ARM64 AOT draft) carry their own versions of these functions. #7201's head (6687cbac29, 2026-10-16) conflicts with main, needs a rebase anyway, and is being split into smaller PRs such as #10552 and #10419. #5021 is a draft of more than 43,000 lines that conflicts with main and says no merge into main is implied. If either lands first with these functions, this PR is not needed and I will close it.

Checklist

libSceAudioIn and libSceAudioOut linked SDL2 statically, as every library
that uses it does. On macOS the Objective-C runtime registers the classes
of SDL from each copy it finds, and when two libraries of one process hold
a copy the runtime warns that one of the two is used and which one is
undefined. They link libSceAgcDriver instead, which holds the SDL of the
process. The other platforms are unchanged.

Co-authored-by: mugurc <mceker@gmail.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head afdd82c67b3372af27242bbfcec44374010fbf31. The Apple-only link changes make AudioIn and AudioOut depend on the existing AgcDriver shared target, whose own link line owns SDL2-static; their non-Apple SDL links remain unchanged. #10669 is still open and is correctly named as the dependency. The author reports the macOS duplicate-class warnings dropping from 42 to 14, with the remaining 14 coming from VideoOut, plus 51 audio tests passing. Hosted conventions/intake/eligibility checks pass; platform build jobs are skipped by path policy. I reviewed the CMake dependency and overlap context; I could not run the Apple build here.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head afdd82c67b3372af27242bbfcec44374010fbf31. On Apple, AudioIn and AudioOut now depend on the existing libSceAgcDriver shared target, which owns SDL2-static; the non-Apple SDL links remain unchanged. The PR declares its dependency on #10669. The author reports 42 duplicate Objective-C SDL class warnings before and 14 after (the remaining 14 are from VideoOut, outside this PR), and 51 audio tests passing on macOS x86-64 under Rosetta. Hosted conventions, eligibility, intake, labels and report checks pass; platform build jobs are skipped by path policy. I could not independently rerun the Apple build or audio tests on this Linux host.

@Betr0x

Betr0x commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

M4 data point for the libSceVideoOut follow-up.

Setup: Apple M4, macOS 27.0.1, Apple clang 21, x86-64 Release under Rosetta 2, MoltenVK 1.4.2 (LunarG SDK 1.4.363.0). Tree: main 3a2c51a plus mugurc's ci/macos-series-2, which already carries this PR's change (63db337cd8). Syobon Action (PPSA47402, catalog 01.001.000) relinked with --macos --to-rosetta.

  • With this PR's change: 14 duplicate class warnings in the first 30 s, all libSceVideoOut against libSceAgcDriver, as you describe.
  • With libSceVideoOut linking libSceAgcDriver's SDL on Apple instead of SDL2-static (it already links libSceAgcDriver): 0 warnings, and libSceVideoOut.prx goes from 1.7 MB to 320 KB with 55 SDL imports. Title screen, level 1 and pad input through APS5_PAD_INPUT_FILE work as before.
  • The test executables that link both libSceVideoOut and their own SDL2-static need the same change: pad_sdl aborts otherwise, because its virtual joysticks are attached in the test's SDL copy while VideoOut asks libSceAgcDriver's. With video_out_mouse_tests, pad_sdl_tests, video_out_hdr_probe_tests and video_out_telemetry_tests switched as well, ctest -R "video_out|audio|pad|mouse|keyboard" passes 97 of 97 here (the VideoOut flip tests skip, as before), and video_out_mouse_tests passes.

Are you planning that follow-up yourself? If not, I'd be happy to open it with Depends on: #11049.

AI-assisted: yes

@imellag

imellag commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

@Betr0x Thanks for the M4 run and for working out the test executables. Yes please, go ahead and open the libSceVideoOut follow-up with Depends on: #11049. You found the pad_sdl abort and have the 97-test run, so it's better coming from you.

@THEMANnt THEMANnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed afdd82c67b3372af27242bbfcec44374010fbf31. Pending review.

CMake linkage branches are verified; native macOS SDL behavior remains unverified in this review.

Validation: Executed the submitted AudioIn/AudioOut CMake on head and base across Darwin/Linux/Windows branches. Darwin uses libSceAgcDriver and drops the extra SDL2-static/exclude-libs linkage; the Linux/Windows link commands retain their old behavior.

Scope / next step: This does not prove Mach-O symbol resolution or Objective-C class identity. The author describes a combined macOS-series run; I did not independently execute or certify that integration. Native Apple evidence remains the limit on approval.

@javierUDP

Copy link
Copy Markdown
Contributor

On macOS, with this branch merged into main 5b1d381, audio_out2_timing_tests no longer links:

Undefined symbols for architecture x86_64:
  "_SDL_CloseAudioDevice", referenced from:

AudioOut2Timing.cpp calls SDL itself, but the target links only libSceAudioOut libc, so it took SDL from libSceAudioOut. On Apple that library now gets SDL from libSceAgcDriver, and with two-level namespaces the symbol has to come from a library the test links. Linking the test to libSceAgcDriver on Apple, as this PR does for libSceAudioOut, fixes it:

    target_link_libraries(audio_out2_timing_tests PRIVATE libSceAudioOut libc)
    if(APPLE)
        target_link_libraries(audio_out2_timing_tests PRIVATE libSceAgcDriver)
    endif()

With that, audio_out2_timing links and passes here (macOS 27.2, Apple M5, x86-64 under Rosetta); without it the link fails as above.

AI-assisted: yes

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi imellag,

Thanks for the macOS work here. One thing to fix before this can land: once this branch is merged with current main, a test target on macOS stops linking, as javierUDP reported on 4 Nov (audio_out2_timing_tests: Undefined symbols ... "_SDL_CloseAudioDevice").

What I see in the merged tree (merge of this head into main 5b1d381, no conflicts): main's AudioOut2Timing.cpp calls SDL directly (line 203, SDL_CloseAudioDevice), and the audio_out2_timing_tests target links only libSceAudioOut libc. With this PR, libSceAudioOut no longer links SDL itself on Apple (it gets it from libSceAgcDriver, as a PRIVATE dependency), so the test has no library it links that provides the symbol, and two-level namespaces on macOS do not resolve it. Nothing else in the change adds an Apple link for the test targets.

Please link the test targets that call SDL themselves to the library that now provides it on Apple, for example for audio_out2_timing_tests:

if(APPLE)
    target_link_libraries(audio_out2_timing_tests PRIVATE libSceAgcDriver)
endif()

The same check is worth doing for the other test targets in core/libs/prx/libSceAudioOut/CMakeLists.txt whose sources call SDL: AudioOutBufferSize, AudioOutDefaultOpen, AudioOutInitialization, AudioOutPortLocks and AudioOutVibrationDevice (each links libc, libkernel, libScePad and/or libSceAudioOut, not SDL). AudioOutResampling already links SDL2-static explicitly. If any of them link fine as they are, a short note saying why is enough.

@imellag

imellag commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean @javierUDP thanks, fixed in 978f05f (after a merge of main b11c7bf): on Apple, audio_out2_timing_tests now also links libSceAgcDriver, which provides SDL there.

I built every audio test target on macOS in a tree with this head, current main and the open macOS port PRs (support/macos-boot-1103): all 28 targets link, and ctest -R '^(audio_out|audio_in|guest_audio_in)' passes 60 of 60. Before this commit audio_out2_timing_tests was the only one that failed to link.

The others you listed:

  • AudioOutBufferSize, AudioOutDefaultOpen and AudioOutVibrationDevice define the 13 SDL functions they call as test fakes (extern "C" ... SDL_WasInit and the rest), and AudioOutInitialization defines the one it calls, so they link as they are.
  • AudioOutPortLocks and AudioOutResampling are only built on Linux (if(CMAKE_SYSTEM_NAME STREQUAL "Linux")), so they are not targets on macOS.

AI-assisted: yes

@malekaifa malekaifa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imellag I confirmed the Nov. 20 blocker against current head 978f05f4427bb05cc914c12756c62c0d2ab688d0. On Apple this PR makes libSceAudioIn and libSceAudioOut share the SDL copy from libSceAgcDriver, but AudioIn still calls SDL_InitSubSystem(SDL_INIT_AUDIO) under its own g_mutex, while AudioOut calls InitializeSdlAudio_nid_no_patch() under a different static initialization mutex. That leaves concurrent AudioIn/AudioOut opens able to enter SDL audio initialization independently on the same SDL instance. Romannachwievor reproduced failures/crashes with concurrent real-CoreAudio starts and 0 failures after routing Apple AudioIn through InitializeSdlAudio_nid_no_patch(). Please fold that serialization into this PR (the proposed Apple-only AudioIn -> libSceAudioOut link has no reverse dependency) and retain the existing audio-target build/test coverage. This is also a prerequisite blocker for #24341. AI-assisted: yes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants