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

[native] Change name of static libraries in some cases #9135

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

grendello
Copy link
Contributor

The native runtime is subdivided into a collection of static libraries,
linked into the target shared library based on a set of conditions.

Some static libraries are "private" and aren't copied to packages, but
some are "public" in that they can be shipped in our nugets (when
dynamic runtime linking at app build time is implemented). At the same
time, we have several build configurations which differ in their build
and link configurations, and especially in whether or not they link
against the shared C++ standard library or not. In particular, the ASAN
and UBSAN builds require enabling of exceptions, RTTI and linking
against the shared C++ library.

Static component libraries will be built with the same set of
compilation and linking flags, and without modifying their output names
in some way, they may result in linking errors similar to:

native failed with 25 error(s) (0.6s) → 
    ld.lld : error : undefined symbol: std::logic_error::logic_error(char const*)
    clang++ : error : linker command failed with exit code 1 (use -v to see invocation)
    ld.lld : error : undefined symbol: __gxx_personality_v0
    ld.lld : error : undefined symbol: __cxa_begin_catch
    ld.lld : error : undefined symbol: std::__ndk1::mutex::lock()
    ld.lld : error : undefined symbol: std::__ndk1::mutex::unlock()
    ld.lld : error : undefined symbol: __cxa_end_cleanup

This kind of errors may not show during the very first build of the
repository, but it will show on any subsequent build since the static
component library name used by all the configurations is the same,
but the compilation and linking flags are different. If, e.g., UBSAN
build follows the standard build, it will replace the previously built
library with its own version but different linking requirements.
Subsequent build of non-UBSAN version of library will try to use the
static component library built with UBSAN flags, resulting in the
linking error above.

In order to avoid this kind of confusion but also minimize the number of
branches in CMake script files, this commit simply makes sure that all
the relevant static component libraries use an optional suffix when
generating their output. By default the suffix is empty, resulting in
e.g. libruntime-base.a, but with UBSAN enabled, it will produce
libruntime-base-ubsan.a thus making sure the builds don't step on each
other's toes.

The native runtime is subdivided into a collection of static libraries,
linked into the target shared library based on a set of conditions.

Some static libraries are "private" and aren't copied to packages, but
some are "public" in that they can be shipped in our nugets (when
dynamic runtime linking at app build time is implemented).  At the same
time, we have several build configurations which differ in their build
and link configurations, and especially in whether or not they link
against the shared C++ standard library or not.  In particular, the ASAN
and UBSAN builds require enabling of exceptions, RTTI and linking
against the shared C++ library.

Static component libraries will be built with the same set of
compilation and linking flags, and without modifying their output names
in some way, they may result in linking errors similar to:

```
native failed with 25 error(s) (0.6s) →
    ld.lld : error : undefined symbol: std::logic_error::logic_error(char const*)
    clang++ : error : linker command failed with exit code 1 (use -v to see invocation)
    ld.lld : error : undefined symbol: __gxx_personality_v0
    ld.lld : error : undefined symbol: __cxa_begin_catch
    ld.lld : error : undefined symbol: std::__ndk1::mutex::lock()
    ld.lld : error : undefined symbol: std::__ndk1::mutex::unlock()
    ld.lld : error : undefined symbol: __cxa_end_cleanup
```

This kind of errors may not show during the very first build of the
repository, but it will show on any subsequent build since the static
component library name used by **all** the configurations is the same,
but the compilation and linking flags are different.  If, e.g., UBSAN
build follows the standard build, it will replace the previously built
library with its own version but different linking requirements.
Subsequent build of non-UBSAN version of library will try to use the
static component library built with UBSAN flags, resulting in the
linking error above.

In order to avoid this kind of confusion but also minimize the number of
branches in CMake script files, this commit simply makes sure that all
the relevant static component libraries use an optional suffix when
generating their output.  By default the suffix is empty, resulting in
e.g. `libruntime-base.a`, but with UBSAN enabled, it will produce
`libruntime-base-ubsan.a` thus making sure the builds don't step on each
other's toes.
@grendello grendello requested a review from jonpryor as a code owner July 24, 2024 12:15
@grendello grendello merged commit 2ec6f54 into main Jul 24, 2024
56 of 58 checks passed
@grendello grendello deleted the dev/grendel/native-static-lib-suffix branch July 24, 2024 14:17
grendello added a commit that referenced this pull request Jul 24, 2024
* main:
  [native] Change name of static libraries in some cases (#9135)
  LEGO: Merge pull request 9134
@github-actions github-actions bot locked and limited conversation to collaborators Aug 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant