[llvm] r321883 - [PDB] Correctly link S_FILESTATIC records.

Evgenii Stepanov via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 8 11:24:09 PST 2018


Hi,

MSan is not happy with this change:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/12211

Uninitialized bytes in __interceptor_write at offset 316 inside
[0x720000085000, 1998)
==5173==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x6cf04d in llvm::raw_fd_ostream::write_impl(char const*,
unsigned long) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/Support/raw_ostream.cpp:600:19
    #1 0x4aaa8b in flush
/b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/raw_ostream.h:142:7
    #2 0x4aaa8b in main
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/yaml2obj/yaml2obj.cpp:98
    #3 0x7f5d8f8b92b0 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
    #4 0x43cd19 in _start
(/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/yaml2obj+0x43cd19)


On Fri, Jan 5, 2018 at 11:12 AM, Zachary Turner via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: zturner
> Date: Fri Jan  5 11:12:40 2018
> New Revision: 321883
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321883&view=rev
> Log:
> [PDB] Correctly link S_FILESTATIC records.
>
> This is not a record type that clang currently generates,
> but it is a record that is encountered in object files generated
> by cl.  This record is unusual in that it refers directly to
> the string table instead of indirectly to the string table via
> the FileChecksums table.  Because of this, it was previously
> overlooked and we weren't remapping the string indices at all.
> This would lead to crashes in MSVC when trying to display a
> variable whose debug info involved an S_FILESTATIC.
>
> Original bug report by Alexander Ganea
>
> Differential Revision: https://reviews.llvm.org/D41718
>
> Modified:
>     llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp
>     llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.h
>     llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
>     llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.h
>
> Modified: llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp?rev=321883&r1=321882&r2=321883&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp (original)
> +++ llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp Fri Jan  5 11:12:40 2018
> @@ -848,14 +848,7 @@ Error DumpOutputStyle::dumpXme() {
>    return Error::success();
>  }
>
> -Error DumpOutputStyle::dumpStringTable() {
> -  printHeader(P, "String Table");
> -
> -  if (File.isObj()) {
> -    P.formatLine("Dumping string table is not supported for object files");
> -    return Error::success();
> -  }
> -
> +Error DumpOutputStyle::dumpStringTableFromPdb() {
>    AutoIndent Indent(P);
>    auto IS = getPdb().getStringTable();
>    if (!IS) {
> @@ -895,6 +888,36 @@ Error DumpOutputStyle::dumpStringTable()
>    return Error::success();
>  }
>
> +Error DumpOutputStyle::dumpStringTableFromObj() {
> +  iterateModuleSubsections<DebugStringTableSubsectionRef>(
> +      File, PrintScope{P, 4},
> +      [&](uint32_t Modi, const SymbolGroup &Strings,
> +          DebugStringTableSubsectionRef &Strings2) {
> +        BinaryStreamRef StringTableBuffer = Strings2.getBuffer();
> +        BinaryStreamReader Reader(StringTableBuffer);
> +        while (Reader.bytesRemaining() > 0) {
> +          StringRef Str;
> +          uint32_t Offset = Reader.getOffset();
> +          cantFail(Reader.readCString(Str));
> +          if (Str.empty())
> +            continue;
> +
> +          P.formatLine("{0} | {1}", fmt_align(Offset, AlignStyle::Right, 4),
> +                       Str);
> +        }
> +      });
> +  return Error::success();
> +}
> +
> +Error DumpOutputStyle::dumpStringTable() {
> +  printHeader(P, "String Table");
> +
> +  if (File.isPdb())
> +    return dumpStringTableFromPdb();
> +
> +  return dumpStringTableFromObj();
> +}
> +
>  static void buildDepSet(LazyRandomTypeCollection &Types,
>                          ArrayRef<TypeIndex> Indices,
>                          std::map<TypeIndex, CVType> &DepSet) {
> @@ -1124,6 +1147,7 @@ Error DumpOutputStyle::dumpModuleSymsFor
>        File, PrintScope{P, 2},
>        [&](uint32_t Modi, const SymbolGroup &Strings,
>            DebugSymbolsSubsectionRef &Symbols) {
> +        Dumper.setSymbolGroup(&Strings);
>          for (auto Symbol : Symbols) {
>            if (auto EC = Visitor.visitSymbolRecord(Symbol)) {
>              SymbolError = llvm::make_unique<Error>(std::move(EC));
> @@ -1165,8 +1189,8 @@ Error DumpOutputStyle::dumpModuleSymsFor
>
>          SymbolVisitorCallbackPipeline Pipeline;
>          SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb);
> -        MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, Ids,
> -                                   Types);
> +        MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, Strings,
> +                                   Ids, Types);
>
>          Pipeline.addCallbackToPipeline(Deserializer);
>          Pipeline.addCallbackToPipeline(Dumper);
>
> Modified: llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.h?rev=321883&r1=321882&r2=321883&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.h (original)
> +++ llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.h Fri Jan  5 11:12:40 2018
> @@ -75,6 +75,8 @@ private:
>    Error dumpSymbolStats();
>    Error dumpUdtStats();
>    Error dumpStringTable();
> +  Error dumpStringTableFromPdb();
> +  Error dumpStringTableFromObj();
>    Error dumpLines();
>    Error dumpInlineeLines();
>    Error dumpXmi();
>
> Modified: llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp?rev=321883&r1=321882&r2=321883&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp (original)
> +++ llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp Fri Jan  5 11:12:40 2018
> @@ -10,6 +10,7 @@
>  #include "MinimalSymbolDumper.h"
>
>  #include "FormatUtil.h"
> +#include "InputFile.h"
>  #include "LinePrinter.h"
>
>  #include "llvm/DebugInfo/CodeView/CVRecord.h"
> @@ -18,6 +19,7 @@
>  #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
>  #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
>  #include "llvm/DebugInfo/CodeView/TypeRecord.h"
> +#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
>  #include "llvm/Support/FormatVariadic.h"
>
>  using namespace llvm;
> @@ -450,6 +452,17 @@ Error MinimalSymbolDumper::visitKnownRec
>  Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FileStaticSym &FS) {
>    P.format(" `{0}`", FS.Name);
>    AutoIndent Indent(P, 7);
> +  if (SymGroup) {
> +    Expected<StringRef> FileName =
> +        SymGroup->getNameFromStringTable(FS.ModFilenameOffset);
> +    if (FileName) {
> +      P.formatLine("type = {0}, file name = {1} ({2}), flags = {3}",
> +                   typeIndex(FS.Index), FS.ModFilenameOffset, *FileName,
> +                   formatLocalSymFlags(P.getIndentLevel() + 9, FS.Flags));
> +    }
> +    return Error::success();
> +  }
> +
>    P.formatLine("type = {0}, file name offset = {1}, flags = {2}",
>                 typeIndex(FS.Index), FS.ModFilenameOffset,
>                 formatLocalSymFlags(P.getIndentLevel() + 9, FS.Flags));
>
> Modified: llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.h?rev=321883&r1=321882&r2=321883&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.h (original)
> +++ llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.h Fri Jan  5 11:12:40 2018
> @@ -19,6 +19,7 @@ class LazyRandomTypeCollection;
>
>  namespace pdb {
>  class LinePrinter;
> +class SymbolGroup;
>
>  class MinimalSymbolDumper : public codeview::SymbolVisitorCallbacks {
>  public:
> @@ -26,11 +27,19 @@ public:
>                        codeview::LazyRandomTypeCollection &Ids,
>                        codeview::LazyRandomTypeCollection &Types)
>        : P(P), RecordBytes(RecordBytes), Ids(Ids), Types(Types) {}
> +  MinimalSymbolDumper(LinePrinter &P, bool RecordBytes,
> +                      const SymbolGroup &SymGroup,
> +                      codeview::LazyRandomTypeCollection &Ids,
> +                      codeview::LazyRandomTypeCollection &Types)
> +      : P(P), RecordBytes(RecordBytes), SymGroup(&SymGroup), Ids(Ids),
> +        Types(Types) {}
>
>    Error visitSymbolBegin(codeview::CVSymbol &Record) override;
>    Error visitSymbolBegin(codeview::CVSymbol &Record, uint32_t Offset) override;
>    Error visitSymbolEnd(codeview::CVSymbol &Record) override;
>
> +  void setSymbolGroup(const SymbolGroup *Group) { SymGroup = Group; }
> +
>  #define SYMBOL_RECORD(EnumName, EnumVal, Name)                                 \
>    virtual Error visitKnownRecord(codeview::CVSymbol &CVR,                      \
>                                   codeview::Name &Record) override;
> @@ -45,6 +54,7 @@ private:
>
>    LinePrinter &P;
>    bool RecordBytes;
> +  const SymbolGroup *SymGroup = nullptr;
>    codeview::LazyRandomTypeCollection &Ids;
>    codeview::LazyRandomTypeCollection &Types;
>  };
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list