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

Fix incorrect LLVM Linkage enum #36200

Merged
merged 1 commit into from
Sep 5, 2016
Merged

Conversation

mattico
Copy link
Contributor

@mattico mattico commented Sep 1, 2016

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

@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 @alexcrichton (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

@bors: r+ 5897dcc8bba54ebd382a0fbf7afa20ea7b790963

Thanks!

@mattico
Copy link
Contributor Author

mattico commented Sep 2, 2016

4ce90a2 - Fixed tidy

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 2, 2016

📌 Commit 4ce90a2 has been approved by alexcrichton

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 4, 2016
Rollup of 7 pull requests

- Successful merges: #36070, #36132, #36200, #36212, #36225, #36231, #36234
- Failed merges:
@TimNN
Copy link
Contributor

TimNN commented Sep 4, 2016

This failed as part of the rollup:

---- [run-pass] run-pass/issue-33992.rs stdout ----

error: compilation failed!
status: signal: 6
command: /buildslave/rust-buildbot/slave/auto-linux-64-opt-rustbuild/build/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc /buildslave/rust-buildbot/slave/auto-linux-64-opt-rustbuild/build/src/test/run-pass/issue-33992.rs -L /buildslave/rust-buildbot/slave/auto-linux-64-opt-rustbuild/build/obj/build/x86_64-unknown-linux-gnu/test/run-pass --target=x86_64-unknown-linux-gnu --error-format json -L /buildslave/rust-buildbot/slave/auto-linux-64-opt-rustbuild/build/obj/build/x86_64-unknown-linux-gnu/test/run-pass/issue-33992.stage2-x86_64-unknown-linux-gnu.run-pass.libaux -C prefer-dynamic -o /buildslave/rust-buildbot/slave/auto-linux-64-opt-rustbuild/build/obj/build/x86_64-unknown-linux-gnu/test/run-pass/issue-33992.stage2-x86_64-unknown-linux-gnu -Crpath -O -Lnative=/buildslave/rust-buildbot/slave/auto-linux-64-opt-rustbuild/build/obj/build/x86_64-unknown-linux-gnu/rust-test-helpers
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
Should never emit this
UNREACHABLE executed at /buildslave/rust-buildbot/slave/auto-linux-64-opt-rustbuild/build/src/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:336!

------------------------------------------

@arielb1
Copy link
Contributor

arielb1 commented Sep 4, 2016

But LLVMLinkage is a part of the supposedly backwards-compatible C ABI! Should we wrap everything?

@TimNN
Copy link
Contributor

TimNN commented Sep 4, 2016

To quote the llvm source file AsmPrinter.cpp:336:

  case GlobalValue::ExternalWeakLinkage:
    llvm_unreachable("Should never emit this");
  }

So it's probably just that one linkage type which needs to be removed from the test.


extern "C" unsigned LLVMRustGetLinkage(LLVMValueRef V) {
switch (LLVMGetLinkage(V)) {
case LLVMExternalLinkage:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an enum (see LLVMRustDiagnosticKind).

bors added a commit that referenced this pull request Sep 4, 2016
Rollup of 7 pull requests

- Successful merges: #36070, #36132, #36200, #36212, #36225, #36231, #36234
- Failed merges:
@mattico
Copy link
Contributor Author

mattico commented Sep 4, 2016

@TimNN AppendingLinkage is part of the same case and should also be removed, I guess.

@mattico
Copy link
Contributor Author

mattico commented Sep 4, 2016

Updated to address issues.

@@ -49,6 +49,10 @@ pub enum CallConv {

/// LLVMLinkage
///
/// This does not attempt to mirror the similar enum in LLVM, as this is fragile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comment should be just /// LLVMRustLinkage - see e.g. LLVMRustAsmDialect. While you're at it, maybe also convert the other non-LLVMRust enums before they bite us?

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.

Fixes rust-lang#33992
@mattico
Copy link
Contributor Author

mattico commented Sep 4, 2016

Nits addressed, tests fixed, tidy passed, travis works! 🍀

@arielb1
Copy link
Contributor

arielb1 commented Sep 5, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Sep 5, 2016

📌 Commit b9a8c1a has been approved by arielb1

@bors
Copy link
Contributor

bors commented Sep 5, 2016

⌛ Testing commit b9a8c1a with merge 3f50b63...

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
@bors bors merged commit b9a8c1a into rust-lang:master Sep 5, 2016
@mattico mattico deleted the fix-llvm-linkage 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.

6 participants