diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-01-21 23:11:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-21 23:11:38 +0100 |
| commit | ab54a9c73c0bdb7df9693598c9e18840fccac6e1 (patch) | |
| tree | 8e86e7a787122aeb3034e74da05ec15eaddba08d /src/test/debuginfo/enum-thinlto.rs | |
| parent | 6bb1b0dd3793db24fb1214640af72a5e8c66dded (diff) | |
| parent | 090a968fe7680cce0d3aa8fde25a5dc48948e43e (diff) | |
| download | rust-ab54a9c73c0bdb7df9693598c9e18840fccac6e1.tar.gz rust-ab54a9c73c0bdb7df9693598c9e18840fccac6e1.zip | |
Rollup merge of #47334 - etaoins:only-call-res-init-on-gnu-unix, r=alexcrichton
Only link res_init() on GNU/*nix
To workaround a bug in glibc <= 2.26 lookup_host() calls res_init() based on the glibc version detected at runtime. While this avoids calling res_init() on platforms where it's not required we will still end up linking against the symbol.
This causes an issue on macOS where res_init() is implemented in a separate library (libresolv.9.dylib) from the main libc. While this is harmless for standalone programs it becomes a problem if Rust code is statically linked against another program. If the linked program doesn't already specify -lresolv it will cause the link to fail. This is captured in issue #46797
Fix this by hooking in to the glibc workaround in `cvt_gai` and only activating it for the "gnu" environment on Unix This should include all glibc platforms while excluding musl, windows-gnu, macOS, FreeBSD, etc.
This has the side benefit of removing the #[cfg] in sys_common; only unix.rs has code related to the workaround now.
Before this commit:
```shell
> cat main.rs
use std::net::ToSocketAddrs;
#[no_mangle]
pub extern "C" fn resolve_test() -> () {
let addr_list = ("google.com.au", 0).to_socket_addrs().unwrap();
println!("{:?}", addr_list);
}
> rustc --crate-type=staticlib main.rs
> clang libmain.a test.c -o combined
Undefined symbols for architecture x86_64:
"_res_9_init", referenced from:
std::net::lookup_host::h93c17fe9ad38464a in libmain.a(std-826c8d3b356e180c.std0.rcgu.o)
ld: symbol(s) not found for architecture x86_64
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
```
Afterwards:
```shell
> rustc --crate-type=staticlib main.rs
> clang libmain.a test.c -o combined
> ./combined
IntoIter([V4(172.217.25.131:0)])
```
Fixes #46797
Diffstat (limited to 'src/test/debuginfo/enum-thinlto.rs')
0 files changed, 0 insertions, 0 deletions
