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

rustc: Support various flavors of linkages #12556

Merged
merged 1 commit into from
Mar 11, 2014

Commits on Mar 11, 2014

  1. rustc: Support various flavors of linkages

    It is often convenient to have forms of weak linkage or other various types of
    linkage. Sadly, just using these flavors of linkage are not compatible with
    Rust's typesystem and how it considers some pointers to be non-null.
    
    As a compromise, this commit adds support for weak linkage to external symbols,
    but it requires that this is only placed on extern statics of type `*T`.
    Codegen-wise, we get translations like:
    
        // rust code
        extern {
            #[linkage = "extern_weak"]
            static foo: *i32;
        }
    
        // generated IR
        @foo = extern_weak global i32
        @_some_internal_symbol = internal global *i32 @foo
    
    All references to the rust value of `foo` then reference `_some_internal_symbol`
    instead of the symbol `_foo` itself. This allows us to guarantee that the
    address of `foo` will never be null while the value may sometimes be null.
    
    An example was implemented in `std::rt::thread` to determine if
    `__pthread_get_minstack()` is available at runtime, and a test is checked in to
    use it for a static value as well. Function pointers a little odd because you
    still need to transmute the pointer value to a function pointer, but it's
    thankfully better than not having this capability at all.
    alexcrichton committed Mar 11, 2014
    5 Configuration menu
    Copy the full SHA
    699b33d View commit details
    Browse the repository at this point in the history