Do not dump records not visible outside a translation unit.

Also use non-mangled name for C structs and enums as their unique id.

We do this as attempt to protect against bugs similar to those mentioned
in https://android-review.googlesource.com/c/platform/external/clang/+/599002
which might not have been discovered yet.

Bug: 71486971

Test: Build android source tree for aosp_arm64_ab with -no-filter on
      header-abi-dumper.

Test: tests/test.py

Change-Id: I3e25425d9f3015cd7dece3bd5a27f88e050c1acb
This commit is contained in:
Jayant Chowdhary
2018-01-24 15:02:18 -08:00
parent fbfa4f398a
commit d026c88b34
22 changed files with 81 additions and 35 deletions

View File

@@ -205,10 +205,13 @@ std::string RecordDeclWrapper::GetMangledRTTI(
std::string ABIWrapper::GetTypeUniqueId(const clang::TagDecl *tag_decl) {
clang::QualType qual_type =
tag_decl->getTypeForDecl()->getCanonicalTypeInternal();
llvm::SmallString<256> uid;
llvm::raw_svector_ostream out(uid);
mangle_contextp_->mangleCXXRTTIName(qual_type, out);
return uid.str();
if (!tag_decl->isExternCContext() && ast_contextp_->getLangOpts().CPlusPlus) {
llvm::SmallString<256> uid;
llvm::raw_svector_ostream out(uid);
mangle_contextp_->mangleCXXRTTIName(qual_type, out);
return uid.str();
}
return QualTypeToString(qual_type);
}
// CreateBasicNamedAndTypedDecl creates a BasicNamedAndTypedDecl : that'll

View File

@@ -51,7 +51,8 @@ bool HeaderASTVisitor::VisitRecordDecl(const clang::RecordDecl *decl) {
if (!decl->isThisDeclarationADefinition() ||
decl->getTypeForDecl()->isDependentType() ||
decl->isAnonymousStructOrUnion() ||
!decl->hasNameForLinkage()) {
!decl->hasNameForLinkage() ||
!decl->isExternallyVisible()) {
return true;
}
RecordDeclWrapper record_decl_wrapper(

View File

@@ -211,7 +211,7 @@ record_types {
is_anonymous: true
record_kind: struct_kind
tag_info {
unique_id: "_ZTSN5HelloUt1_Ut_E"
unique_id: "Hello::(anonymous)::(anonymous)"
}
}
record_types {
@@ -246,7 +246,7 @@ record_types {
is_anonymous: true
record_kind: struct_kind
tag_info {
unique_id: "_ZTSN5HelloUt1_E"
unique_id: "Hello::(anonymous)"
}
}
record_types {
@@ -298,7 +298,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS5Hello"
unique_id: "Hello"
}
}
record_types {

View File

@@ -211,7 +211,7 @@ record_types {
is_anonymous: true
record_kind: struct_kind
tag_info {
unique_id: "_ZTSN5HelloUt1_Ut_E"
unique_id: "Hello::(anonymous)::(anonymous)"
}
}
record_types {
@@ -246,7 +246,7 @@ record_types {
is_anonymous: true
record_kind: struct_kind
tag_info {
unique_id: "_ZTSN5HelloUt1_E"
unique_id: "Hello::(anonymous)"
}
}
record_types {
@@ -298,7 +298,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS5Hello"
unique_id: "Hello"
}
}
record_types {

View File

@@ -51,7 +51,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -73,7 +73,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
pointer_types {

View File

@@ -45,7 +45,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -67,7 +67,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
record_types {

View File

@@ -401,6 +401,13 @@ functions {
linker_set_key: "_ZN17HighVolumeSpeaker6ListenEv"
access: public_access
}
global_vars {
name: "HighVolumeSpeaker::global_unprotected_id"
source_file: "/development/vndk/tools/header-checker/tests/integration/cpp/gold/include/high_volume_speaker.h"
linker_set_key: "_ZN17HighVolumeSpeaker21global_unprotected_idE"
referenced_type: "type-2"
access: public_access
}
elf_functions {
name: "_Z26test_virtual_function_callP12SuperSpeaker"
}

View File

@@ -51,7 +51,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -73,7 +73,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
pointer_types {

View File

@@ -45,7 +45,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -67,7 +67,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
record_types {

View File

@@ -401,6 +401,13 @@ functions {
linker_set_key: "_ZN17HighVolumeSpeaker6ListenEv"
access: public_access
}
global_vars {
name: "HighVolumeSpeaker::global_unprotected_id"
source_file: "/development/vndk/tools/header-checker/tests/integration/cpp/gold/include/high_volume_speaker.h"
linker_set_key: "_ZN17HighVolumeSpeaker21global_unprotected_idE"
referenced_type: "type-2"
access: public_access
}
elf_functions {
name: "_Z26test_virtual_function_callP12SuperSpeaker"
}

View File

@@ -51,7 +51,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -73,7 +73,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
pointer_types {

View File

@@ -45,7 +45,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -67,7 +67,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
record_types {

View File

@@ -401,6 +401,13 @@ functions {
linker_set_key: "_ZN17HighVolumeSpeaker6ListenEv"
access: public_access
}
global_vars {
name: "HighVolumeSpeaker::global_unprotected_id"
source_file: "/development/vndk/tools/header-checker/tests/integration/cpp/gold/include/high_volume_speaker.h"
linker_set_key: "_ZN17HighVolumeSpeaker21global_unprotected_idE"
referenced_type: "type-2"
access: public_access
}
elf_functions {
name: "_Z26test_virtual_function_callP12SuperSpeaker"
}

View File

@@ -51,7 +51,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -73,7 +73,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
pointer_types {

View File

@@ -45,7 +45,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -67,7 +67,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
record_types {

View File

@@ -401,6 +401,13 @@ functions {
linker_set_key: "_ZN17HighVolumeSpeaker6ListenEv"
access: public_access
}
global_vars {
name: "HighVolumeSpeaker::global_unprotected_id"
source_file: "/development/vndk/tools/header-checker/tests/integration/cpp/gold/include/high_volume_speaker.h"
linker_set_key: "_ZN17HighVolumeSpeaker21global_unprotected_idE"
referenced_type: "type-2"
access: public_access
}
elf_functions {
name: "_Z26test_virtual_function_callP12SuperSpeaker"
}

View File

@@ -51,7 +51,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -73,7 +73,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
pointer_types {

View File

@@ -45,7 +45,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -67,7 +67,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
record_types {

View File

@@ -401,6 +401,13 @@ functions {
linker_set_key: "_ZN17HighVolumeSpeaker6ListenEv"
access: public_access
}
global_vars {
name: "HighVolumeSpeaker::global_unprotected_id"
source_file: "/development/vndk/tools/header-checker/tests/integration/cpp/gold/include/high_volume_speaker.h"
linker_set_key: "_ZN17HighVolumeSpeaker21global_unprotected_idE"
referenced_type: "type-2"
access: public_access
}
elf_functions {
name: "_Z26test_virtual_function_callP12SuperSpeaker"
}

View File

@@ -51,7 +51,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -73,7 +73,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
pointer_types {

View File

@@ -45,7 +45,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS7Cstruct"
unique_id: "Cstruct"
}
}
record_types {
@@ -67,7 +67,7 @@ record_types {
access: public_access
record_kind: struct_kind
tag_info {
unique_id: "_ZTS6Cinner"
unique_id: "Cinner"
}
}
record_types {

View File

@@ -401,6 +401,13 @@ functions {
linker_set_key: "_ZN17HighVolumeSpeaker6ListenEv"
access: public_access
}
global_vars {
name: "HighVolumeSpeaker::global_unprotected_id"
source_file: "/development/vndk/tools/header-checker/tests/integration/cpp/gold/include/high_volume_speaker.h"
linker_set_key: "_ZN17HighVolumeSpeaker21global_unprotected_idE"
referenced_type: "type-2"
access: public_access
}
elf_functions {
name: "_Z26test_virtual_function_callP12SuperSpeaker"
}