Skip to content

rustc: Fail if LLVM is passed an invalid triple #18411

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

Merged
merged 1 commit into from
Oct 31, 2014

Conversation

richo
Copy link
Contributor

@richo richo commented Oct 29, 2014

This changes create_target_machine to correctly return a Result (Since
the underlying LLVM function can fail and return NULL)

There's an underlying issue that our build infra doesn't stop you from
getting to this point, but this at least turns a segfault into an ICE.

@rust-highfive
Copy link
Contributor

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@richo richo changed the title rustc::back: fail if a valid triple can't be found rustc: Fail if LLVM is passed an invalid triple Oct 29, 2014
@richo
Copy link
Contributor Author

richo commented Oct 29, 2014

This actually wasn't nearly as invasive as I first thought. This should be safe to merge.

return Err(error_str);
} else {
return Ok(tm);
};
Copy link
Member

Choose a reason for hiding this comment

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

This may want to instead leverage the llvm_err method at the top of this file just to ensure we're not duplicating logic with LLVMRustGetLastError

Copy link
Member

Choose a reason for hiding this comment

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

This also seems easy enough to turn the ICE into a normal compiler error via the call to fatal in llvm_err, so could a test be added for this as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes to both- Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've gone up a bunch of frames, and I can't find a Handler in scope. Is there somewhere specific I should be looking?

(I also have a vague concern that this is limiting the reusability of a lot of the target selection code. I'm not sure that's actually a problem though, because I don't have a good sense of how reusable librustc is meant to be)

Copy link
Member

Choose a reason for hiding this comment

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

I think you can get one out of a Session via sess.diagnostic().handler() (or something attached to a Session like that).

Also yeah it's fine to not worry about the reusability librustc, it's not planned to :)

@richo
Copy link
Contributor Author

richo commented Oct 29, 2014

I've updated the branch.

Writing a test for this is hard because I think this condition was only possible due to quirks in the build infrastructure.

I can push the power port I've been working on which currently exhibits the failure if that would help, but unless you can see something I can't I think this is ready to go out

This changes create_target_machine to correctly return a Result (Since
the underlying LLVM function can fail and return NULL)
@alexcrichton
Copy link
Member

Ah I see, I do seem to remember that we try to do validation ahead of time wherever possible anyway. Thanks for looking into it! (it's ok to not have a test)

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Oct 30, 2014
@bors bors merged commit 89e8caa into rust-lang:master Oct 31, 2014
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.

4 participants