fix(libSceSsl): keep the bundled mbedtls symbols out of libSceSsl's exports on macOS #10530

Merged
maximilianfv merged 1 commit from upstream-pr/10530 into main 2026-10-26 20:22:33 +00:00
maximilianfv commented 2026-10-24 08:40:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-24T08:40:36Z.


What

On Linux and MinGW, --exclude-libs,ALL keeps the statically linked Mbed TLS out of libSceSsl's dynamic exports. Apple's linker has no such option, so on macOS libSceSsl.prx exports 930 mbedtls_* and 155 psa_* symbols (54 of its 1,139 exports are libSceSsl's own). A program that links its own Mbed TLS can then bind to libSceSsl's copy, which allocates from libSceSsl's context pool. guest_ssl_transport_kernel and guest_ssl_transport_net fail on macOS this way: their test TLS server links Mbed TLS itself. The analysis in #8658 (commit 8a4bd1e4cd) traced this to the server's mbedtls_ssl_setup resolving to libSceSsl's copy and failing with MBEDTLS_ERR_SSL_ALLOC_FAILED.

This builds the mbedtls, mbedcrypto, mbedx509 and p256m targets with hidden C visibility on Apple. These targets are shared, so the change also reaches libSceLibreSsl, which links mbedcrypto and exported 27 mbedtls_* symbols on macOS; it now exports none. The Linux and MinGW paths are unchanged.

Prior art, credited:

  • #7332 by @ycarogabriel-lgtm (closed), commit a5c41edb82, authored 2026-10-18: the same change, line for line. This PR brings it to current main as a standalone fix, with Ycaro as co-author.
  • #8658 by @iamthehimansh (closed, being split into smaller PRs such as #10419), commit 8a4bd1e4cd, authored 2026-10-19: the same fix, done with -unexported_symbol,_mbedtls_* and _psa_* linker options rather than hidden visibility. None of the PRs split from #8658 so far includes it.
  • #9848 by @Felipebmaitan (open) fixes the same kind of macOS export leak for libSceFreeType with an export allowlist. An allowlist does not fit libSceSsl, whose own exports are not all _nid_ names; the existing guest_ssl_transport_* tests cover this change.

pr_overlap.py (run serially): no overlapping PRs. It could not compare #6044 because #6044 conflicts with main. #6044 changes core/libs/prx/libSceSsl/CMakeLists.txt only in the BUILD_TESTING block, not the lines changed here.

Tested

Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2. main alone does not build on macOS, so I tested on mugurc's macOS series (ci/macos-series-2, 27e968974) merged with main at 1e20650e84, plus the macOS build parts of #10419, toggling only this change.

without with
nm -gU libSceSsl.prx 1,139 exports (930 mbedtls_, 155 psa_) 54 exports, no mbedtls_ or psa_
nm -gU libSceLibreSsl.prx 427 exports (27 mbedtls_) 400 exports, no mbedtls_
ctest -R 'guest_ssl|guest_libressl|guest_http' (14 tests) 12 pass; guest_ssl_transport_kernel and guest_ssl_transport_net fail with a server certificate without a loaded CA passed the initial verify options 14 pass

The five guest_libressl* tests pass both ways. On the series alone (27e968974, without the main merge), the same two transport tests failed without the change and all 9 ssl|http tests passed with it.

Not tested on Linux or Windows. Their CMake path is unchanged.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code counted the exports, ran the tests and wrote this description; I am responsible for every line)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4993933324 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10530). Originally posted by [maximilianfv](https://github.com/maximilianfv) on 2026-10-24T08:40:36Z. --- ### What On Linux and MinGW, `--exclude-libs,ALL` keeps the statically linked Mbed TLS out of libSceSsl's dynamic exports. Apple's linker has no such option, so on macOS `libSceSsl.prx` exports 930 `mbedtls_*` and 155 `psa_*` symbols (54 of its 1,139 exports are libSceSsl's own). A program that links its own Mbed TLS can then bind to libSceSsl's copy, which allocates from libSceSsl's context pool. `guest_ssl_transport_kernel` and `guest_ssl_transport_net` fail on macOS this way: their test TLS server links Mbed TLS itself. The analysis in #8658 (commit 8a4bd1e4cd) traced this to the server's `mbedtls_ssl_setup` resolving to libSceSsl's copy and failing with `MBEDTLS_ERR_SSL_ALLOC_FAILED`. This builds the `mbedtls`, `mbedcrypto`, `mbedx509` and `p256m` targets with hidden C visibility on Apple. These targets are shared, so the change also reaches `libSceLibreSsl`, which links `mbedcrypto` and exported 27 `mbedtls_*` symbols on macOS; it now exports none. The Linux and MinGW paths are unchanged. Prior art, credited: - #7332 by @ycarogabriel-lgtm (closed), commit a5c41edb82, authored 2026-10-18: the same change, line for line. This PR brings it to current `main` as a standalone fix, with Ycaro as co-author. - #8658 by @iamthehimansh (closed, being split into smaller PRs such as #10419), commit 8a4bd1e4cd, authored 2026-10-19: the same fix, done with `-unexported_symbol,_mbedtls_*` and `_psa_*` linker options rather than hidden visibility. None of the PRs split from #8658 so far includes it. - #9848 by @Felipebmaitan (open) fixes the same kind of macOS export leak for libSceFreeType with an export allowlist. An allowlist does not fit libSceSsl, whose own exports are not all `_nid_` names; the existing `guest_ssl_transport_*` tests cover this change. `pr_overlap.py` (run serially): no overlapping PRs. It could not compare #6044 because #6044 conflicts with `main`. #6044 changes `core/libs/prx/libSceSsl/CMakeLists.txt` only in the `BUILD_TESTING` block, not the lines changed here. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2. `main` alone does not build on macOS, so I tested on mugurc's macOS series (`ci/macos-series-2`, 27e968974) merged with `main` at 1e20650e84, plus the macOS build parts of #10419, toggling only this change. | | without | with | |---|---|---| | `nm -gU libSceSsl.prx` | 1,139 exports (930 `mbedtls_`, 155 `psa_`) | 54 exports, no `mbedtls_` or `psa_` | | `nm -gU libSceLibreSsl.prx` | 427 exports (27 `mbedtls_`) | 400 exports, no `mbedtls_` | | `ctest -R 'guest_ssl\|guest_libressl\|guest_http'` (14 tests) | 12 pass; `guest_ssl_transport_kernel` and `guest_ssl_transport_net` fail with `a server certificate without a loaded CA passed the initial verify options` | 14 pass | The five `guest_libressl*` tests pass both ways. On the series alone (27e968974, without the `main` merge), the same two transport tests failed without the change and all 9 `ssl|http` tests passed with it. Not tested on Linux or Windows. Their CMake path is unchanged. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code counted the exports, ran the tests and wrote this description; I am responsible for every line) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 11:09:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T11:09:39Z.

Review: APPROVED


Reviewed the exact two-line CMake change and the reported export/test comparison. It applies hidden C visibility to the four bundled Mbed TLS targets only on Apple; Linux/MinGW retain --exclude-libs,ALL and other platforms are untouched. The earlier implementation is cited, but it is not in current upstream main, and the PR provides a macOS-specific report showing the resulting export set and SSL transport regression coverage. The automatic build jobs for this PR are skipped; I am relying on the described macOS run, not treating it as hosted CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638029222 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10530#pullrequestreview-5638029222). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T11:09:39Z. **Review:** APPROVED --- Reviewed the exact two-line CMake change and the reported export/test comparison. It applies hidden C visibility to the four bundled Mbed TLS targets only on Apple; Linux/MinGW retain `--exclude-libs,ALL` and other platforms are untouched. The earlier implementation is cited, but it is not in current upstream `main`, and the PR provides a macOS-specific report showing the resulting export set and SSL transport regression coverage. The automatic build jobs for this PR are skipped; I am relying on the described macOS run, not treating it as hosted CI.
imellag commented 2026-10-25 09:45:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-25T09:45:15Z.

Review: APPROVED


Tested head f5dffcb12f on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2. The tree is main 61fc572cee plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries. Only this change was toggled.

  • Without it: nm -gU libSceSsl.prx lists 1,085 mbedtls_*/psa_* symbols. guest_ssl_transport_kernel and guest_ssl_transport_net fail 2 runs out of 2, at a server certificate without a loaded CA passed the initial verify options.
  • With it: libSceSsl.prx exports 55 symbols and none of them is mbedtls_* or psa_*. libSceLibreSsl.prx exports none either. Both transport tests pass 3 runs out of 3.
  • ctest -R 'ssl|http|libressl|crypto|tls|x509' (63 tests): 61 pass without this change and all 63 with it. Only the two transport tests change.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642577476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10530#pullrequestreview-5642577476). Originally posted by [imellag](https://github.com/imellag) on 2026-10-25T09:45:15Z. **Review:** APPROVED --- Tested head `f5dffcb12f` on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2. The tree is `main` `61fc572cee` plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries. Only this change was toggled. - **Without it:** `nm -gU libSceSsl.prx` lists 1,085 `mbedtls_*`/`psa_*` symbols. `guest_ssl_transport_kernel` and `guest_ssl_transport_net` fail 2 runs out of 2, at `a server certificate without a loaded CA passed the initial verify options`. - **With it:** `libSceSsl.prx` exports 55 symbols and none of them is `mbedtls_*` or `psa_*`. `libSceLibreSsl.prx` exports none either. Both transport tests pass 3 runs out of 3. - `ctest -R 'ssl|http|libressl|crypto|tls|x509'` (63 tests): 61 pass without this change and all 63 with it. Only the two transport tests change. AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10530
No description provided.