This is an archive of the discontinued LLVM Phabricator instance.

[clang][OpenMP][DebugInfo] Debug support for TLS variables when present in OpenMP consructs
ClosedPublic

Authored by alok on Apr 14 2022, 5:45 AM.

Details

Summary

In case of OpenMP programs, thread local variables can be present in any clause pertaining to
OpenMP constructs, as we know that compiler generates artificial functions and in some cases
values are passed to those artificial functions thru parameters.
For an example, if thread local variable is present in copyin clause (testcase attached with the
patch), parameter with same name is generated as parameter to artificial function. When user
inquires the thread Local variable, its debug info is hidden by the parameter. The debug info
for parameters (for thread local) must be suppressed.

Without the patch, attached testcase behaves wrongly under debuggers.

Thread 3 "a.out" hit Breakpoint 3, .omp_outlined._debug__ (.global_tid.=0x155547ffde20, .bound_tid.=0x155547ffde18, nt=@0x7fffffffe2b8: 4, gbl_int=@0x15555553333c: 65)
    at simple.c:29
29                  printf ("In parallel region total threads = %d, thread id = %d data=%d gbl_addr = %p\n", nt, tid, data, &gbl_int);
(gdb) p tid
$1 = 2
(gdb) p &gbl_int
$2 = (int *) 0x15555553333c
(gdb) c
Continuing.
[Switching to Thread 0x155553ad2b80 (LWP 12279)]

Thread 2 "a.out" hit Breakpoint 2, .omp_outlined._debug__ (.global_tid.=0x155553ad1de0, .bound_tid.=0x155553ad1dd8, nt=@0x7fffffffe2b8: 4, gbl_int=@0x15555553333c: 65)
    at simple.c:27
27                  printf ("In parallel region total threads = %d, thread id = %d data=%d gbl_addr = %p\n", nt, tid, data, &gbl_int);
(gdb) p tid
$3 = 1
(gdb) p &gbl_int
$4 = (int *) 0x15555553333c

Please note that same address is shown for all the threads which is wrong (for thread local variable).

With the current patch, the issue is fixed.

Diff Detail

Event Timeline

alok created this revision.Apr 14 2022, 5:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2022, 5:45 AM
alok requested review of this revision.Apr 14 2022, 5:45 AM
Herald added a project: Restricted Project. · View Herald Transcript

For an example, if thread local variable is present in copyin clause (testcase attached with the

patch), parameter with same name is generated as parameter to artificial function. When user
inquires the thread Local variable, its debug info is hidden by the parameter. The debug info
for parameters (for thread local) must be suppressed.

What does the dwarfdump output for the old behavior look like? Are the two in the same scope?

alok added a comment.Apr 18 2022, 3:05 AM

For an example, if thread local variable is present in copyin clause (testcase attached with the

patch), parameter with same name is generated as parameter to artificial function. When user
inquires the thread Local variable, its debug info is hidden by the parameter. The debug info
for parameters (for thread local) must be suppressed.

What does the dwarfdump output for the old behavior look like? Are the two in the same scope?

The dwarfdump output looks like below. DIE (0x00000023) is for actual user defined variable and artificial one DIE (0x000000b1) is at local scope, the one at local scope gets precedence.

0x0000000c: DW_TAG_compile_unit
              DW_AT_producer    ("clang version 14.0.0")
              DW_AT_language    (DW_LANG_C99)
              DW_AT_name        ("debug_threadprivate_copyin.c")
              DW_AT_str_offsets_base    (0x00000008)
              DW_AT_stmt_list   (0x00000000)
              DW_AT_comp_dir    ("/home/alok/amdllvm/build.llvm.d")
              DW_AT_low_pc      (0x0000000000000000)
              DW_AT_high_pc     (0x000000000000029b)
              DW_AT_addr_base   (0x00000008)

0x00000023:   DW_TAG_variable
                DW_AT_name      ("gbl_dynamic_int")
                DW_AT_type      (0x00000036 "int")
                DW_AT_external  (true)
                DW_AT_decl_file ("debug_threadprivate_copyin.c")
                DW_AT_decl_line (22)
                DW_AT_location  (DW_OP_const8u 0x0, DW_OP_GNU_push_tls_address)

0x00000089:   DW_TAG_subprogram
                DW_AT_low_pc    (0x0000000000000090)
                DW_AT_high_pc   (0x0000000000000260)
                DW_AT_frame_base        (DW_OP_reg6 RBP)
                DW_AT_call_all_calls    (true)
                DW_AT_name      (".omp_outlined._debug__")
                DW_AT_decl_file ("debug_threadprivate_copyin.c")
                DW_AT_decl_line (35)
                DW_AT_prototyped        (true)

0x000000b1:     DW_TAG_formal_parameter
                  DW_AT_location        (DW_OP_fbreg -32)
                  DW_AT_name    ("gbl_dynamic_int")
                  DW_AT_decl_file       ("debug_threadprivate_copyin.c")
                  DW_AT_decl_line       (22)
                  DW_AT_type    (0x00000154 "int &")
alok updated this revision to Diff 423362.Apr 18 2022, 5:23 AM

Re-based.

aprantl accepted this revision.Apr 22 2022, 10:14 AM

Oh, it's a global variable that supposed to shadow the function parameter! Thanks for clarifying.

This revision is now accepted and ready to land.Apr 22 2022, 10:14 AM