Skip to content

Commit 760384c

Browse files
authored
Merge pull request #1810 from hermit-os/libm-symbols
feat(hermit-builtins): allow merging libm symbols
2 parents 7577f3a + ca525d3 commit 760384c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

hermit-builtins/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![no_std]
2+
#![feature(linkage)]
23

34
pub mod math;
45

hermit-builtins/src/math.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
macro_rules! export {
66
($(fn $fn:ident($($arg:ident: $argty:ty),+) -> $retty:ty;)+) => {
77
$(
8+
#[linkage = "weak_odr"]
89
#[unsafe(no_mangle)]
910
pub extern "C" fn $fn($($arg: $argty),+) -> $retty {
1011
::libm::$fn($($arg),+)
@@ -143,6 +144,7 @@ export! {
143144
macro_rules! export_out_param {
144145
($(fn $fn:ident($($arg:ident: $argty:ty),+; $out:ident: $outty:ty) -> $retty:ty;)+) => {
145146
$(
147+
#[linkage = "weak_odr"]
146148
#[unsafe(no_mangle)]
147149
pub extern "C" fn $fn($($arg: $argty),+, $out: $outty) -> $retty {
148150
let (ret, out) = ::libm::$fn($($arg),+);
@@ -164,11 +166,13 @@ export_out_param! {
164166
fn remquof(x: f32, y: f32; n: &mut i32) -> f32;
165167
}
166168

169+
#[linkage = "weak_odr"]
167170
#[unsafe(no_mangle)]
168171
pub extern "C" fn sincos(x: f64, s: &mut f64, c: &mut f64) {
169172
(*s, *c) = libm::sincos(x);
170173
}
171174

175+
#[linkage = "weak_odr"]
172176
#[unsafe(no_mangle)]
173177
pub extern "C" fn sincosf(x: f32, s: &mut f32, c: &mut f32) {
174178
(*s, *c) = libm::sincosf(x);
@@ -181,6 +185,7 @@ pub extern "C" fn sincosf(x: f32, s: &mut f32, c: &mut f32) {
181185
/// `arg` has to point to a valid [`CStr`].
182186
///
183187
/// [`CStr`]: core::ffi::CStr
188+
#[linkage = "weak_odr"]
184189
#[unsafe(no_mangle)]
185190
pub unsafe extern "C" fn nan(arg: *const core::ffi::c_char) -> f64 {
186191
let _arg = arg;
@@ -194,6 +199,7 @@ pub unsafe extern "C" fn nan(arg: *const core::ffi::c_char) -> f64 {
194199
/// `arg` has to point to a valid [`CStr`].
195200
///
196201
/// [`CStr`]: core::ffi::CStr
202+
#[linkage = "weak_odr"]
197203
#[unsafe(no_mangle)]
198204
pub unsafe extern "C" fn nanf(arg: *const core::ffi::c_char) -> f32 {
199205
let _arg = arg;

0 commit comments

Comments
 (0)