Skip to content

Commit 80dae15

Browse files
authored
[clang][DebugInfo] Disable VTable debug info (#130255) on COFF platforms (#151684)
On COFF platform, d1b0cbf generates a debug info linked with VTable regardless definition is present or not. If that VTable ends up implicitly dllimported from another DLL, ld.bfd produces a runtime pseudo relocation for it (LLD doesn't, since d17db60). If the debug section is stripped, the runtime pseudo relocation points to memory space outside of the module, causing an access violation. At this moment, we simply disable VTable debug info on COFF platform to avoid this problem.
1 parent 1406058 commit 80dae15

File tree

4 files changed

+49
-26
lines changed

4 files changed

+49
-26
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,8 @@ StringRef CGDebugInfo::getVTableName(const CXXRecordDecl *RD) {
26302630
// existing information in the DWARF. The type is assumed to be 'void *'.
26312631
void CGDebugInfo::emitVTableSymbol(llvm::GlobalVariable *VTable,
26322632
const CXXRecordDecl *RD) {
2633-
if (!CGM.getTarget().getCXXABI().isItaniumFamily())
2633+
if (!CGM.getTarget().getCXXABI().isItaniumFamily() ||
2634+
CGM.getTarget().getTriple().isOSBinFormatCOFF())
26342635
return;
26352636
if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
26362637
return;

clang/test/CodeGenCXX/debug-info-class.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ int main(int argc, char **argv) {
9999
return 0;
100100
}
101101

102-
// RUN: %clang_cc1 -triple x86_64-unknown_unknown -emit-llvm -debug-info-kind=limited -fexceptions -std=c++98 %s -o - | FileCheck -check-prefix=CHECK98 -check-prefix=CHECK %s
103-
// RUN: %clang_cc1 -triple i686-cygwin -emit-llvm -debug-info-kind=limited -fexceptions -std=c++98 %s -o - | FileCheck -check-prefix=CHECK98 -check-prefix=CHECK %s
104-
// RUN: %clang_cc1 -triple armv7l-unknown-linux-gnueabihf -emit-llvm -debug-info-kind=limited -fexceptions -std=c++98 %s -o - | FileCheck -check-prefix=CHECK98 -check-prefix=CHECK %s
105-
// RUN: %clang_cc1 -triple x86_64-unknown_unknown -emit-llvm -debug-info-kind=limited -fexceptions -std=c++11 %s -o - | FileCheck -check-prefix=CHECK11 -check-prefix=CHECK %s
106-
// RUN: %clang_cc1 -triple i686-cygwin -emit-llvm -debug-info-kind=limited -fexceptions -std=c++11 %s -o - | FileCheck -check-prefix=CHECK11 -check-prefix=CHECK %s
107-
// RUN: %clang_cc1 -triple armv7l-unknown-linux-gnueabihf -emit-llvm -debug-info-kind=limited -fexceptions -std=c++11 %s -o - | FileCheck -check-prefix=CHECK11 -check-prefix=CHECK %s
102+
// RUN: %clang_cc1 -triple x86_64-unknown_unknown -emit-llvm -debug-info-kind=limited -fexceptions -std=c++98 %s -o - | FileCheck -check-prefix=CHECK98 -check-prefix=CHECK -check-prefix=CHECKELF %s
103+
// RUN: %clang_cc1 -triple i686-cygwin -emit-llvm -debug-info-kind=limited -fexceptions -std=c++98 %s -o - | FileCheck -check-prefix=CHECK98 -check-prefix=CHECK -check-prefix=CHECKCOFF %s
104+
// RUN: %clang_cc1 -triple armv7l-unknown-linux-gnueabihf -emit-llvm -debug-info-kind=limited -fexceptions -std=c++98 %s -o - | FileCheck -check-prefix=CHECK98 -check-prefix=CHECK -check-prefix=CHECKELF %s
105+
// RUN: %clang_cc1 -triple x86_64-unknown_unknown -emit-llvm -debug-info-kind=limited -fexceptions -std=c++11 %s -o - | FileCheck -check-prefix=CHECK11 -check-prefix=CHECK -check-prefix=CHECKELF %s
106+
// RUN: %clang_cc1 -triple i686-cygwin -emit-llvm -debug-info-kind=limited -fexceptions -std=c++11 %s -o - | FileCheck -check-prefix=CHECK11 -check-prefix=CHECK -check-prefix=CHECKCOFF %s
107+
// RUN: %clang_cc1 -triple armv7l-unknown-linux-gnueabihf -emit-llvm -debug-info-kind=limited -fexceptions -std=c++11 %s -o - | FileCheck -check-prefix=CHECK11 -check-prefix=CHECK -check-prefix=CHECKELF %s
108108

109109
// CHECK98: invoke {{.+}} @_ZN1BD1Ev(ptr {{[^,]*}} %b)
110110
// CHECK98-NEXT: unwind label %{{.+}}, !dbg ![[EXCEPTLOC:.*]]
@@ -122,6 +122,14 @@ int main(int argc, char **argv) {
122122
// CHECK-SAME: ){{$}}
123123

124124
// CHECK: ![[INT:[0-9]+]] = !DIBasicType(name: "int"
125+
// CHECKCOFF: !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
126+
// CHECKCOFF: !DICompositeType(tag: DW_TAG_class_type, name: "bar"
127+
// CHECKCOFF: !DICompositeType(tag: DW_TAG_union_type, name: "baz"
128+
// CHECKCOFF: !DICompositeType(tag: DW_TAG_class_type, name: "B"
129+
// CHECKCOFF-NOT: DIFlagFwdDecl
130+
// CHECKCOFF-SAME: ){{$}}
131+
// CHECKCOFF: !DIDerivedType(tag: DW_TAG_member, name: "_vptr$B",
132+
// CHECKCOFF-SAME: DIFlagArtificial
125133

126134
// CHECK: [[C:![0-9]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C",
127135
// CHECK-NOT: DIFlagFwdDecl
@@ -137,19 +145,19 @@ int main(int argc, char **argv) {
137145
// CHECK-SAME: DIFlagStaticMember
138146
// CHECK: [[C_DTOR]] = !DISubprogram(name: "~C"
139147

140-
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "K"
141-
// CHECK-SAME: identifier: "_ZTS1K"
142-
// CHECK-SAME: ){{$}}
148+
// CHECKELF: !DICompositeType(tag: DW_TAG_structure_type, name: "K"
149+
// CHECKELF-SAME: identifier: "_ZTS1K"
150+
// CHECKELF-SAME: ){{$}}
143151

144-
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "B"
145-
// CHECK-NOT: DIFlagFwdDecl
146-
// CHECK-SAME: ){{$}}
147-
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "_vptr$B",
148-
// CHECK-SAME: DIFlagArtificial
152+
// CHECKELF: !DICompositeType(tag: DW_TAG_class_type, name: "B"
153+
// CHECKELF-NOT: DIFlagFwdDecl
154+
// CHECKELF-SAME: ){{$}}
155+
// CHECKELF: !DIDerivedType(tag: DW_TAG_member, name: "_vptr$B",
156+
// CHECKELF-SAME: DIFlagArtificial
149157

150-
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
151-
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "bar"
152-
// CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "baz"
158+
// CHECKELF: !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
159+
// CHECKELF: !DICompositeType(tag: DW_TAG_class_type, name: "bar"
160+
// CHECKELF: !DICompositeType(tag: DW_TAG_union_type, name: "baz"
153161

154162
// CHECK: [[D:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "D"
155163
// CHECK-SAME: size:
@@ -162,6 +170,10 @@ int main(int argc, char **argv) {
162170
// CHECK-NOT: identifier:
163171
// CHECK-SAME: ){{$}}
164172

173+
// CHECKCOFF: !DICompositeType(tag: DW_TAG_structure_type, name: "K"
174+
// CHECKCOFF-SAME: identifier: "_ZTS1K"
175+
// CHECKCOFF-SAME: ){{$}}
176+
165177
// CHECK: [[L:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "L"
166178
// CHECK-SAME: ){{$}}
167179
// CHECK: [[L_FUNC_DECL:![0-9]*]] = !DISubprogram(name: "func",{{.*}} scope: [[L]]

clang/test/CodeGenCXX/vtable-debug-info-inheritance-simple.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: target={{x86_64.*-linux.*}}
2-
31
// Simple inheritance case:
42
// For CBase and CDerived we check:
53
// - Generation of their vtables (including attributes).
@@ -30,13 +28,20 @@ int main() {
3028
return 0;
3129
}
3230

33-
// RUN: %clang --target=x86_64-linux -Xclang -disable-O0-optnone -Xclang -disable-llvm-passes -emit-llvm -S -g %s -o - | FileCheck %s
31+
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -mrelocation-model pic -pic-is-pie -debug-info-kind=limited -dwarf-version=5 -disable-O0-optnone -disable-llvm-passes %s -o - | FileCheck %s
32+
// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -mrelocation-model pic -pic-is-pie -debug-info-kind=limited -dwarf-version=5 -disable-O0-optnone -disable-llvm-passes %s -o - | FileCheck %s --check-prefix=COFF
3433

3534
// CHECK: $_ZTVN3NSP5CBaseE = comdat any
3635
// CHECK: $_ZTV8CDerived = comdat any
3736

3837
// CHECK: @_ZTVN3NSP5CBaseE = linkonce_odr {{dso_local|hidden}} unnamed_addr constant {{.*}}, comdat, align 8, !dbg [[BASE_VTABLE_VAR:![0-9]*]]
3938
// CHECK: @_ZTV8CDerived = linkonce_odr {{dso_local|hidden}} unnamed_addr constant {{.*}}, comdat, align 8, !dbg [[DERIVED_VTABLE_VAR:![0-9]*]]
39+
// COFF: @_ZTVN3NSP5CBaseE = linkonce_odr {{dso_local|hidden}} unnamed_addr constant {{.*}}, comdat, align 8
40+
// COFF-NOT: !dbg
41+
// COFF-SAME: {{$}}
42+
// COFF: @_ZTV8CDerived = linkonce_odr {{dso_local|hidden}} unnamed_addr constant {{.*}}, comdat, align 8
43+
// COFF-NOT: !dbg
44+
// COFF-SAME: {{$}}
4045

4146
// CHECK: [[BASE_VTABLE_VAR]] = !DIGlobalVariableExpression(var: [[BASE_VTABLE:![0-9]*]], expr: !DIExpression())
4247
// CHECK-NEXT: [[BASE_VTABLE]] = distinct !DIGlobalVariable(name: "_vtable$", linkageName: "_ZTVN3NSP5CBaseE"

clang/test/Modules/ExtDebugInfo.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// RUN: -fmodule-format=obj -fimplicit-module-maps -DMODULES \
99
// RUN: -triple %itanium_abi_triple \
1010
// RUN: -fmodules-cache-path=%t %s -I %S/Inputs -I %t -emit-llvm -o %t-mod.ll
11-
// RUN: cat %t-mod.ll | FileCheck %s
11+
// RUN: cat %t-mod.ll | FileCheck %s --check-prefix=CHECK %if target={{.*-(win|mingw|cyg).*}} %{--check-prefix=CHECKCOFF%} %else %{--check-prefix=CHECKELF%}
1212

1313
// PCH:
1414
// RUN: %clang_cc1 -x c++ -std=c++11 -fmodule-format=obj -emit-pch -I%S/Inputs \
@@ -18,7 +18,7 @@
1818
// RUN: -dwarf-ext-refs -fmodule-format=obj \
1919
// RUN: -triple %itanium_abi_triple \
2020
// RUN: -include-pch %t.pch %s -emit-llvm -o %t-pch.ll
21-
// RUN: cat %t-pch.ll | FileCheck %s
21+
// RUN: cat %t-pch.ll | FileCheck %s --check-prefix=CHECK %if target={{.*-(win|mingw|cyg).*}} %{--check-prefix=CHECKCOFF%} %else %{--check-prefix=CHECKELF%}
2222
// RUN: cat %t-pch.ll | FileCheck %s --check-prefix=CHECK-PCH
2323

2424
#ifdef MODULES
@@ -208,9 +208,9 @@ void foo() {
208208
// CHECK-SAME: name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)
209209

210210
// There is a full definition of the type available in the module.
211-
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
212-
// CHECK-SAME: DIFlagFwdDecl
213-
// CHECK-SAME: identifier: "_ZTS7Virtual")
211+
// CHECKELF: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
212+
// CHECKELF-SAME: DIFlagFwdDecl
213+
// CHECKELF-SAME: identifier: "_ZTS7Virtual")
214214

215215
// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !{{[0-9]+}}, entity: ![[STRUCT]], file: ![[CPP]], line: 50)
216216

@@ -222,3 +222,8 @@ void foo() {
222222

223223
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A",
224224
// CHECK-SAME: DIFlagFwdDecl
225+
226+
// There is a full definition of the type available in the module.
227+
// CHECKCOFF: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
228+
// CHECKCOFF-SAME: DIFlagFwdDecl
229+
// CHECKCOFF-SAME: identifier: "_ZTS7Virtual")

0 commit comments

Comments
 (0)