Skip to content

lldb crash for "x86_64-w64-windows-gnu" because of architecture triple mismatch - solution proposition #50775

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

Closed
llvmbot opened this issue Aug 10, 2021 · 2 comments
Labels
bugzilla Issues migrated from bugzilla crash Prefer [crash-on-valid] or [crash-on-invalid] lldb

Comments

@llvmbot
Copy link
Member

llvmbot commented Aug 10, 2021

Bugzilla Link 51433
Version 12.0
OS Windows NT
Attachments the crash backtrace
Reporter LLVM Bugzilla Contributor
CC @cristianadam,@JDevlieghere

Extended Description

The problem concerns the 64bit lldb (12.0.01 and 14.0.0) debugger compiled for "x86_64-w64-windows-gnu".
The debugger crashes if a variable of type class method pointer is examined.
Debugging of the lldb shown the problem is a result of the architecture "triple" mismatch, and a difference in the implementation of class method pointers between "msvc" and "gnu".
The triplet lldb for debugged exe file obtains the by method "ObjectFilePECOFF::GetModuleSpecifications"
and sets it to "x86_64-pc-windows". Finally the triplet is transformed to ""x86_64-pc-windows.msvc" by Triple::normalize at the clang side.

It seems to be reasonable to resolve the problem at its origin, by replacing the wrong hard coded triple value, in "ObjectFilePECOFF:: GetModuleSpecifications" to the proper one, by using some additional criteria.

Here is the patch:

diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index 9eb1c25d2403..61550682a019 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -32,6 +32,7 @@
#include "llvm/Object/COFFImportFile.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Host.h"

#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
@@ -163,7 +164,10 @@ size_t ObjectFilePECOFF::GetModuleSpecifications(

switch (COFFObj->getMachine()) {
case MachineAmd64:

  • spec.SetTriple("x86_64-pc-windows");
  •   if(llvm::sys::getProcessTriple()=="x86_64-w64-windows-gnu")
    
  •           spec.SetTriple("x86_64-w64-windows-gnu");
    
  •   else
    
  •           spec.SetTriple("x86_64-pc-windows");
    
    specs.Append(module_spec);
    break;
    case MachineX86:
@cristianadam
Copy link
Contributor

I've got a similar crash with LLVM-MinGW 13.0.0 RC1
mstorsjo/llvm-mingw#226

Crash stacktrace:

eERROR: Lldb stderr: #​0 0x00007ffab4913933 clang::CreateMicrosoftCXXABI(clang::ASTContext&) (C:\llvm-mingw\bin\libclang-cpp.dll+0x563933)
e #​1 0x00007ffab45e0e95 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (C:\llvm-mingw\bin\libclang-cpp.dll+0x230e95)
e #​2 0x00007ffab45e225b clang::ASTContext::getTypeInfo(clang::Type const*) const (C:\llvm-mingw\bin\libclang-cpp.dll+0x23225b)
e #​3 0x00007ffadae4e17a PyInit__lldb (C:\llvm-mingw\bin\liblldb.dll+0x6be17a)

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@fhahn fhahn added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Apr 11, 2022
@fhahn fhahn changed the title crash for "x86_64-w64-windows-gnu" because of architecture triple mismatch - solution proposition lldb crash for "x86_64-w64-windows-gnu" because of architecture triple mismatch - solution proposition Apr 11, 2022
@alvinhochun
Copy link
Contributor

mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
PE/COFF can use either MSVC or GNU (MinGW) ABI for C++ code, however
LLDB had defaulted to MSVC implicitly with no way to override it. This
causes issues when debugging modules built with the GNU ABI, sometimes
even crashes.

This changes the PE/COFF plugin to set the module triple according to
the default target triple used to build LLDB. If the default target
triple is Windows and a valid environment is specified, then this
environment will be used for the module spec. This not only works for
MSVC and GNU, but also other environments.

A new setting, `plugin.object-file.pe-coff.abi`,  has been added to
allow overriding this default ABI.

* Fixes llvm/llvm-project#50775
* Fixes mstorsjo/llvm-mingw#226
* Fixes mstorsjo/llvm-mingw#282

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D127048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla crash Prefer [crash-on-valid] or [crash-on-invalid] lldb
Projects
None yet
Development

No branches or pull requests

4 participants