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

The war of symbol and symbol (the PR dedicated to duplicate symbols breaking rustc in unexpected ways) #23011

Merged
merged 14 commits into from
Apr 12, 2015

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Mar 3, 2015

We provide tools to tell what exact symbols to emit for any fn or static, but
don’t quite check if that won’t cause any issues later on. Some of the issues
include LLVM mangling our names again and our names pointing to wrong locations,
us generating dumb foreign call wrappers, linker errors, extern functions
resolving to different symbols altogether (extern {fn fail();} fail(); in some
cases calling fail1()), etc.

Before the commit we had a function called note_unique_llvm_symbol, so it is
clear somebody was aware of the issue at some point, but the function was barely
used, mostly in irrelevant locations.

Along with working on it I took liberty to start refactoring trans/base into
a few smaller modules. The refactoring is incomplete and I hope I will find some
motivation to carry on with it.

This is possibly a [breaking-change] because it makes dumbly written code
properly invalid.

This fixes all those issues about incorrect use of #[no_mangle] being not reported/misreported/ICEd by the compiler.

NB. This PR does not attempt to tackle the parallel codegen issue that was mentioned in #22811, but I believe it should be very straightforward in a follow up PR by modifying trans::declare::get_defined_value to look at all the contexts.

cc @alexcrichton @huonw @nrc because you commented on the original RFC issue.

EDIT: wow, this became much bigger than I initially intended.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@nagisa nagisa changed the title The war of symbol and symbol The war of symbol and symbol (the PR dedicated to duplicate symbols breaking rustc in unexpected ways) Mar 3, 2015
if is_origin { OriginalTranslation } else { InlinedCopy });

