[PATCH] D55336: [CodeView] Emit global variables within lexical scopes to limit visibility

Wyma, Brock via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 5 17:54:31 PST 2018


> Does this match how msvc emits S_LDATA32?
Yes, the new behavior matches how Visual Studio 2017 emits S_LDATA32 symbols.

                - Brock


From: Zachary Turner [mailto:zturner at google.com]
Sent: Wednesday, December 5, 2018 3:27 PM
To: reviews+D55336+public+f46083dda81dc3cf at reviews.llvm.org
Cc: Wyma, Brock <brock.wyma at intel.com>; rnk at google.com; llvm-commits at lists.llvm.org; john.reagan at vmssoftware.com
Subject: Re: [PATCH] D55336: [CodeView] Emit global variables within lexical scopes to limit visibility

Does this match how msvc emits S_LDATA32?
On Wed, Dec 5, 2018 at 12:15 PM Brock Wyma via Phabricator <reviews at reviews.llvm.org<mailto:reviews at reviews.llvm.org>> wrote:
bwyma created this revision.
bwyma added reviewers: rnk, zturner.

Currently, global variables with local visibility such as the following...

  void foo() {
    static int local = 1;
  }

  void bar() {
    static int local = 3;
  }

...  are emitted in CodeView as global S_LDATA32 entries outside of any routine:

  CodeViewDebugInfo [
    Section: .debug$S (5)
    Subsection [
      GlobalProcIdSym {
        Kind: S_GPROC32_ID (0x1147)
        DisplayName: foo                              # Routine foo()
      }
      ProcEnd {
        Kind: S_PROC_ID_END (0x114F)
      }
    ]
    Subsection [
      GlobalProcIdSym {
        Kind: S_GPROC32_ID (0x1147)
        DisplayName: bar                              # Routine bar()
      }
      ProcEnd {
        Kind: S_PROC_ID_END (0x114F)
      }
    ]
    Subsection [
      DataSym {
        Kind: S_LDATA32 (0x110C)
        DisplayName: local                            # "local" inside "foo"
        LinkageName: ?local@?1??foo@@YAXXZ at 4HA
      }
      DataSym {
        Kind: S_LDATA32 (0x110C)
        DisplayName: local                            # "local" inside "bar"
        LinkageName: ?local@?1??bar@@YAXXZ at 4HA
      }
    ]
  ]

When debugging routines foo() and bar(), Visual Studio 2017 will locate whichever value for "local" it finds first, which may not be the correct one, and happily display the potentially incorrect value.

This change builds upon the lexical block support added in rL327620 <https://reviews.llvm.org/rL327620> to sort global variables according to lexical scope. The result for the example above after this patch looks like this:

  CodeViewDebugInfo [
    Section: .debug$S (5)
    Subsection [
      SubSectionType: Symbols (0xF1)
      GlobalProcIdSym {
        Kind: S_GPROC32_ID (0x1147)
        DisplayName: foo                              # Routine foo()
      }
      DataSym {
        Kind: S_LDATA32 (0x110C)
        DisplayName: local                            # "local" inside "foo"
        LinkageName: ?local@?1??foo@@YAXXZ at 4HA
      }
      ProcEnd {
        Kind: S_PROC_ID_END (0x114F)
      }
    ]
    Subsection [
      SubSectionType: Symbols (0xF1)
      GlobalProcIdSym {
        Kind: S_GPROC32_ID (0x1147)
        DisplayName: bar                              # Routine bar()
      }
      DataSym {
        Kind: S_LDATA32 (0x110C)
        DisplayName: local                            # "local" inside "bar"
        LinkageName: ?local@?1??bar@@YAXXZ at 4HA
      }
      ProcEnd {
        Kind: S_PROC_ID_END (0x114F)
      }
    ]
  ]

The changes to the test type-quals.ll are index adjustments because of a minor change in the order in which the entries appear. I added the test global_visibility.ll to validate the new scoping behavior.


https://reviews.llvm.org/D55336

Files:
  lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  lib/CodeGen/AsmPrinter/CodeViewDebug.h
  test/DebugInfo/COFF/global_visibility.ll
  test/DebugInfo/COFF/type-quals.ll
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181206/113ffa1f/attachment.html>


More information about the llvm-commits mailing list