[X86][AsmParser] Fix MS inline asm label mismatch with offset operator#199552
[X86][AsmParser] Fix MS inline asm label mismatch with offset operator#199552sonyps5201314 wants to merge 2 commits into
Conversation
|
Hello @sonyps5201314 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
@llvm/pr-subscribers-backend-x86 Author: sonyps5201314 ChangesWhen using the 'offset' operator to reference an inline asm label in MSVC-style inline assembly, the label reference was missing the PrivateLabelPrefix (e.g., 'L' on COFF targets). This caused a symbol name mismatch between the label definition and its reference:
This mismatch resulted in an 'undefined symbol' linker error when using lld-link on Windows. The fix prepends PrivateLabelPrefix to the internal label name when parsing the offset operator, matching what AOK_Label does for label definitions and non-offset references. for fix #132863 Full diff: https://github.com/llvm/llvm-project/pull/199552.diff 2 Files Affected:
diff --git a/clang/test/CodeGen/ms-inline-asm.c b/clang/test/CodeGen/ms-inline-asm.c
index c3eef9a23e166..2cf3cb3ce74a2 100644
--- a/clang/test/CodeGen/ms-inline-asm.c
+++ b/clang/test/CodeGen/ms-inline-asm.c
@@ -789,6 +789,20 @@ int test_indirect_field(LARGE_INTEGER LargeInteger) {
// CHECK-LABEL: define{{.*}} i32 @test_indirect_field(
// CHECK: call i32 asm sideeffect inteldialect "mov eax, $1",
+// Test that 'offset' references to inline asm labels use the same
+// PrivateLabelPrefix as the label definition.
+void label_offset(void) {
+ __asm {
+ label_offset_target:
+ mov eax, offset label_offset_target
+ }
+ // CHECK-LABEL: define{{.*}} void @label_offset(
+ // CHECK: call void asm sideeffect inteldialect
+ // CHECK-SAME: {{.*}}__MSASMLABEL_.${:uid}__label_offset_target:
+ // CHECK-SAME: mov eax, offset {{.*}}__MSASMLABEL_.${:uid}__label_offset_target
+ // CHECK-SAME: "~{eax},~{dirflag},~{fpsr},~{flags}"()
+}
+
// MS ASM containing labels must not be duplicated (PR23715).
// CHECK: attributes [[ATTR1]] = {
// CHECK-NOT: noduplicate
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 1741efac3a8c7..942ee6bb07d28 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -2317,8 +2317,14 @@ bool X86AsmParser::ParseIntelInlineAsmIdentifier(
if (!IsParsingOffsetOperator)
InstInfo->AsmRewrites->emplace_back(AOK_Label, Loc, Identifier.size(),
InternalName);
- else
- Identifier = InternalName;
+ else {
+ // When parsing the offset operator, we need to prepend
+ // PrivateLabelPrefix to match the AOK_Label rewrite at label definition.
+ StringRef Prefix = getContext().getAsmInfo().getPrivateLabelPrefix();
+ SmallString<128> PrefixedName;
+ (Twine(Prefix) + InternalName).toVector(PrefixedName);
+ Identifier = getContext().allocateString(PrefixedName);
+ }
} else if (Info.isKind(InlineAsmIdentifierInfo::IK_EnumVal))
return false;
// Create the symbol reference.
|
When using the 'offset' operator to reference an inline asm label in MSVC-style inline assembly, the label reference was missing the PrivateLabelPrefix (e.g., 'L' on COFF targets). This caused a symbol name mismatch between the label definition and its reference: - Label definition (via AOK_Label rewrite): L__MSASMLABEL_.0__name - Offset reference (no rewrite): __MSASMLABEL_.0__name This mismatch resulted in an 'undefined symbol' linker error when using lld-link on Windows. The fix prepends PrivateLabelPrefix to the internal label name when parsing the offset operator, matching what AOK_Label does for label definitions and non-offset references. Fixes llvm#132863 Assisted by: Claude Opus 4.6
Yes, I have already read it. |
|
@lattner @topperc @RKSimon @arsenm @espindola @MaskRay @rotateright @tkremenek @nikic @kazutakahirata @ddunbar @d0k @DougGregor @fhahn @EugeneZelenko Could you review and merge the code? |
When using the 'offset' operator to reference an inline asm label in
MSVC-style inline assembly, the label reference was missing the
PrivateLabelPrefix (e.g., 'L' on COFF targets). This caused a symbol
name mismatch between the label definition and its reference:
This mismatch resulted in an 'undefined symbol' linker error when
using lld-link on Windows.
The fix prepends PrivateLabelPrefix to the internal label name when
parsing the offset operator, matching what AOK_Label does for label
definitions and non-offset references.
Fixes #132863
Assisted by: Claude Opus 4.6