[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

Mitch Phillips via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 20 16:19:39 PDT 2022

hctim added a comment.

In D123534#3462551 <https://reviews.llvm.org/D123534#3462551>, @dblaikie wrote:

> What's the DW_AT_type referring to? (why is there a type called ".str"?)
> For your particular purposes, it seems like the name/type/linkage name could all be omitted & that might be OK, since these entities aren't actually named in the source?

In D123534#3462849 <https://reviews.llvm.org/D123534#3462849>, @probinson wrote:

> I'd expect it to point to a base type, in this case character string.  A typeless variable with a location would be pretty weird.
> But I agree the name/linkage_name would be unnecessary.

I've updated the patch to:

1. Omit the linkage name,
2. Omit the display name (including associated changes to allow this), and
3. Used the `char[SIZE]` type.

#3 could be optimised for file size further by changing to a `const char*` type, but I:

1. Can't see an obvious way to synthesize a `const char*` `QualType` to pass to `createGlobalVariableExpression`, and
2. Think it might actually be useful to have the correct type here (as it now also describes the size of the variable).

Here's the new dwarfdump:

  0x00000065:   DW_TAG_variable                                                                               
                  DW_AT_type      (0x0000006f "char [11]")                                                    
                  DW_AT_decl_file ("/tmp/file.c")                                                             
                  DW_AT_decl_line (4)                                                                         
                  DW_AT_location  (DW_OP_addrx 0x3)                                                           
  0x0000006f:   DW_TAG_array_type                                                                             
                  DW_AT_type      (0x00000048 "char")                                                         
  0x00000074:     DW_TAG_subrange_type                                                                        
                    DW_AT_type    (0x0000004c "__ARRAY_SIZE_TYPE__")                                          
                    DW_AT_count   (0x0b)                                                                      
  0x0000007a:     NULL

Apparently with `-DCMAKE_BUILD_TYPE='RelWithDebInfo'`, `bin/clang-15` went from 1373029152B to 1373030960B (~0%), which seems suspiciously low to me. I double checked the builds twice, and they seem to be right...

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list