microsoft / microsoft/SizeBench

Enum / class in different unnamed namespaces cause Error opening binary

Open
#16 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
175
Forks
20
PR merge metrics
No merged PRs in 30d

Description

I have found a bug in Sizebench (the version downloaded from the Microsoft AppStore, I did not try to compile a version from source). The bug happens when compiling an executable or dll with VC2017, when in one translation unit an unnamed namespace exists with a virtual class, and in another translation unit an unnamed namespace with an enum with the same name. The following is a minimal example. If you rename NameClash in either file to something different, the problem no longer occurs.

-------- virtualstruct.cpp --------

namespace
{
    struct NameClash
    {
        virtual ~NameClash() = default;
    };
    NameClash instance;
}

-------- main.cpp --------

namespace
{
    enum NameClash { FOO };
}

int main(int argc, char ** argv)
{
    NameClash t = NameClash(argc);
    if (t == FOO)
        return 1;
    else
        return 0;
}

When you compile this with Visual Studio 2017, and open the resulting executable with Sizebench, you get a dialog with an error message "Error opening binary! - There was an error opening this binary or PDB", following by a link to some log, and a call stack.

I have found out that this problem does not occur when compiling the same files with Visual Studio 2022.

I'll try to attach a screenshot, the content of the log file, and a zip file with the project file, which can be used with Visual Studio 2017 to compile and reproduce the bug.

sizebencherror

tmpAD61.tmp.sizebenchlog.txt

sizebenchbug.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the attached sizebenchbug.zip, with virtualstruct.cpp and main.cpp compiled by Visual Studio 2017, then open the resulting binary in SizeBench and review the linked log. Compare the behavior with the same example built by Visual Studio 2022; done means the affected binary opens without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.