diff options
author | Tomohiro Kashiwada <kikairoya@gmail.com> | 2025-09-23 17:10:20 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-23 11:10:20 +0300 |
commit | 2b90eb8abbbde4ed83a32b6930c450e03f84e03c (patch) | |
tree | 49215fadb16831c848d9d61fd8fe40db97e8fb48 /clang/lib/CodeGen/CGDebugInfo.cpp | |
parent | d9515751f5766109f0f13d5643952313efe53424 (diff) | |
download | llvm-2b90eb8abbbde4ed83a32b6930c450e03f84e03c.zip llvm-2b90eb8abbbde4ed83a32b6930c450e03f84e03c.tar.gz llvm-2b90eb8abbbde4ed83a32b6930c450e03f84e03c.tar.bz2 |
[clang][DebugInfo] Re-enable VTable debug info on COFF platforms (#158450)
The debug info for VTables introduced in #130255 was temporarily
disabled on COFF platforms by #151684, due to the risk of emitting
dangling relocations (see also:
https://github.com/llvm/llvm-project/issues/149639#issuecomment-3114257062
).
This patch re-enables that debug info and adds a guard to prevent
emitting dangling relocations by checking whether the VTable definition
is actually emitted.
Resolves #149639
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 578d09f..12c7d48 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2657,12 +2657,22 @@ StringRef CGDebugInfo::getVTableName(const CXXRecordDecl *RD) { // existing information in the DWARF. The type is assumed to be 'void *'. void CGDebugInfo::emitVTableSymbol(llvm::GlobalVariable *VTable, const CXXRecordDecl *RD) { - if (!CGM.getTarget().getCXXABI().isItaniumFamily() || - CGM.getTarget().getTriple().isOSBinFormatCOFF()) + if (!CGM.getTarget().getCXXABI().isItaniumFamily()) return; if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly) return; + // On COFF platform, we shouldn't emit a reference to an external entity (i.e. + // VTable) into debug info, which is constructed within a discardable section. + // If that entity ends up implicitly dllimported from another DLL, the linker + // may produce a runtime pseudo-relocation for it (BFD-ld only. LLD prohibits + // to emit such relocation). If the debug section is stripped, the runtime + // pseudo-relocation points to memory space outside of the module, causing an + // access violation. + if (CGM.getTarget().getTriple().isOSBinFormatCOFF() && + VTable->isDeclarationForLinker()) + return; + ASTContext &Context = CGM.getContext(); StringRef SymbolName = "_vtable$"; SourceLocation Loc; |