[llvm] r346154 - [COFF][LLD] Add link support for Microsoft precompiled headers OBJs
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 5 11:20:47 PST 2018
Author: aganea
Date: Mon Nov 5 11:20:47 2018
New Revision: 346154
URL: http://llvm.org/viewvc/llvm-project?rev=346154&view=rev
Log:
[COFF][LLD] Add link support for Microsoft precompiled headers OBJs
This change allows for link-time merging of debugging information from
Microsoft precompiled types OBJs compiled with cl.exe /Z7 /Yc and /Yu.
This fixes llvm.org/PR34278
Differential Revision: https://reviews.llvm.org/D45213
Modified:
llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h
llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h
llvm/trunk/include/llvm/Support/BinaryStreamArray.h
llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp
llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h?rev=346154&r1=346153&r2=346154&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h Mon Nov 5 11:20:47 2018
@@ -83,18 +83,21 @@ Error mergeIdRecords(MergingTypeTableBui
Error mergeTypeAndIdRecords(MergingTypeTableBuilder &DestIds,
MergingTypeTableBuilder &DestTypes,
SmallVectorImpl<TypeIndex> &SourceToDest,
- const CVTypeArray &IdsAndTypes);
+ const CVTypeArray &IdsAndTypes,
+ Optional<EndPrecompRecord> &EndPrecomp);
Error mergeTypeAndIdRecords(GlobalTypeTableBuilder &DestIds,
GlobalTypeTableBuilder &DestTypes,
SmallVectorImpl<TypeIndex> &SourceToDest,
const CVTypeArray &IdsAndTypes,
- ArrayRef<GloballyHashedType> Hashes);
+ ArrayRef<GloballyHashedType> Hashes,
+ Optional<EndPrecompRecord> &EndPrecomp);
Error mergeTypeRecords(GlobalTypeTableBuilder &Dest,
SmallVectorImpl<TypeIndex> &SourceToDest,
const CVTypeArray &Types,
- ArrayRef<GloballyHashedType> Hashes);
+ ArrayRef<GloballyHashedType> Hashes,
+ Optional<EndPrecompRecord> &EndPrecomp);
Error mergeIdRecords(GlobalTypeTableBuilder &Dest, ArrayRef<TypeIndex> Types,
SmallVectorImpl<TypeIndex> &SourceToDest,
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h?rev=346154&r1=346153&r2=346154&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h Mon Nov 5 11:20:47 2018
@@ -21,24 +21,23 @@ enum class pdb_error_code {
dia_sdk_not_present,
dia_failed_loading,
signature_out_of_date,
- type_server_not_found,
unspecified,
};
-} // namespace codeview
+} // namespace pdb
} // namespace llvm
namespace std {
- template <>
- struct is_error_code_enum<llvm::pdb::pdb_error_code> : std::true_type {};
+template <>
+struct is_error_code_enum<llvm::pdb::pdb_error_code> : std::true_type {};
} // namespace std
namespace llvm {
namespace pdb {
- const std::error_category &PDBErrCategory();
+const std::error_category &PDBErrCategory();
- inline std::error_code make_error_code(pdb_error_code E) {
- return std::error_code(static_cast<int>(E), PDBErrCategory());
- }
+inline std::error_code make_error_code(pdb_error_code E) {
+ return std::error_code(static_cast<int>(E), PDBErrCategory());
+}
/// Base class for errors originating when parsing raw PDB files
class PDBError : public ErrorInfo<PDBError, StringError> {
Modified: llvm/trunk/include/llvm/Support/BinaryStreamArray.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/BinaryStreamArray.h?rev=346154&r1=346153&r2=346154&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/BinaryStreamArray.h (original)
+++ llvm/trunk/include/llvm/Support/BinaryStreamArray.h Mon Nov 5 11:20:47 2018
@@ -125,6 +125,8 @@ public:
BinaryStreamRef getUnderlyingStream() const { return Stream; }
void setUnderlyingStream(BinaryStreamRef S) { Stream = S; }
+ void drop_front() { Stream = Stream.drop_front(begin()->length()); }
+
private:
BinaryStreamRef Stream;
Extractor E;
Modified: llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp?rev=346154&r1=346153&r2=346154&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp Mon Nov 5 11:20:47 2018
@@ -41,6 +41,8 @@ public:
};
static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory;
-const std::error_category &llvm::codeview::CVErrorCategory() { return *CodeViewErrCategory; }
+const std::error_category &llvm::codeview::CVErrorCategory() {
+ return *CodeViewErrCategory;
+}
char CodeViewError::ID;
Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp?rev=346154&r1=346153&r2=346154&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp Mon Nov 5 11:20:47 2018
@@ -12,6 +12,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h"
#include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
+#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
@@ -63,7 +64,12 @@ class TypeStreamMerger {
public:
explicit TypeStreamMerger(SmallVectorImpl<TypeIndex> &SourceToDest)
: IndexMap(SourceToDest) {
- SourceToDest.clear();
+ // When dealing with precompiled headers objects, all data in SourceToDest
+ // belongs to the precompiled headers object, and is assumed to be already
+ // remapped to the target PDB. Any forthcoming type that will be merged in
+ // might potentially back-reference this data. We also don't want to resolve
+ // twice the types in the precompiled object.
+ CurIndex += SourceToDest.size();
}
static const TypeIndex Untranslated;
@@ -71,7 +77,8 @@ public:
// Local hashing entry points
Error mergeTypesAndIds(MergingTypeTableBuilder &DestIds,
MergingTypeTableBuilder &DestTypes,
- const CVTypeArray &IdsAndTypes);
+ const CVTypeArray &IdsAndTypes,
+ Optional<EndPrecompRecord> &EP);
Error mergeIdRecords(MergingTypeTableBuilder &Dest,
ArrayRef<TypeIndex> TypeSourceToDest,
const CVTypeArray &Ids);
@@ -82,13 +89,15 @@ public:
Error mergeTypesAndIds(GlobalTypeTableBuilder &DestIds,
GlobalTypeTableBuilder &DestTypes,
const CVTypeArray &IdsAndTypes,
- ArrayRef<GloballyHashedType> Hashes);
+ ArrayRef<GloballyHashedType> Hashes,
+ Optional<EndPrecompRecord> &EP);
Error mergeIdRecords(GlobalTypeTableBuilder &Dest,
ArrayRef<TypeIndex> TypeSourceToDest,
const CVTypeArray &Ids,
ArrayRef<GloballyHashedType> Hashes);
Error mergeTypeRecords(GlobalTypeTableBuilder &Dest, const CVTypeArray &Types,
- ArrayRef<GloballyHashedType> Hashes);
+ ArrayRef<GloballyHashedType> Hashes,
+ Optional<EndPrecompRecord> &EP);
private:
Error doit(const CVTypeArray &Types);
@@ -156,6 +165,8 @@ private:
return llvm::make_error<CodeViewError>(cv_error_code::corrupt_record);
}
+ Expected<bool> shouldRemapType(const CVType &Type);
+
Optional<Error> LastError;
bool UseGlobalHashes = false;
@@ -185,6 +196,8 @@ private:
/// Temporary storage that we use to copy a record's data while re-writing
/// its type indices.
SmallVector<uint8_t, 256> RemapStorage;
+
+ Optional<EndPrecompRecord> EndPrecomp;
};
} // end anonymous namespace
@@ -261,22 +274,27 @@ Error TypeStreamMerger::mergeIdRecords(M
Error TypeStreamMerger::mergeTypesAndIds(MergingTypeTableBuilder &DestIds,
MergingTypeTableBuilder &DestTypes,
- const CVTypeArray &IdsAndTypes) {
+ const CVTypeArray &IdsAndTypes,
+ Optional<EndPrecompRecord> &EP) {
DestIdStream = &DestIds;
DestTypeStream = &DestTypes;
UseGlobalHashes = false;
- return doit(IdsAndTypes);
+ auto Err = doit(IdsAndTypes);
+ EP = EndPrecomp;
+ return Err;
}
// Global hashing entry points
Error TypeStreamMerger::mergeTypeRecords(GlobalTypeTableBuilder &Dest,
const CVTypeArray &Types,
- ArrayRef<GloballyHashedType> Hashes) {
+ ArrayRef<GloballyHashedType> Hashes,
+ Optional<EndPrecompRecord> &EP) {
DestGlobalTypeStream = &Dest;
UseGlobalHashes = true;
GlobalHashes = Hashes;
-
- return doit(Types);
+ auto Err = doit(Types);
+ EP = EndPrecomp;
+ return Err;
}
Error TypeStreamMerger::mergeIdRecords(GlobalTypeTableBuilder &Dest,
@@ -294,12 +312,15 @@ Error TypeStreamMerger::mergeIdRecords(G
Error TypeStreamMerger::mergeTypesAndIds(GlobalTypeTableBuilder &DestIds,
GlobalTypeTableBuilder &DestTypes,
const CVTypeArray &IdsAndTypes,
- ArrayRef<GloballyHashedType> Hashes) {
+ ArrayRef<GloballyHashedType> Hashes,
+ Optional<EndPrecompRecord> &EP) {
DestGlobalIdStream = &DestIds;
DestGlobalTypeStream = &DestTypes;
UseGlobalHashes = true;
GlobalHashes = Hashes;
- return doit(IdsAndTypes);
+ auto Err = doit(IdsAndTypes);
+ EP = EndPrecomp;
+ return Err;
}
Error TypeStreamMerger::doit(const CVTypeArray &Types) {
@@ -345,25 +366,30 @@ Error TypeStreamMerger::remapAllTypes(co
}
Error TypeStreamMerger::remapType(const CVType &Type) {
- auto DoSerialize =
- [this, Type](MutableArrayRef<uint8_t> Storage) -> ArrayRef<uint8_t> {
- return remapIndices(Type, Storage);
- };
+ auto R = shouldRemapType(Type);
+ if (!R)
+ return R.takeError();
TypeIndex DestIdx = Untranslated;
- if (LLVM_LIKELY(UseGlobalHashes)) {
- GlobalTypeTableBuilder &Dest =
- isIdRecord(Type.kind()) ? *DestGlobalIdStream : *DestGlobalTypeStream;
- GloballyHashedType H = GlobalHashes[CurIndex.toArrayIndex()];
- DestIdx = Dest.insertRecordAs(H, Type.RecordData.size(), DoSerialize);
- } else {
- MergingTypeTableBuilder &Dest =
- isIdRecord(Type.kind()) ? *DestIdStream : *DestTypeStream;
-
- RemapStorage.resize(Type.RecordData.size());
- ArrayRef<uint8_t> Result = DoSerialize(RemapStorage);
- if (!Result.empty())
- DestIdx = Dest.insertRecordBytes(Result);
+ if (*R) {
+ auto DoSerialize =
+ [this, Type](MutableArrayRef<uint8_t> Storage) -> ArrayRef<uint8_t> {
+ return remapIndices(Type, Storage);
+ };
+ if (LLVM_LIKELY(UseGlobalHashes)) {
+ GlobalTypeTableBuilder &Dest =
+ isIdRecord(Type.kind()) ? *DestGlobalIdStream : *DestGlobalTypeStream;
+ GloballyHashedType H = GlobalHashes[CurIndex.toArrayIndex()];
+ DestIdx = Dest.insertRecordAs(H, Type.RecordData.size(), DoSerialize);
+ } else {
+ MergingTypeTableBuilder &Dest =
+ isIdRecord(Type.kind()) ? *DestIdStream : *DestTypeStream;
+
+ RemapStorage.resize(Type.RecordData.size());
+ ArrayRef<uint8_t> Result = DoSerialize(RemapStorage);
+ if (!Result.empty())
+ DestIdx = Dest.insertRecordBytes(Result);
+ }
}
addMapping(DestIdx);
@@ -418,25 +444,29 @@ Error llvm::codeview::mergeIdRecords(Mer
Error llvm::codeview::mergeTypeAndIdRecords(
MergingTypeTableBuilder &DestIds, MergingTypeTableBuilder &DestTypes,
- SmallVectorImpl<TypeIndex> &SourceToDest, const CVTypeArray &IdsAndTypes) {
+ SmallVectorImpl<TypeIndex> &SourceToDest, const CVTypeArray &IdsAndTypes,
+ Optional<EndPrecompRecord> &EndPrecomp) {
TypeStreamMerger M(SourceToDest);
- return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes);
+ return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, EndPrecomp);
}
Error llvm::codeview::mergeTypeAndIdRecords(
GlobalTypeTableBuilder &DestIds, GlobalTypeTableBuilder &DestTypes,
SmallVectorImpl<TypeIndex> &SourceToDest, const CVTypeArray &IdsAndTypes,
- ArrayRef<GloballyHashedType> Hashes) {
+ ArrayRef<GloballyHashedType> Hashes,
+ Optional<EndPrecompRecord> &EndPrecomp) {
TypeStreamMerger M(SourceToDest);
- return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, Hashes);
+ return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, Hashes,
+ EndPrecomp);
}
Error llvm::codeview::mergeTypeRecords(GlobalTypeTableBuilder &Dest,
SmallVectorImpl<TypeIndex> &SourceToDest,
const CVTypeArray &Types,
- ArrayRef<GloballyHashedType> Hashes) {
+ ArrayRef<GloballyHashedType> Hashes,
+ Optional<EndPrecompRecord> &EndPrecomp) {
TypeStreamMerger M(SourceToDest);
- return M.mergeTypeRecords(Dest, Types, Hashes);
+ return M.mergeTypeRecords(Dest, Types, Hashes, EndPrecomp);
}
Error llvm::codeview::mergeIdRecords(GlobalTypeTableBuilder &Dest,
@@ -447,3 +477,18 @@ Error llvm::codeview::mergeIdRecords(Glo
TypeStreamMerger M(SourceToDest);
return M.mergeIdRecords(Dest, Types, Ids, Hashes);
}
+
+Expected<bool> TypeStreamMerger::shouldRemapType(const CVType &Type) {
+ // For object files containing precompiled types, we need to extract the
+ // signature, through EndPrecompRecord. This is done here for performance
+ // reasons, to avoid re-parsing the Types stream.
+ if (Type.kind() == LF_ENDPRECOMP) {
+ assert(!EndPrecomp);
+ EndPrecomp.emplace();
+ if (auto EC = TypeDeserializer::deserializeAs(const_cast<CVType &>(Type),
+ EndPrecomp.getValue()))
+ return joinErrors(std::move(EC), errorCorruptRecord());
+ return false;
+ }
+ return true;
+}
Modified: llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp?rev=346154&r1=346153&r2=346154&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp Mon Nov 5 11:20:47 2018
@@ -24,8 +24,6 @@ public:
switch (static_cast<pdb_error_code>(Condition)) {
case pdb_error_code::unspecified:
return "An unknown error has occurred.";
- case pdb_error_code::type_server_not_found:
- return "Type server PDB was not found.";
case pdb_error_code::dia_sdk_not_present:
return "LLVM was not compiled with support for DIA. This usually means "
"that you are not using MSVC, or your Visual Studio "
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=346154&r1=346153&r2=346154&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Mon Nov 5 11:20:47 2018
@@ -1248,7 +1248,9 @@ void COFFDumper::mergeCodeViewTypes(Merg
error(object_error::parse_failed);
}
SmallVector<TypeIndex, 128> SourceToDest;
- if (auto EC = mergeTypeAndIdRecords(CVIDs, CVTypes, SourceToDest, Types))
+ Optional<EndPrecompRecord> EndPrecomp;
+ if (auto EC = mergeTypeAndIdRecords(CVIDs, CVTypes, SourceToDest, Types,
+ EndPrecomp))
return error(std::move(EC));
}
}
More information about the llvm-commits
mailing list