Skip to content

Request for new "declfile" source type #339

@ertucci

Description

@ertucci

I’m trying to use bloaty to divide up memory usage of a project by directory structure. The compileunits source type seemed to be the closest fit to what I was looking for, so I used it as the base type for my custom directory structure data type. However, I noticed that constants inlined within header files weren’t placed into a compileunit named with the path to file, which was the case for most symbols. These were instead rolled up in a generic [section .rodata] compileunit. I’ve tried to reproduce a simple version of this behavior using the source code at the bottom and compiling using gcc and clang.

The symbol, sample_array, should be 40 bytes in size, defined in array.h, and used in translation_unit1.cc and translation_unit2.cc. However, bloaty analysis of the clang executable puts it under both main.cc with strange size attribution because of additional inclusion in the .eh_frame_hdr section.

$ bloaty bloat_header_inline_example_clang.elf -d sections,compileunits,symbols --domain=vm --source-filter=sample_array
     VM SIZE    
 -------------- 
  76.9%      40    .rodata
   100.0%      40    main.cc
     100.0%      40    sample_array
  23.1%      12    .eh_frame_hdr
   100.0%      12    main.cc
     100.0%      12    sample_array
 100.0%      52    TOTAL

For gcc, the compileunit name is not intuitive and therefore it is difficult to attribute symbols defined in header inlines to the appropriate source code.

$ bloaty bloat_header_inline_example_gcc.elf -d sections,compileunits,symbols --domain=vm --source-filter=sample_array
     VM SIZE    
 -------------- 
 100.0%      40    .rodata
   100.0%      40    QUIET_NAN__ 1
     100.0%      40    sample_array
 100.0%      40    TOTAL

Looking at the dwarfdump of both executables, it looks like the information I want is present under the DW_AT_decl_file tag.

COMPILE_UNIT<header overall offset = 0x000000b1>:
< 0><0x0000000c>  DW_TAG_compile_unit
                    DW_AT_producer              (indexed string: 0x00000000)Fuchsia clang version 15.0.0 (https://llvm.googlesource.com/a/llvm-project 3a20597776a5d2920e511d81653b4d2b6ca0c855)
                    DW_AT_language              DW_LANG_C_plus_plus_14
                    DW_AT_name                  (indexed string: 0x00000001)translation_unit2.cc
                    DW_AT_str_offsets_base      0x00000058
                    DW_AT_stmt_list             0x000000f0
                    DW_AT_comp_dir              (indexed string: 0x00000002)
                    DW_AT_low_pc                (addr_index: 0x00000001)0x00001880
                    DW_AT_high_pc               <offset-from-lowpc> 56 <highpc: 0x000018b8>
                    DW_AT_addr_base             0x00000030

LOCAL_SYMBOLS:

< 1><0x00000035>    DW_TAG_variable
                      DW_AT_name                  (indexed string: 0x00000005)sample_array
                      DW_AT_type                  <0x00000040>
                      DW_AT_external              yes(1)
                      DW_AT_decl_file             0x00000001 /array.h
                      DW_AT_decl_line             0x00000003
                      DW_AT_location              len 0x0002: 0xa100:
                          DW_OP_addrx 0

Is it possible to create a different source type which is primarily based on the decl file (as this is essentially what I want and compileunits was just as close as I could get)?

``

main.h

#pragma once

int main();

main.cc

#include "translation_unit1.h"
#include "translation_unit2.h"

int main() {
  int i = 0;
  while(1){
    increment_i_1(&i);
    increment_i_2(&i);
  }
  return 0;
}

array.h

#pragma once

inline constexpr int sample_array[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

translation_unit1.h

#pragma once

void increment_i_1(int* i);

translation_unit1.cc

#include "translation_unit1.h"
#include "array.h"

const int i_1 = 2;

void increment_i_1(int* i) {
  *i += sample_array[*i % 10];
  *i += i_1;
}

translation_unit2.h

#pragma once

void increment_i_2(int* i);

translation_unit2.cc

#include "translation_unit2.h"
#include "array.h"

const int i_2 = 3;

void increment_i_2(int* i) {
  *i += sample_array[*i % 10];
  *i += i_2;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions