-
Notifications
You must be signed in to change notification settings - Fork 16.3k
MC: Support quoted symbol names #138817
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
MaskRay
merged 3 commits into
main
from
users/MaskRay/spr/mc-support-quoted-symbol-names
May 8, 2025
Merged
MC: Support quoted symbol names #138817
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,28 @@ | ||
| // RUN: llvm-mc -triple i686-pc-linux -filetype=obj %s -o - | llvm-readobj --symbols - | FileCheck %s | ||
| // RUN: llvm-mc -triple=x86_64 -filetype=obj %s | llvm-objdump -tdr - | FileCheck %s | ||
|
|
||
| // MC allows ?'s in symbol names as an extension. | ||
|
|
||
| // CHECK-LABEL:SYMBOL TABLE: | ||
| // CHECK-NEXT: 0000000000000001 l F .text 0000000000000000 a"b\{{$}} | ||
| // CHECK-NEXT: 0000000000000006 l .text 0000000000000000 a\{{$}} | ||
| // CHECK-NEXT: 0000000000000000 g F .text 0000000000000000 foo?bar | ||
| // CHECK-NEXT: 0000000000000000 *UND* 0000000000000000 a"b\q{{$}} | ||
| // CHECK-EMPTY: | ||
|
|
||
| .text | ||
| .globl foo?bar | ||
| .type foo?bar, @function | ||
| foo?bar: | ||
| ret | ||
|
|
||
| // CHECK: Symbol | ||
| // CHECK: Name: foo?bar | ||
| // CHECK-LABEL:<a"b\>: | ||
| // CHECK-NEXT: callq {{.*}} <a"b\> | ||
| // CHECK-LABEL:<a\>: | ||
| // CHECK-NEXT: callq {{.*}} | ||
| // CHECK-NEXT: R_X86_64_PLT32 a"b\q-0x4 | ||
| .type "a\"b\\", @function | ||
| "a\"b\\": | ||
| call "a\"b\\" | ||
| "a\\": | ||
| /// GAS emits a warning for \q | ||
| call "a\"b\q" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this unescaping only be done when parsing textual assembly in AsmParser, but not when programmatically creating symbols?
I'd expect the LLVM IR
@"\\\22" = constant i8 0to result in"\\\"":rather than"\"":, as it does with this patch. (Previously it resulted in"\\"":, which is also wrong, but at least only affects the case where you're emitting assembly.)See rust-lang/rust#146065 for a regression from this change. Of course we could easily apply additional escaping on the Rust side, but I think the current behavior here isn't right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just saw this message. I agree that ideally this should be limited to texual assembly in MC/MCParser/AsmParser.cpp. Unfortunately this is challenging because the wide-used API
AsmParser::parseIdentifier(used ~107 times) takes aStringRefinstead of an owned string. It seems a lot of work to fix parseIdentifier...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a problem. I put up #158106 to put at least some of these uses behind a common API.
A simple option would be to just keep StringRef and have the backing storage in an Allocator. This would avoid API changes and should not really be a performance or memory usage problem as long as quoted symbols are rare.
Though I'm not sure whether all uses of parseIdentifier should parse quoted strings or not.