anp / rusl

An experimental (read: DONT USE) musl libc implementation in Rust.
Other
292 stars 12 forks source link

Make symbol linkage weak in certain cases #11

Closed mrhota closed 7 years ago

mrhota commented 7 years ago

Musl makes the linkage of some symbols weak (using weak_alias(foo, bar)). Currently, the list of symbols which don't have weak linkage attributes looks like this:

Weak linkage is a feature of ELF binaries, so it's not supported in Windows or Mac OS X. It should be as simple as an attribute like so on the above functions:

#[cfg_attr(all(feature = "weak", not(windows), not(target_os = "macos")), linkage = "weak")]

And an attribute like so to enable the linkage feature:

#![cfg_attr(all(feature = "weak", not(windows), not(target_os = "macos")), feature(linkage))]

See the Rust reference and rlibc repository for more.

anp commented 7 years ago

I had some issues with weak linkage for these symbols before (as well as malloc, free, etc) when compiling on a much older nightly. If you're able to make this work, I'd certainly be happy. Although we'd want some way to test the weak linkage on Travis now that libc-test has been submodule'd.

I'm not really sure it matters how link args are handled on Windows or Mac -- (m|r)usl only supports Linux, and even if cross compiling is useful we wouldn't want the symbols to stop being weak when cross compiling. I guess this also gets at a broader question of platform compatibility, but since Linux is the only environment I'm aware of with a stable syscall ABI, I don't see it being very useful to compile rusl for other platforms. Your thoughts?

mrhota commented 7 years ago

I think the linkage feature is broken in rustc. I annotated all the symbols, just like in rlibc, but nothing came out with weak linkage. I think there's an issue in the rust repo indicating that linkage is broken, but I can't find it now

anp commented 7 years ago

Looks like the progress here is being tracked in https://github.com/rust-lang/rust/issues/29603, although that doesn't reference any issues which explicitly list it as broken.

mrhota commented 7 years ago

Closed by #15