if is_entry_fn(ccx.sess(), item.id) {
Copy link
Member Author

Choose a reason for hiding this comment

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

NB: before the move of this block from finish_register_fn we reported “compilation successful” error before we created the entry wrapper or actually translated contents of the entry function.

@alexcrichton
Copy link
Member

This seems like a fine refactoring to me, thanks @nagisa! I'm not trans hacker though so I'm not comfortable r+'ing

@nagisa nagisa force-pushed the the-war-of-symbol-and-symbol branch from 4ac3765 to e1f7a6b Compare March 4, 2015 09:52
@nagisa
Copy link
Member Author

nagisa commented Mar 4, 2015

Thanks for taking a look @alexcrichton!

// These are not really pointers but pairs, (pointer, len)
ty::ty_uniq(it) |
ty::ty_rptr(_, ty::mt { ty: it, .. }) if !common::type_is_sized(ccx.tcx(), it) => {}
ty::ty_uniq(inner) | ty::ty_rptr(_, ty::mt { ty: inner, .. }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the double negative?

Copy link
Member Author

Choose a reason for hiding this comment

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

This function has only been moved and renamed from base::get_fn_llvm_attributes only. The body has seen no changes (other than variable renames, of course).

Nicely spotted, nevertheless. I will go ahead and fix this.

@bors
Copy link
Contributor

bors commented Mar 12, 2015

☔ The latest upstream changes (presumably #23265) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix
Copy link
Member

(i'm going to be out until wedneday; but I will try to get to this then. sorry for the absurd delay; maybe you can rebase in the meantime @nagisa )

@nagisa nagisa force-pushed the the-war-of-symbol-and-symbol branch from 07e593c to caa5001 Compare March 13, 2015 11:10
@bors
Copy link
Contributor

bors commented Mar 13, 2015

☔ The latest upstream changes (presumably #23337) made this pull request unmergeable. Please resolve the merge conflicts.

@nagisa nagisa force-pushed the the-war-of-symbol-and-symbol branch from caa5001 to e935301 Compare March 13, 2015 21:04
@bors
Copy link
Contributor

bors commented Mar 17, 2015

☔ The latest upstream changes (presumably #23376) made this pull request unmergeable. Please resolve the merge conflicts.

@nagisa nagisa force-pushed the the-war-of-symbol-and-symbol branch from e935301 to 46b0b82 Compare March 20, 2015 13:09
@nagisa
Copy link
Member Author

nagisa commented Mar 20, 2015

Rebased. I didn’t even notice the last breakage until now, didn’t get github mail.

@bors
Copy link
Contributor

bors commented Mar 24, 2015

☔ The latest upstream changes (presumably #23654) made this pull request unmergeable. Please resolve the merge conflicts.

@nagisa nagisa force-pushed the the-war-of-symbol-and-symbol branch from 46b0b82 to 91e9f9d Compare March 26, 2015 18:50
@nagisa
Copy link
Member Author

nagisa commented Mar 26, 2015

Rebased.

@pnkfelix
Copy link
Member

@nagisa my plan is to review this right after the beta-release, is that okay with you?

@nagisa
Copy link
Member Author

nagisa commented Mar 28, 2015

Sure, been waiting for a month, can easily wait a few weeks more. I’ll have to rigorously review the patch for bitrot, though.

@pnkfelix
Copy link
Member

@nagisa yeah, sorry about the delay...

@bors
Copy link
Contributor

bors commented Apr 1, 2015

☔ The latest upstream changes (presumably #23936) made this pull request unmergeable. Please resolve the merge conflicts.

It emits the same symbol – `transmute` – from the same crate twice.
nagisa added 10 commits April 3, 2015 15:46
This discovers another class of mis-trans where we wrap multiple native functions into a single
wrapper, which is wrong.
This commit causes no change in trans semantics, it just moves some functions around and
deduplicates them.
These functions have only a single use and functionally belong to foreign and glue respectively
anyway
We provide tools to tell what exact symbols to emit for any fn or static, but
don’t quite check if that won’t cause any issues later on. Some of the issues
include LLVM mangling our names again and our names pointing to wrong locations,
us generating dumb foreign call wrappers, linker errors, extern functions
resolving to different symbols altogether (extern {fn fail();} fail(); in some
cases calling fail1()), etc.

Before the commit we had a function called note_unique_llvm_symbol, so it is
clear somebody was aware of the issue at some point, but the function was barely
used, mostly in irrelevant locations.

Along with working on it I took liberty to start refactoring trans/base into
a few smaller modules. The refactoring is incomplete and I hope I will find some
motivation to carry on with it.

This is possibly a [breaking-change] because it makes dumbly written code
properly invalid.
@nagisa nagisa force-pushed the the-war-of-symbol-and-symbol branch from 91e9f9d to 16881af Compare April 3, 2015 12:48
@nagisa nagisa force-pushed the the-war-of-symbol-and-symbol branch from 16881af to 000db38 Compare April 3, 2015 21:22
@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 12, 2015

📌 Commit 000db38 has been approved by pnkfelix

@bors
Copy link
Contributor

bors commented Apr 12, 2015

⌛ Testing commit 000db38 with merge 5afa270...

bors added a commit that referenced this pull request Apr 12, 2015
We provide tools to tell what exact symbols to emit for any fn or static, but
don’t quite check if that won’t cause any issues later on. Some of the issues
include LLVM mangling our names again and our names pointing to wrong locations,
us generating dumb foreign call wrappers, linker errors, extern functions
resolving to different symbols altogether (`extern {fn fail();} fail();` in some
cases calling `fail1()`), etc.

Before the commit we had a function called `note_unique_llvm_symbol`, so it is
clear somebody was aware of the issue at some point, but the function was barely
used, mostly in irrelevant locations.

Along with working on it I took liberty to start refactoring trans/base into
a few smaller modules. The refactoring is incomplete and I hope I will find some
motivation to carry on with it.

This is possibly a [breaking-change] because it makes dumbly written code
properly invalid.

This fixes all those issues about incorrect use of #[no_mangle] being not reported/misreported/ICEd by the compiler.

NB. This PR does not attempt to tackle the parallel codegen issue that was mentioned in #22811, but I believe it should be very straightforward in a follow up PR by modifying `trans::declare::get_defined_value` to look at all the contexts.

cc @alexcrichton @huonw @nrc because you commented on the original RFC issue.

EDIT: wow, this became much bigger than I initially intended.
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