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

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 5 12:27:13 PST 2018


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> 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/20181205/413aaae5/attachment.html>


More information about the llvm-commits mailing list