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

[WIP] Fix incorrect LLVM Linkage enum #33994

Closed
wants to merge 1 commit into from

Conversation

mattico
Copy link
Contributor

@mattico mattico commented May 31, 2016

The Linkage enum in librustc_llvm got out of sync with the version in LLVM and it caused two variants of the #[linkage=""] attribute to break.

Fixes #33992

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Aatch (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

Ah the test looks like it may fail for two reasons:

  • It's gonna be compiled as an executable, and lacking a main function will cause that to fail
  • Are you sure all those linkage types are supported on all platforms? This could perhaps be a codegen test where we just test the LLVM IR output

@alexcrichton
Copy link
Member

Thanks for the PR though! The fix looks fine to me :)

@brson
Copy link
Contributor

brson commented May 31, 2016

Since this enum has changed it will break compatibility with any older versions of LLVM right? Should we also change the configure script to reject older LLVM versions?

@alexcrichton
Copy link
Member

alexcrichton commented May 31, 2016

Oh I was assuming that we just never had the right definition. If this changed in LLVM over time, though, then we should define our own enum with our own discriminants and then translate in C++ to the LLVM symbolic names.

@mattico
Copy link
Contributor Author

mattico commented May 31, 2016

@alexcrichton Good points. I'll update the PR once I actually get the tests to run locally...

@mattico
Copy link
Contributor Author

mattico commented Jun 1, 2016

Turns out the build failures I was having were due to this change. I was basing the enum values off of the github master branch of the llvm repo and that is very different from the submodule included in the rust distribution. After double-triple-checking that the enum values line up between my local rust and the local rust's llvm, I get the following error about 100 times:

Only global variables can have appending linkage!
i1 (%"option::Option<usize>"*, %"option::Option<usize>"*)* @"_ZN70_$LT$core..option..Option$LT$T$GT$$u20$as$u20$core..cmp..PartialEq$GT$2ne17hdb2b03f033fe475fE"
Only global variables can have appending linkage!
void (%"char::EscapeDefault"*, %"char::EscapeDefault"*)* @"_ZN54_$LT$I$u20$as$u20$core..iter..traits..IntoIterator$GT$9into_iter17h46cca4884daa3d2bE"
Only global variables can have appending linkage!
i8 (%"fmt::Formatter"*, float*, i1)* @_ZN4core3fmt23float_to_decimal_common17h1cc684f615bc0ea2E
Only global variables can have appending linkage!
<snip>
Only global arrays can have appending linkage!
i64* @const27542
Only global arrays can have appending linkage!
i8* @const27560
Only global arrays can have appending linkage!
i8* @const27561
Only global arrays can have appending linkage!
i32* @const27562
Only global arrays can have appending linkage!
i32* @const27563
Only global arrays can have appending linkage!

I can't find anywhere in the stdlib or compiler that AppendingLinkage is used, so this is very puzzling to me.

It seems this change is not as simple as I had thought.

@mattico mattico changed the title Fix incorrect LLVM Linkage enum [WIP] Fix incorrect LLVM Linkage enum Jun 1, 2016
@mattico mattico force-pushed the fix-linkage-attribute branch from 3611953 to f04c77f Compare June 1, 2016 18:57
The `Linkage` enum in librustc_llvm got out of sync with the version in LLVM and it caused two variants of the #[linkage=""] attribute to break.

Fixes rust-lang#33992
@mattico mattico force-pushed the fix-linkage-attribute branch from f04c77f to 3e0f018 Compare June 1, 2016 19:12
@alexcrichton
Copy link
Member

Oh that may just be a case that's OK to elide, appending linkage I think is a pretty special LLVM-ism

@mattico
Copy link
Contributor Author

mattico commented Jun 1, 2016

@alexcrichton I'll try that.

You mentioned translating the rust enum to the LLVM enum in C++, would that code go in librustllvm?

@alexcrichton
Copy link
Member

@mattico yeah, I was thinking something like:

// src/librustc_llvm/lib.rs
pub enum RustLinkage {
    External,
    // ...
}
void SetLinkage(LLVMValue V, unsigned RustLinkage) {
    switch (RustLinkage) {
        case 0:
            SetLLVMLinkage(v, LLVMExternalLinkage);
            break;
        // ...
    }
}

(or something like that)

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to reopen with comments addressed!

Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 4, 2016
…chton

Fix incorrect LLVM Linkage enum

Followup of rust-lang#33994 to actually work.

The `Linkage` enum in librustc_llvm got out of sync with the version in LLVM and it caused two variants of the `#[linkage=""]` attribute to break.

This adds the functions `LLVMRustGetLinkage` and `LLVMRustSetLinkage` which convert between the Rust Linkage enum and the LLVM one, which should stop this from breaking every time LLVM changes it.

Possible remaining concerns:

1. There could be a codegen test to make sure that the attributes are applied correctly (I don't know how to do this).
2. The test does not exercise the `appending` linkage. I can't figure out how to make a global static raw pointer to an array. This might not even be possible? If not we should probably remove appending linkage as its unusable in rust.
3. The test only runs on Linux.

Fixes rust-lang#33992

r? @alexcrichton
bors added a commit that referenced this pull request Sep 5, 2016
Fix incorrect LLVM Linkage enum

Followup of #33994 to actually work.

The `Linkage` enum in librustc_llvm got out of sync with the version in LLVM and it caused two variants of the `#[linkage=""]` attribute to break.

This adds the functions `LLVMRustGetLinkage` and `LLVMRustSetLinkage` which convert between the Rust Linkage enum and the LLVM one, which should stop this from breaking every time LLVM changes it.

Possible remaining concerns:

1. There could be a codegen test to make sure that the attributes are applied correctly (I don't know how to do this).
2. ~~The test does not exercise the `appending` linkage. I can't figure out how to make a global static raw pointer to an array. This might not even be possible? If not we should probably remove appending linkage as its unusable in rust.~~ Appending linkage is not 'emittable' anyway.
3. The test only runs on Linux.

Fixes #33992

r? @alexcrichton
@mattico mattico deleted the fix-linkage-attribute branch September 5, 2016 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants