@@ -57,6 +57,12 @@ cl::opt<bool>
57
57
DarwinLongFormat (" l" , cl::desc(" When format is darwin, use long format "
58
58
" to include addresses and offsets." ));
59
59
60
+ cl::opt<bool >
61
+ ELFCommons (" common" ,
62
+ cl::desc (" Print common symbols in the ELF file. When using "
63
+ " Berkely format, this is added to bss." ),
64
+ cl::init(false ));
65
+
60
66
static cl::list<std::string>
61
67
ArchFlags (" arch" , cl::desc(" architecture(s) from a Mach-O file to dump" ),
62
68
cl::ZeroOrMore);
@@ -127,6 +133,15 @@ static bool considerForSize(ObjectFile *Obj, SectionRef Section) {
127
133
return true ;
128
134
}
129
135
136
+ // / Total size of all ELF common symbols
137
+ static uint64_t getCommonSize (ObjectFile *Obj) {
138
+ uint64_t TotalCommons = 0 ;
139
+ for (auto &Sym : Obj->symbols ())
140
+ if (Obj->getSymbolFlags (Sym.getRawDataRefImpl ()) & SymbolRef::SF_Common)
141
+ TotalCommons += Obj->getCommonSymbolSize (Sym.getRawDataRefImpl ());
142
+ return TotalCommons;
143
+ }
144
+
130
145
// / Print the size of each Mach-O segment and section in @p MachO.
131
146
// /
132
147
// / This is when used when @c OutputFormat is darwin and produces the same
@@ -352,6 +367,13 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
352
367
outs () << format (fmt.str ().c_str (), namestr.c_str (), size, addr);
353
368
}
354
369
370
+ if (ELFCommons) {
371
+ uint64_t CommonSize = getCommonSize (Obj);
372
+ total += CommonSize;
373
+ outs () << format (fmt.str ().c_str (), std::string (" *COM*" ).c_str (),
374
+ CommonSize, static_cast <uint64_t >(0 ));
375
+ }
376
+
355
377
// Print total.
356
378
fmtbuf.clear ();
357
379
fmt << " %-" << max_name_len << " s "
@@ -379,6 +401,9 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
379
401
total_bss += size;
380
402
}
381
403
404
+ if (ELFCommons)
405
+ total_bss += getCommonSize (Obj);
406
+
382
407
total = total_text + total_data + total_bss;
383
408
384
409
if (!BerkeleyHeaderPrinted) {
0 commit comments