]> git.lizzy.rs Git - rust.git/commit
Add a "link-guard" to avoid accidentally linking to a wrong dylib at runtime.
authorMichael Woerister <michaelwoerister@posteo.net>
Tue, 1 Mar 2016 13:19:00 +0000 (08:19 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Fri, 25 Mar 2016 18:07:19 +0000 (14:07 -0400)
commit247570732205fd226981082ee5c96c0abf5fed21
treebd688feb9cc055d362723d373fbc9a5bb40a0f1e
parent82b5f1d8690ec538557ce3f355add91e3809ba51
Add a "link-guard" to avoid accidentally linking to a wrong dylib at runtime.

We want to prevent compiling something against one version
of a dynamic library and then, at runtime accidentally
using a different version of the dynamic library. With the
old symbol-naming scheme this could not happen because every
symbol had the SVH in it and you'd get an error by the
dynamic linker when using the wrong version of a dylib. With
the new naming scheme this isn't the case any more, so this
patch adds the "link-guard" to prevent this error case.

This is implemented as follows:

- In every crate that we compile, we emit a function called
  "__rustc_link_guard_<crate-name>_<crate-svh>"
- The body of this function contains calls to the
  "__rustc_link_guard" functions of all dependencies.
- An executable contains a call to it's own
  "__rustc_link_guard" function.

As a consequence the "__rustc_link_guard" function call graph
mirrors the crate graph and the dynamic linker will fail if a
wrong dylib is loaded somewhere because its
"__rustc_link_guard" function will contain a different SVH in
its name.
14 files changed:
src/librustc/middle/cstore.rs
src/librustc_metadata/creader.rs
src/librustc_metadata/csearch.rs
src/librustc_metadata/cstore.rs
src/librustc_metadata/decoder.rs
src/librustc_trans/back/linker.rs
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/link_guard.rs [new file with mode: 0644]
src/librustc_trans/trans/mod.rs
src/test/run-make/link-guard/Makefile [new file with mode: 0644]
src/test/run-make/link-guard/bad/lib.rs [new file with mode: 0644]
src/test/run-make/link-guard/good/lib.rs [new file with mode: 0644]
src/test/run-make/link-guard/main.rs [new file with mode: 0644]
src/test/run-make/relocation-model/Makefile