Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of dllexport #27416

Merged
merged 2 commits into from
Aug 11, 2015
Merged

Commits on Aug 11, 2015

  1. syntax: Add a new unstable #[linked_from] attribute

    To correctly reexport statically included libraries from a DLL on Windows, the
    compiler will soon need to have knowledge about what symbols are statically
    included and which are not. To solve this problem a new unstable
    `#[linked_from]` attribute is being added and recognized on `extern` blocks to
    indicate which native library the symbols are coming from.
    
    The compiler then keeps track of what the set of FFI symbols are that are
    included statically. This information will be used in a future commit to
    configure how we invoke the linker on Windows.
    alexcrichton committed Aug 11, 2015
    Configuration menu
    Copy the full SHA
    1860714 View commit details
    Browse the repository at this point in the history
  2. trans: Stop informing LLVM about dllexport

    Rust's current compilation model makes it impossible on Windows to generate one
    object file with a complete and final set of dllexport annotations. This is
    because when an object is generated the compiler doesn't actually know if it
    will later be included in a dynamic library or not. The compiler works around
    this today by flagging *everything* as dllexport, but this has the drawback of
    exposing too much.
    
    Thankfully there are alternate methods of specifying the exported surface area
    of a dll on Windows, one of which is passing a `*.def` file to the linker which
    lists all public symbols of the dynamic library. This commit removes all
    locations that add `dllexport` to LLVM variables and instead dynamically
    generates a `*.def` file which is passed to the linker. This file will include
    all the public symbols of the current object file as well as all upstream
    libraries, and the crucial aspect is that it's only used when generating a
    dynamic library. When generating an executable this file isn't generated, so all
    the symbols aren't exported from an executable.
    
    To ensure that statically included native libraries are reexported correctly,
    the previously added support for the `#[linked_from]` attribute is used to
    determine the set of FFI symbols that are exported from a dynamic library, and
    this is required to get the compiler to link correctly.
    alexcrichton committed Aug 11, 2015
    Configuration menu
    Copy the full SHA
    e648c96 View commit details
    Browse the repository at this point in the history