[llvm-branch-commits] [lld] eaadb41 - [LLD][COFF] When using PCH.OBJ, ensure func_id records indices are remapped under /DEBUG:GHASH

Alexandre Ganea via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 7 14:32:00 PST 2021


Author: Alexandre Ganea
Date: 2021-01-07T17:27:13-05:00
New Revision: eaadb41db6233cf1c9e882d74a31c1f9d6e211ff

URL: https://github.com/llvm/llvm-project/commit/eaadb41db6233cf1c9e882d74a31c1f9d6e211ff
DIFF: https://github.com/llvm/llvm-project/commit/eaadb41db6233cf1c9e882d74a31c1f9d6e211ff.diff

LOG: [LLD][COFF] When using PCH.OBJ, ensure func_id records indices are remapped under /DEBUG:GHASH

Before this patch, when using LLD with /DEBUG:GHASH and MSVC precomp.OBJ files, we had a bunch of:

lld-link: warning: S_[GL]PROC32ID record in blabla.obj refers to PDB item index 0x206ED1 which is not a LF[M]FUNC_ID record

This was caused by LF_FUNC_ID and LF_MFUNC_ID which didn't have correct mapping to the corresponding TPI records. The root issue was that the indexMapStorage was improperly re-assembled in UsePrecompSource::remapTpiWithGHashes.

After this patch, /DEBUG and /DEBUG:GHASH produce exactly the same debug infos in the PDB.

Differential Revision: https://reviews.llvm.org/D93732

Added: 
    lld/test/COFF/Inputs/precomp-ghash-obj1.obj
    lld/test/COFF/Inputs/precomp-ghash-obj2.obj
    lld/test/COFF/Inputs/precomp-ghash-precomp.obj
    lld/test/COFF/precomp-ghash.test

Modified: 
    lld/COFF/DebugTypes.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp
index 0c8bfd8ae5b8..d3996eabca7d 100644
--- a/lld/COFF/DebugTypes.cpp
+++ b/lld/COFF/DebugTypes.cpp
@@ -532,7 +532,7 @@ Error UsePrecompSource::mergeInPrecompHeaderObj() {
          TypeIndex::FirstNonSimpleIndex);
   assert(precompDependency.getTypesCount() <= precompSrc->tpiMap.size());
   // Use the previously remapped index map from the precompiled headers.
-  indexMapStorage.append(precompSrc->tpiMap.begin(),
+  indexMapStorage.insert(indexMapStorage.begin(), precompSrc->tpiMap.begin(),
                          precompSrc->tpiMap.begin() +
                              precompDependency.getTypesCount());
 
@@ -842,6 +842,7 @@ void UsePrecompSource::loadGHashes() {
 }
 
 void UsePrecompSource::remapTpiWithGHashes(GHashState *g) {
+  fillMapFromGHashes(g, indexMapStorage);
   // This object was compiled with /Yu, so process the corresponding
   // precompiled headers object (/Yc) first. Some type indices in the current
   // object are referencing data in the precompiled headers object, so we need
@@ -851,7 +852,6 @@ void UsePrecompSource::remapTpiWithGHashes(GHashState *g) {
     return;
   }
 
-  fillMapFromGHashes(g, indexMapStorage);
   tpiMap = indexMapStorage;
   ipiMap = indexMapStorage;
   mergeUniqueTypeRecords(file->debugTypes,

diff  --git a/lld/test/COFF/Inputs/precomp-ghash-obj1.obj b/lld/test/COFF/Inputs/precomp-ghash-obj1.obj
new file mode 100644
index 000000000000..078593e05f66
Binary files /dev/null and b/lld/test/COFF/Inputs/precomp-ghash-obj1.obj 
diff er

diff  --git a/lld/test/COFF/Inputs/precomp-ghash-obj2.obj b/lld/test/COFF/Inputs/precomp-ghash-obj2.obj
new file mode 100644
index 000000000000..f9cff3b9dfad
Binary files /dev/null and b/lld/test/COFF/Inputs/precomp-ghash-obj2.obj 
diff er

diff  --git a/lld/test/COFF/Inputs/precomp-ghash-precomp.obj b/lld/test/COFF/Inputs/precomp-ghash-precomp.obj
new file mode 100644
index 000000000000..b28ff77f19aa
Binary files /dev/null and b/lld/test/COFF/Inputs/precomp-ghash-precomp.obj 
diff er

diff  --git a/lld/test/COFF/precomp-ghash.test b/lld/test/COFF/precomp-ghash.test
new file mode 100644
index 000000000000..e9d1984ac40d
--- /dev/null
+++ b/lld/test/COFF/precomp-ghash.test
@@ -0,0 +1,53 @@
+
+# This test ensures that under /DEBUG:GHASH, IPI records LF_FUNC_ID/LF_MFUNC_ID
+# have properly remapped indices to corresponding TPI records.
+
+RUN: lld-link %p/Inputs/precomp-ghash-precomp.obj \
+RUN:    %p/Inputs/precomp-ghash-obj1.obj\
+RUN:    %p/Inputs/precomp-ghash-obj2.obj /debug:ghash /out:%t.exe /pdb:%t.pdb
+RUN: llvm-pdbutil dump -types -ids %t.pdb | FileCheck %s
+
+; These object files were generated via the following inputs and commands:
+; ----------------------------------------------
+; // precomp-ghash-obj.h
+; namespace NS {
+;   struct Foo {
+;     explicit Foo(int x) : X(x) {}
+;     int X;
+;   };
+;
+;   int func(const Foo &f);
+; }
+; ----------------------------------------------
+; // precomp-ghash-obj1.cpp
+; #include "precomp-ghash-obj.h"
+;
+; int main(int argc, char **argv) {
+;   NS::Foo f(argc);
+;   return NS::func(f);
+; }
+; ----------------------------------------------
+; // precomp-ghash-obj2.cpp
+; #include "precomp-ghash-obj.h"
+;
+; int NS::func(const Foo &f) {
+;   return 2 * f.X;
+; }
+; ----------------------------------------------
+; // precomp-ghash-precomp.cpp
+; #include "precomp-ghash-obj.h"
+; ----------------------------------------------
+; $ cl /c /Z7 /GS- precomp-ghash-precomp.cpp /Ycprecomp-ghash-obj.h
+; $ cl /c /Z7 /GS- precomp-ghash-obj1.cpp /Yuprecomp-ghash-obj.h
+; $ cl /c /Z7 /GS- precomp-ghash-obj2.cpp /Yuprecomp-ghash-obj.h
+
+CHECK:                           Types (TPI Stream)
+CHECK-NEXT: ============================================================
+CHECK:   0x1003 | LF_MFUNCTION
+CHECK:   0x274F | LF_PROCEDURE
+CHECK:                     Types (IPI Stream)                     
+CHECK-NEXT: ============================================================
+CHECK:   0x189D | LF_FUNC_ID [size = 20]
+CHECK-NEXT:       name = main, type = 0x274F, parent scope = <no type>
+CHECK-NEXT:  0x189E | LF_MFUNC_ID [size = 20]
+CHECK-NEXT:           name = {ctor}, type = 0x1003, class type = 0x1000


        


More information about the llvm-branch-commits mailing list