-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
MaskRay
merged 3 commits into
main
from
users/MaskRay/spr/mc-support-quoted-symbol-names
May 8, 2025
Conversation
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
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-mc Author: Fangrui Song (MaskRay) Changesgas has supported " quoted symbols since 2015: Close #138390 Full diff: https://github.com/llvm/llvm-project/pull/138817.diff 2 Files Affected:
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index f70087e14f702..41caf20b331b2 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -212,6 +212,27 @@ MCDataFragment *MCContext::allocInitialFragment(MCSection &Sec) {
MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
SmallString<128> NameSV;
StringRef NameRef = Name.toStringRef(NameSV);
+ if (NameRef.contains('\\')) {
+ NameSV = NameRef;
+ size_t S = 0;
+ // Support escaped \\ and \" as in GNU Assembler. GAS issues a warning for
+ // other characters following \\, which we do not implement due to code
+ // structure.
+ for (size_t I = 0, E = NameSV.size(); I < E; ++I) {
+ char C = NameSV[I];
+ if (C == '\\') {
+ switch (NameSV[I + 1]) {
+ case '"':
+ case '\\':
+ C = NameSV[++I];
+ break;
+ }
+ }
+ NameSV[S++] = C;
+ }
+ NameSV.resize(S);
+ NameRef = NameSV;
+ }
assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
diff --git a/llvm/test/MC/ELF/symbol-names.s b/llvm/test/MC/ELF/symbol-names.s
index f605c723d4d4d..8c891052ebd9a 100644
--- a/llvm/test/MC/ELF/symbol-names.s
+++ b/llvm/test/MC/ELF/symbol-names.s
@@ -1,12 +1,25 @@
-// 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: 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-NEXT: callq {{.*}}
+// CHECK-NEXT: R_X86_64_PLT32 a"b\q-0x4
+.type "a\"b\\", @function
+"a\"b\\":
+ call "a\"b\\"
+/// GAS emits a warning for \q
+ call "a\"b\q"
|
brad0
approved these changes
May 7, 2025
Created using spr 1.3.5-bogner
Created using spr 1.3.5-bogner
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
May 8, 2025
gas has supported " quoted symbols since 2015: https://sourceware.org/pipermail/binutils/2015-August/090003.html We don't handle \\ or \" , leading to clang -c --save-temps vs clang -c difference for the following C code: ``` int x asm("a\"\\b"); ``` Fix #138390 MC/COFF/safeseh.h looks incorrect. \01 in `.safeseh "\01foo"` is not a correct escape sequence. Change it to \\ Pull Request: llvm/llvm-project#138817
petrhosek
pushed a commit
to petrhosek/llvm-project
that referenced
this pull request
May 8, 2025
gas has supported " quoted symbols since 2015: https://sourceware.org/pipermail/binutils/2015-August/090003.html We don't handle \\ or \" , leading to clang -c --save-temps vs clang -c difference for the following C code: ``` int x asm("a\"\\b"); ``` Fix llvm#138390 MC/COFF/safeseh.h looks incorrect. \01 in `.safeseh "\01foo"` is not a correct escape sequence. Change it to \\ Pull Request: llvm#138817
This broke the bots it seems: https://lab.llvm.org/buildbot/#/builders/153/builds/31071 |
joker-eph
added a commit
that referenced
this pull request
May 9, 2025
Reverts #138817 The BOLT testing is failing after this change.
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
May 9, 2025
Reverts llvm/llvm-project#138817 The BOLT testing is failing after this change.
MaskRay
added a commit
that referenced
this pull request
May 10, 2025
gas has supported " quoted symbols since 2015. Both \ and " need to be escaped. https://sourceware.org/pipermail/binutils/2015-August/090003.html We don't unescape \\ or \" in assembly strings, leading to clang -c --save-temps vs clang -c difference for the following C code: ``` int x asm("a\"\\b"); ``` Fix #138390 MC/COFF/safeseh.h looks incorrect. \01 in `.safeseh "\01foo"` is not a correct escape sequence. Change it to \\ Pull Request: #138817
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
May 10, 2025
gas has supported " quoted symbols since 2015. Both \ and " need to be escaped. https://sourceware.org/pipermail/binutils/2015-August/090003.html We don't unescape \\ or \" in assembly strings, leading to clang -c --save-temps vs clang -c difference for the following C code: ``` int x asm("a\"\\b"); ``` Fix #138390 MC/COFF/safeseh.h looks incorrect. \01 in `.safeseh "\01foo"` is not a correct escape sequence. Change it to \\ Pull Request: llvm/llvm-project#138817
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
gas has supported " quoted symbols since 2015:
https://sourceware.org/pipermail/binutils/2015-August/090003.html
We don't handle \ or " , leading to clang -c --save-temps vs clang -c
difference for the following C code:
Fix #138390
MC/COFF/safeseh.h looks incorrect. \01 in
.safeseh "\01foo"
is not acorrect escape sequence. Change it to \