Skip to content

Commit aae6c0f

Browse files
Explicitly pass RTLD_LOCAL to dlopen
This happens to be the default on Linux, but the default is unspecified in the POSIX standard. Also switches to `cast` to keep line lengths in check.
1 parent f07011b commit aae6c0f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/librustc_metadata/dynamic_lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ mod dl {
9999
let s = CString::new(filename.as_bytes()).unwrap();
100100

101101
let mut dlerror = error::lock();
102-
let ret = unsafe { libc::dlopen(s.as_ptr(), libc::RTLD_LAZY) } as *mut u8;
102+
let ret = unsafe { libc::dlopen(s.as_ptr(), libc::RTLD_LAZY | libc::RTLD_LOCAL) };
103103

104104
if !ret.is_null() {
105-
return Ok(ret);
105+
return Ok(ret.cast());
106106
}
107107

108108
// A NULL return from `dlopen` indicates that an error has definitely occurred, so if
@@ -122,10 +122,10 @@ mod dl {
122122
// error message by accident.
123123
dlerror.clear();
124124

125-
let ret = libc::dlsym(handle as *mut libc::c_void, symbol) as *mut u8;
125+
let ret = libc::dlsym(handle as *mut libc::c_void, symbol);
126126

127127
if !ret.is_null() {
128-
return Ok(ret);
128+
return Ok(ret.cast());
129129
}
130130

131131
// If `dlsym` returns NULL but there is nothing in `dlerror` it means one of two things:

0 commit comments

Comments
 (0)