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

[MSP430] Do not generate '@' character in symbol names. #38286

Merged
merged 1 commit into from
Dec 13, 2016

Conversation

pftbest
Copy link
Contributor

@pftbest pftbest commented Dec 10, 2016

MSP430 assembler does not like '@' character in symbol names, so we need
to replace it with some other character.

Fixes #38116

@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 @arielb1 (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.

@japaric
Copy link
Member

japaric commented Dec 10, 2016

cc @eddyb @michaelwoerister you may have some thoughts about this. I don't know if having a single target that uses a different format for symbol names would cause problems in debuginfo or incr. compilation or somewhere else.

This target, msp430, is a little weird though because llvm can't generate object files for it so we are making llvm emit assembly (.s files) and then converting those into object files using gcc (msp430-gcc). So ... I think that means we can't even embed debuginfo into the object file in the first place (?).


// MSP430 assembler does not like '@' character in symbol names.
if self.sess().target.target.arch == "msp430" {
name = str::replace(&name[..], "@", "_");
Copy link
Member

Choose a reason for hiding this comment

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

Where does the @ even come from? prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, prefix is ok, the @ comes from base_n

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other solution would be to use smaller MAX_BASE on msp430. That way there will be no string allocation and copying.

Copy link
Member

Choose a reason for hiding this comment

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

Aaaah. What is even MAX_BASE? FWIW @ is one of the characters we "escape" in symbols, on all targets.
So we don't actually consider it safe enough to use, although here it doesn't matter as much because it's unexported.

Another question nagging me is: do we really need this function? LLVM can handle multiple definitions with no name or with the same "informative" name without us needing to keep our own counters. Where are we keeping these Strings generated here, and if they're stored in CrateContext, why isn't the ValueRef kept instead?

Copy link
Member

Choose a reason for hiding this comment

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

The function could probably be refactored away, yes.

As to MAX_BASE and @: Using a base64 encoding for the counter was an attempt to keep IR small after people complaining that it was too big. An unnecessary optimization as it turned out because it made no real difference.

@brson
Copy link
Contributor

brson commented Dec 11, 2016

r? @michaelwoerister

Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Since the counter containing the @ is something purely cosmetic this could also easily be handled consistently for all platforms. My suggestion would be:

  • Add a pub const ALPHA_NUMERIC_ONLY = 62 to base_n ...
  • ... and use that instead of MAX_BASE in generate_local_symbol_name.

@pftbest, would you mind adapting the PR in this way?


// MSP430 assembler does not like '@' character in symbol names.
if self.sess().target.target.arch == "msp430" {
name = str::replace(&name[..], "@", "_");
Copy link
Member

Choose a reason for hiding this comment

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

The function could probably be refactored away, yes.

As to MAX_BASE and @: Using a base64 encoding for the counter was an attempt to keep IR small after people complaining that it was too big. An unnecessary optimization as it turned out because it made no real difference.

MSP430 assembler does not like '@' character in symbol names, so we should
only use alphanumerics when we generate a new name.

Fixes rust-lang#38116
@pftbest
Copy link
Contributor Author

pftbest commented Dec 12, 2016

@michaelwoerister Updated the PR

@michaelwoerister
Copy link
Member

@bors r+

Thanks, @pftbest, that should do the trick :)

@bors
Copy link
Contributor

bors commented Dec 12, 2016

📌 Commit 9d764fc has been approved by michaelwoerister

@japaric japaric mentioned this pull request Dec 12, 2016
9 tasks
@bors
Copy link
Contributor

bors commented Dec 13, 2016

⌛ Testing commit 9d764fc with merge ace092f...

bors added a commit that referenced this pull request Dec 13, 2016
[MSP430] Do not generate '@' character in symbol names.

MSP430 assembler does not like '@' character in symbol names, so we need
to replace it with some other character.

Fixes #38116
@bors bors merged commit 9d764fc into rust-lang:master Dec 13, 2016
@pftbest pftbest deleted the msp430_at_symbol branch December 13, 2016 16:19
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.

8 participants