Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Compiling libm for std #290

Closed
wants to merge 3 commits into from

Conversation

Amjad50
Copy link
Contributor

@Amjad50 Amjad50 commented Feb 18, 2024

Added the ability to compile libm as a child dependency of std.

This will allow fixing the issue where some targets that don't have libc linked can have math functions without linking errors.

This fixes the issue originating in rust-lang/compiler-builtins#576

This also replaces #289 as its included in this one.

The commit 5e0eca7 removed the
`checked` feature and replaced it by using `debug_assertions`.

There were some places that were not modified, this commit fixes them
Since `std` dependencies cannot use `core` manually, it has to include
it manually as a dependencies from the package
`rustc-std-workspace-core`.

This allow us to use `libm` to compile a dependency of `std`.

This fixes the issue rust-lang/compiler-builtins#576
@Amjad50 Amjad50 changed the title Compiling libm for std Compiling libm for std Feb 18, 2024
@Amjad50
Copy link
Contributor Author

Amjad50 commented Feb 18, 2024

The compilation fails because of usage of internal feature

@Amanieu
Copy link
Member

Amanieu commented Feb 18, 2024

I think a better approach would be to have compiler-builtins always create the necessary symbols on all targets, but define them as weak symbols. There is already functionality for this in compiler-builtins, we just need to make sure it is disabled for targets that don't properly support weak symbols (Apple & Windows).

The reasoning behind this is to allow using platform-provided optimized versions of the math functions when they are available since they can be faster than our implementation in libm.

@Amjad50
Copy link
Contributor Author

Amjad50 commented Feb 18, 2024

Ah I didn't know about weak symbols, I'll look into it and add it there then, I'll close this then.

Thanks

Amjad50 added a commit to Amjad50/compiler-builtins that referenced this pull request Feb 19, 2024
This is a replacement for rust-lang/libm#290

This fixes crashes during compilations for targets that don't have math
symbols by default.

So, we will provide them libm symbols, but mark it as `weak` (if its
supported), so that the linker will choose the system builtin functions,
since those are sometimes more optimized.
If the linker couldn't find those, it will go with `libm`
implementation.
Amjad50 added a commit to Amjad50/Emerald that referenced this pull request Feb 23, 2024
This adds the missing functions `rust/std` require
that are normally available in `libc`

We will update `rust` as well to use these new functions.

We have modified `libm` in the PR: rust-lang/libm#290
to enable building `std`.
Amjad50 added a commit to Amjad50/compiler-builtins that referenced this pull request Mar 28, 2024
This is a replacement for rust-lang/libm#290

This fixes crashes during compilations for targets that don't have math
symbols by default.

So, we will provide them libm symbols, but mark it as `weak` (if its
supported), so that the linker will choose the system builtin functions,
since those are sometimes more optimized.
If the linker couldn't find those, it will go with `libm`
implementation.
Amjad50 added a commit to Amjad50/compiler-builtins that referenced this pull request Mar 28, 2024
This is a replacement for rust-lang/libm#290

This fixes crashes during compilations for targets that don't have math
symbols by default.

So, we will provide them libm symbols, but mark it as `weak` (if its
supported), so that the linker will choose the system builtin functions,
since those are sometimes more optimized.
If the linker couldn't find those, it will go with `libm`
implementation.
Amjad50 added a commit to Amjad50/compiler-builtins that referenced this pull request Mar 30, 2024
This is a replacement for rust-lang/libm#290

This fixes crashes during compilations for targets that don't have math
symbols by default.

So, we will provide them libm symbols, but mark it as `weak` (if its
supported), so that the linker will choose the system builtin functions,
since those are sometimes more optimized.
If the linker couldn't find those, it will go with `libm`
implementation.
Amanieu pushed a commit to Amjad50/compiler-builtins that referenced this pull request Apr 10, 2024
This is a replacement for rust-lang/libm#290

This fixes crashes during compilations for targets that don't have math
symbols by default.

So, we will provide them libm symbols, but mark it as `weak` (if its
supported), so that the linker will choose the system builtin functions,
since those are sometimes more optimized.
If the linker couldn't find those, it will go with `libm`
implementation.
@Amjad50 Amjad50 closed this Apr 10, 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.

2 participants