Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS static library build from source code , symbol visibility issue #17722

Closed
sarojlo opened this issue Sep 27, 2023 · 1 comment
Closed

iOS static library build from source code , symbol visibility issue #17722

sarojlo opened this issue Sep 27, 2023 · 1 comment
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@sarojlo
Copy link

sarojlo commented Sep 27, 2023

Describe the issue

  • We have built static onnxruntime lib from source code for iOS . THis creates many static library like libonnxruntime_session.a , onnxruntime_optimizer.a , onnxruntime_providers.a ... libabsl.a all of them have all symbols in global namespace.
  • As we are building a static library for end customer from our code we then used libtool to create a single library using our code and all the onnxruntime libraries
  • now issue is custome also using libabsl.a may be diffrent version and as all symbols are in global namespace its causing symbol collision.

Libraries which we combined from onnxruntime are

libclog.a libcpuinfo.a libonnxruntime_optimizer.a libonnxruntime_util.a libonnxruntime_common.a libonnxruntime_flatbuffers.a libonnxruntime_framework.a libonnxruntime_graph.a libonnxruntime_mlas.a libonnxruntime_providers.a libflatbuffers.a libonnx.a libonnxruntime_session.a libonnx_proto.a libprotobuf-lite.a libre2.a libnsync_cpp.a libabsl.a

To reproduce

Use static build

Urgency

Yes. Customer issue

Platform

iOS

OS Version

iosx64 build compiled on MAC

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.15.1

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

default

@github-actions github-actions bot added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Sep 27, 2023
@snnn
Copy link
Member

snnn commented Sep 27, 2023

I believe static libraries have no visibility control. This is called: diamond dependency problem. There is no Silver Bullet for this problem. On the other hand, if the operating system can support dynamic libraries(e.g. DLL, shared libraries), they can help.

@snnn snnn closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2023
skottmckay added a commit that referenced this issue Nov 3, 2023
### 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 #17722
kleiti pushed a commit to kleiti/onnxruntime that referenced this issue 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
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

2 participants