Skip to content

Pre-link when creating static library for apple framework - #18241

Merged
skottmckay merged 3 commits into
mainfrom
skottmckay/Hide_iOS_symbols_PR
Nov 3, 2023
Merged

Pre-link when creating static library for apple framework#18241
skottmckay merged 3 commits into
mainfrom
skottmckay/Hide_iOS_symbols_PR

Conversation

@skottmckay

Copy link
Copy Markdown
Contributor

Description

Pre-link with ld -r to apply symbol visibility when the static library is created to replicate XCode's Single Object Pre-link.

Current builds set the visibility flags but that doesn't get applied until the static library is linked into something else, which can be too late. Pre-linking fixes this.

The pre-link uses the .o files from the ORT static libraries and the .a files from external libraries. This combination limits the symbols included from the .a files to things required by the ORT .o files.

In order to minimize changes elsewhere in the build we extract the .o files from the ORT static libraries using ar -x.

Re-ordered the pieces use to build the Apple framework to make it a little more readable.
Fixed a couple of misc issues with missing symbols from the minimal build that show up when pre-linking is applied.

Motivation and Context

Will hopefully address #17722

…mbol visibility to the generated static library.

Fix some issues with minimal builds when pre-linking is used.
@skottmckay
skottmckay requested a review from edgchen1 November 2, 2023 08:18
Comment thread cmake/onnxruntime.cmake
edgchen1
edgchen1 previously approved these changes Nov 2, 2023
@skottmckay
skottmckay merged commit 016b752 into main Nov 3, 2023
@skottmckay
skottmckay deleted the skottmckay/Hide_iOS_symbols_PR branch November 3, 2023 13:38
kleiti pushed a commit to kleiti/onnxruntime that referenced this pull request Mar 22, 2024
…18241)

### Description
<!-- Describe your changes. -->
Pre-link with `ld -r` to apply symbol visibility when the static library
is created to replicate XCode's Single Object Pre-link.

Current builds set the visibility flags but that doesn't get applied
until the static library is linked into something else, which can be too
late. Pre-linking fixes this.

The pre-link uses the .o files from the ORT static libraries and the .a
files from external libraries. This combination limits the symbols
included from the .a files to things required by the ORT .o files.

In order to minimize changes elsewhere in the build we extract the .o
files from the ORT static libraries using `ar -x`.

Re-ordered the pieces use to build the Apple framework to make it a
little more readable.
Fixed a couple of misc issues with missing symbols from the minimal
build that show up when pre-linking is applied.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Will hopefully address microsoft#17722
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants