<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 16px; font-family: Calibri, sans-serif;">
<div>
<div>Hi everyone,</div>
<div><br>
</div>
<div>We have found a problem while using the MCJIT engine on Windows. Our jitted code is invoking some external C++ functions. These external functions have names that are mangled using the MSVC C++ naming convention. These were not handled properly by the
ELObjectWriter.</div>
<div><br>
</div>
<div>The attached patch addresses this issue. The patch is against the LLVM release_35 branch (Revision 223459). The patch also includes a regression test. </div>
<div><br>
</div>
<div>We have successfully ran all LLVM & Clang regression tests after applying the patch on both Debug+Assert and Release builds.</div>
<div><br>
</div>
<div>Regards,</div>
<div>Benoit</div>
<div><br>
</div>
<div>------</div>
<div><br>
</div>
<div>The ELF format is used on Windows by the MCJIT engine.</div>
<div>Thus, on Windows, the ELFObjectWriter can encounter symbols mangled</div>
<div>using the MS Visual Studio C++ name mangling. Symbols mangled using the</div>
<div>MSVC C++ name mangling can legally have "@@@" as a substring. The</div>
<div>EFLObjectWriter should not interpret the "@@@" substring as specifying</div>
<div>GNU-style symbol versioning. The ELFObjectWriter therefore check for</div>
<div>the MSVC C++ name mangling prefix which is either "?", "@?", "__imp_?"</div>
<div>or "__imp_?@".</div>
<div><br>
</div>
<div>---</div>
<div> lib/MC/ELFObjectWriter.cpp | 38 +++++++++++++++++++++++------</div>
<div> test/MC/ELF/symver-msvc.s | 60 ++++++++++++++++++++++++++++++++++++++++++++++</div>
<div> 2 files changed, 91 insertions(+), 7 deletions(-)</div>
<div> create mode 100644 test/MC/ELF/symver-msvc.s</div>
<div><br>
</div>
<div>diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp</div>
<div>index 5779b27..9fddca5 100644</div>
<div>--- a/lib/MC/ELFObjectWriter.cpp</div>
<div>+++ b/lib/MC/ELFObjectWriter.cpp</div>
<div>@@ -1051,14 +1051,38 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,</div>
<div> </div>
<div> // The @@@ in symbol version is replaced with @ in undefined symbols and</div>
<div> // @@ in defined ones.</div>
<div>+ //</div>
<div>+ // We have to be careful though:</div>
<div>+ //</div>
<div>+ // The ELF format is used on Windows by the MCJIT engine. Thus, on</div>
<div>+ // Windows, the ELFObjectWriter can encounter symbols mangled using the MS</div>
<div>+ // Visual Studio C++ name mangling. Symbols mangled using the MSVC C++</div>
<div>+ // name mangling can legally have "@@@" as a sub-string. The</div>
<div>+ // EFLObjectWriter should not interpret the "@@@" sub-string as specifying</div>
<div>+ // GNU-style symbol versioning. The ELFObjectWriter therefore check for</div>
<div>+ // the MSVC C++ name mangling prefix which is either "?", "@?", "__imp_?"</div>
<div>+ // or "__imp_@?".</div>
<div>+ //</div>
<div>+ // It would have been interesting to be able to perform this ms mangling</div>
<div>+ // prefix check only when the target triple is of the form *-pc-windows-elf</div>
<div>+ // but it seems that this information is not easily accessible from the</div>
<div>+ // ELFObjectWriter.</div>
<div> StringRef Name = Symbol.getName();</div>
<div>- SmallString<32> Buf;</div>
<div>- size_t Pos = Name.find("@@@");</div>
<div>- if (Pos != StringRef::npos) {</div>
<div>- Buf += Name.substr(0, Pos);</div>
<div>- unsigned Skip = MSD.SectionIndex == ELF::SHN_UNDEF ? 2 : 1;</div>
<div>- Buf += Name.substr(Pos + Skip);</div>
<div>- Name = Buf;</div>
<div>+ if ( !Name.startswith("?") </div>
<div>+ && !Name.startswith("@?")</div>
<div>+ && !Name.startswith("__imp_?")</div>
<div>+ && !Name.startswith("__imp_@?")) {</div>
<div>+ // This symbol isn't following the MSVC C++ name mangling convention. We</div>
<div>+ // can thus safely interpret the @@@ in symbol names as specifying</div>
<div>+ // symbol versioning.</div>
<div>+ SmallString<32> Buf;</div>
<div>+ size_t Pos = Name.find("@@@");</div>
<div>+ if (Pos != StringRef::npos) {</div>
<div>+ Buf += Name.substr(0, Pos);</div>
<div>+ unsigned Skip = MSD.SectionIndex == ELF::SHN_UNDEF ? 2 : 1;</div>
<div>+ Buf += Name.substr(Pos + Skip);</div>
<div>+ Name = Buf;</div>
<div>+ }</div>
<div> }</div>
<div> MSD.Name = StrTabBuilder.add(Name);</div>
<div> </div>
<div>diff --git a/test/MC/ELF/symver-msvc.s b/test/MC/ELF/symver-msvc.s</div>
<div>new file mode 100644</div>
<div>index 0000000..4a40791</div>
<div>--- /dev/null</div>
<div>+++ b/test/MC/ELF/symver-msvc.s</div>
<div>@@ -0,0 +1,60 @@</div>
<div>+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-windows-elf %s -o - | llvm-readobj -r -t | FileCheck %s</div>
<div>+</div>
<div>+// Verify that MSVC C++ mangled symbol are not affected by the</div>
<div>+// ELF symbol versioning. The ELF format is used on Windows by the</div>
<div>+// MCJIT execution engine.</div>
<div>+</div>
<div>+</div>
<div>+ .long "??_R0?AVexception@std@@@8"</div>
<div>+ .long "@??_R0?AVinvalid_argument@std@@@8"</div>
<div>+ .long "__imp_??_R0?AVlogic_error@std@@@8"</div>
<div>+ .long "__imp_@??_R0PAVexception@std@@@8"</div>
<div>+</div>
<div>+</div>
<div>+// CHECK: Relocations [</div>
<div>+// CHECK-NEXT: Section (2) .rela.text {</div>
<div>+// CHECK-NEXT: 0x0 R_X86_64_32 ??_R0?AVexception@std@@@8 0x0</div>
<div>+// CHECK-NEXT: 0x4 R_X86_64_32 @??_R0?AVinvalid_argument@std@@@8 0x0</div>
<div>+// CHECK-NEXT: 0x8 R_X86_64_32 __imp_??_R0?AVlogic_error@std@@@8 0x0</div>
<div>+// CHECK-NEXT: 0xC R_X86_64_32 __imp_@??_R0PAVexception@std@@@8 0x0</div>
<div>+// CHECK-NEXT: }</div>
<div>+// CHECK-NEXT: ]</div>
<div>+ </div>
<div>+// CHECK: Symbols [</div>
<div>+// CHECK: Symbol {</div>
<div>+// CHECK: Name: ??_R0?AVexception@std@@@8 (102)</div>
<div>+// CHECK-NEXT: Value: 0x0</div>
<div>+// CHECK-NEXT: Size: 0</div>
<div>+// CHECK-NEXT: Binding: Global (0x1)</div>
<div>+// CHECK-NEXT: Type: None (0x0)</div>
<div>+// CHECK-NEXT: Other: 0</div>
<div>+// CHECK-NEXT: Section: Undefined (0x0)</div>
<div>+// CHECK-NEXT: }</div>
<div>+// CHECK-NEXT: Symbol {</div>
<div>+// CHECK-NEXT: Name: @??_R0?AVinvalid_argument@std@@@8 (1)</div>
<div>+// CHECK-NEXT: Value: 0x0</div>
<div>+// CHECK-NEXT: Size: 0</div>
<div>+// CHECK-NEXT: Binding: Global (0x1)</div>
<div>+// CHECK-NEXT: Type: None (0x0)</div>
<div>+// CHECK-NEXT: Other: 0</div>
<div>+// CHECK-NEXT: Section: Undefined (0x0)</div>
<div>+// CHECK-NEXT: }</div>
<div>+// CHECK-NEXT: Symbol {</div>
<div>+// CHECK-NEXT: Name: __imp_??_R0?AVlogic_error@std@@@8 (35)</div>
<div>+// CHECK-NEXT: Value: 0x0</div>
<div>+// CHECK-NEXT: Size: 0</div>
<div>+// CHECK-NEXT: Binding: Global (0x1)</div>
<div>+// CHECK-NEXT: Type: None (0x0)</div>
<div>+// CHECK-NEXT: Other: 0</div>
<div>+// CHECK-NEXT: Section: Undefined (0x0)</div>
<div>+// CHECK-NEXT: }</div>
<div>+// CHECK-NEXT: Symbol {</div>
<div>+// CHECK-NEXT: Name: __imp_@??_R0PAVexception@std@@@8 (69)</div>
<div>+// CHECK-NEXT: Value: 0x0</div>
<div>+// CHECK-NEXT: Size: 0</div>
<div>+// CHECK-NEXT: Binding: Global (0x1)</div>
<div>+// CHECK-NEXT: Type: None (0x0)</div>
<div>+// CHECK-NEXT: Other: 0</div>
<div>+// CHECK-NEXT: Section: Undefined (0x0)</div>
<div>+// CHECK-NEXT: }</div>
<div>+// CHECK-NEXT: ]</div>
<div>-- </div>
<div>1.8.4.2</div>
<div><br>
</div>
</div>
<div>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 9pt; font-family: Arial, sans-serif; color: rgb(99, 99, 99);">Benoit Belley</span></b><span style="font-size: 9pt; "><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Sr Principal Developer</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">M&E-Product Development Group</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">MAIN</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1
514 393 1616</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">DIRECT</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1
438 448 6304</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">FAX</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1
514 393 0110</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><a href="http://twitter.com/autodesk" style="color: purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Twitter</span></a><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><a href="https://www.facebook.com/Autodesk" style="color: purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Facebook</span></a><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Autodesk, Inc.</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">10 Duke Street</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Montreal, Quebec, Canada H3C 2L7</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><a href="http://www.autodesk.com/" style="color: purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">www.autodesk.com</span></a><span style="color: rgb(146, 147, 150); "><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><img border="0" width="283" height="41" id="Picture_x0020_1" src="cid:275589CA-7B39-402E-A3B7-EC24F87822B5" alt="Description: Email_Signature_Logobar" type="image/png"><o:p></o:p></p>
<div style="font-family: Calibri; font-size: medium; ">
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="font-size: 11.5pt; "> </span></p>
</div>
</div>
</body>
</html>