[PATCH] D40128: [ELF] - Reveal layout of synthetic mergeable sections when producing -Map
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 17 21:18:27 PST 2017
FWIW, I consider this particularly useful.
If the linker can provide enough informations to users to diagnose
where they lost/gained bytes, I think it should.
Nothing before link time has the luxury of seeing the whole
executable/shared library (kinda), so having a linker pass (possibly
separate) could help a lot.
On Fri, Nov 17, 2017 at 9:07 PM, Rui Ueyama via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> I'm inclined to directly implement what Samuel and other people want to lld
> if it is useful for not only Chrome but also for other large projects that
> want to keep track of their binary size and analyze their binary contents.
>
> Such "analyze pass" is an independent pass, so it can be designed separately
> than other passes in the linker.
>
> We could emit enough information in a map file or something so that a
> post-processor can analyze binary size, but it might be much easier to do
> that in the linker, because the linker naturally knows almost everything.
>
>
> On Fri, Nov 17, 2017 at 4:07 PM, Rafael Avila de Espindola
> <rafael.espindola at gmail.com> wrote:
>>
>> Samuel, would the information included in this patch solve your problem?
>>
>> I agree that printing an address for each input section is bogus.
>> Keeping the synthetic in the output is probably a good thing, since that
>> is what has an address and it shows the final size of each merge.
>>
>> So what we have to figure out is a format that
>> * Doesn't print a bogus address for input SHF_MERGE.
>> * Still includes synthetic sections.
>>
>> This map is a direct textual dump of lld's internal state and it is a
>> fact that some input sections are added directly to output sections
>> and some are not. How about replacing "Out In" with "Section tree" and
>> allowing it to have 2 or 3 levels?
>>
>> BTW, .eh_frame could also show up as 3 levels.
>>
>> Cheers,
>> Rafael
>>
>>
>> George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
>>
>> > grimar created this revision.
>> > Herald added subscribers: arichardson, emaste.
>> >
>> > It is inspired by comments for PR35248 though not directly relative to
>> > it.
>> > It turns out we do not show the internal layout for mergeable sections
>> > when
>> > producing Map file. Though it can be useful to show where is content
>> > coming from and
>> > what is initial size (before mrging) and final size.
>> > Patch adds support for dumping such sections.
>> >
>> >
>> > https://reviews.llvm.org/D40128
>> >
>> > Files:
>> > ELF/MapFile.cpp
>> > ELF/SyntheticSections.h
>> > test/ELF/Inputs/map-file2.s
>> > test/ELF/map-file.s
>> >
>> >
>> > Index: test/ELF/map-file.s
>> > ===================================================================
>> > --- test/ELF/map-file.s
>> > +++ test/ELF/map-file.s
>> > @@ -29,6 +29,9 @@
>> > abs = 0xAB5
>> > labs = 0x1AB5
>> >
>> > +.section .strings,"MS", at progbits,1
>> > +.asciz "AAA"
>> > +
>> > // CHECK: Address Size Align Out In
>> > Symbol
>> > // CHECK-NEXT: 0000000000200158 0000000000000030 8 .eh_frame
>> > // CHECK-NEXT: 0000000000200158 0000000000000030 8
>> > <internal>:(.eh_frame)
>> > @@ -49,12 +52,18 @@
>> > // CHECK-NEXT: 0000000000202000 0000000000000004 16 .bss
>> > // CHECK-NEXT: 0000000000202000 0000000000000004 16
>> > {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON)
>> > // CHECK-NEXT: 0000000000202000 0000000000000004 0
>> > common
>> > +// CHECK-NEXT: 0000000000000000 0000000000000008 2 .strings
>> > +// CHECK-NEXT: 0000000000000000 0000000000000004 1
>> > <internal>:(.strings)
>> > +// CHECK-NEXT: 0000000000000000 0000000000000004 1
>> > {{.*}}{{/|\\}}map-file.s.tmp1.o:(.strings)
>> > +// CHECK-NEXT: 0000000000000004 0000000000000004 2
>> > <internal>:(.strings)
>> > +// CHECK-NEXT: 0000000000000000 0000000000000008 2
>> > {{.*}}{{/|\\}}map-file.s.tmp2.o:(.strings)
>> > // CHECK-NEXT: 0000000000000000 0000000000000008 1 .comment
>>
>>
>>
>>
>>
>>
>> > // CHECK-NEXT: 0000000000000000 0000000000000008 1
>> > <internal>:(.comment)
>> > +// CHECK-NEXT: 0000000000000000 0000000000000008 1
>> > <internal>:(.comment)
>> > // CHECK-NEXT: 0000000000000000 0000000000000120 8 .symtab
>> > // CHECK-NEXT: 0000000000000000 0000000000000120 8
>> > <internal>:(.symtab)
>> > -// CHECK-NEXT: 0000000000000000 0000000000000039 1 .shstrtab
>> > -// CHECK-NEXT: 0000000000000000 0000000000000039 1
>> > <internal>:(.shstrtab)
>> > +// CHECK-NEXT: 0000000000000000 0000000000000042 1 .shstrtab
>> > +// CHECK-NEXT: 0000000000000000 0000000000000042 1
>> > <internal>:(.shstrtab)
>> > // CHECK-NEXT: 0000000000000000 0000000000000038 1 .strtab
>> > // CHECK-NEXT: 0000000000000000 0000000000000038 1
>> > <internal>:(.strtab)
>> >
>> > Index: test/ELF/Inputs/map-file2.s
>> > ===================================================================
>> > --- test/ELF/Inputs/map-file2.s
>> > +++ test/ELF/Inputs/map-file2.s
>> > @@ -6,3 +6,7 @@
>> > .section .text.zed,"ax", at progbits
>> > .global zed
>> > zed:
>> > +.section .strings,"MS", at progbits,1
>> > +.align 2
>> > +.asciz "AAA"
>> > +.asciz "AAA"
>> > Index: ELF/SyntheticSections.h
>> > ===================================================================
>> > --- ELF/SyntheticSections.h
>> > +++ ELF/SyntheticSections.h
>> > @@ -682,6 +682,8 @@
>> > public:
>> > void addSection(MergeInputSection *MS);
>> >
>> > + ArrayRef<MergeInputSection *> getSections() { return Sections; }
>> > +
>> > protected:
>> > MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags,
>> > uint32_t Alignment)
>> > Index: ELF/MapFile.cpp
>> > ===================================================================
>> > --- ELF/MapFile.cpp
>> > +++ ELF/MapFile.cpp
>> > @@ -27,9 +27,11 @@
>> > #include "SymbolTable.h"
>> > #include "SyntheticSections.h"
>> > #include "lld/Common/Threads.h"
>> > +#include "llvm/BinaryFormat/ELF.h"
>> > #include "llvm/Support/raw_ostream.h"
>> >
>> > using namespace llvm;
>> > +using namespace llvm::ELF;
>> > using namespace llvm::object;
>> >
>> > using namespace lld;
>> > @@ -132,6 +134,15 @@
>> > OS << indent(1) << toString(IS) << '\n';
>> > for (Defined *Sym : SectionSyms[IS])
>> > OS << SymStr[Sym] << '\n';
>> > +
>> > + // Dump synthetic mergeable sections layout.
>> > + if (!isa<SyntheticSection>(IS) || !(IS->Flags & SHF_MERGE))
>> > + continue;
>> > + MergeSyntheticSection *MS = static_cast<MergeSyntheticSection
>> > *>(IS);
>> > + for (MergeInputSection *Sec : MS->getSections()) {
>> > + writeHeader(OS, 0, Sec->getSize(), Sec->Alignment);
>> > + OS << indent(2) << toString(Sec) << '\n';
>> > + }
>> > }
>> > }
>> > }
>> >
>> >
>> > Index: test/ELF/map-file.s
>> > ===================================================================
>> > --- test/ELF/map-file.s
>> > +++ test/ELF/map-file.s
>> > @@ -29,6 +29,9 @@
>> > abs = 0xAB5
>> > labs = 0x1AB5
>> >
>> > +.section .strings,"MS", at progbits,1
>> > +.asciz "AAA"
>> > +
>> > // CHECK: Address Size Align Out In
>> > Symbol
>> > // CHECK-NEXT: 0000000000200158 0000000000000030 8 .eh_frame
>> > // CHECK-NEXT: 0000000000200158 0000000000000030 8
>> > <internal>:(.eh_frame)
>> > @@ -49,12 +52,18 @@
>> > // CHECK-NEXT: 0000000000202000 0000000000000004 16 .bss
>> > // CHECK-NEXT: 0000000000202000 0000000000000004 16
>> > {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON)
>> > // CHECK-NEXT: 0000000000202000 0000000000000004 0
>> > common
>> > +// CHECK-NEXT: 0000000000000000 0000000000000008 2 .strings
>> > +// CHECK-NEXT: 0000000000000000 0000000000000004 1
>> > <internal>:(.strings)
>> > +// CHECK-NEXT: 0000000000000000 0000000000000004 1
>> > {{.*}}{{/|\\}}map-file.s.tmp1.o:(.strings)
>> > +// CHECK-NEXT: 0000000000000004 0000000000000004 2
>> > <internal>:(.strings)
>> > +// CHECK-NEXT: 0000000000000000 0000000000000008 2
>> > {{.*}}{{/|\\}}map-file.s.tmp2.o:(.strings)
>> > // CHECK-NEXT: 0000000000000000 0000000000000008 1 .comment
>> > // CHECK-NEXT: 0000000000000000 0000000000000008 1
>> > <internal>:(.comment)
>> > +// CHECK-NEXT: 0000000000000000 0000000000000008 1
>> > <internal>:(.comment)
>> > // CHECK-NEXT: 0000000000000000 0000000000000120 8 .symtab
>> > // CHECK-NEXT: 0000000000000000 0000000000000120 8
>> > <internal>:(.symtab)
>> > -// CHECK-NEXT: 0000000000000000 0000000000000039 1 .shstrtab
>> > -// CHECK-NEXT: 0000000000000000 0000000000000039 1
>> > <internal>:(.shstrtab)
>> > +// CHECK-NEXT: 0000000000000000 0000000000000042 1 .shstrtab
>> > +// CHECK-NEXT: 0000000000000000 0000000000000042 1
>> > <internal>:(.shstrtab)
>> > // CHECK-NEXT: 0000000000000000 0000000000000038 1 .strtab
>> > // CHECK-NEXT: 0000000000000000 0000000000000038 1
>> > <internal>:(.strtab)
>> >
>> > Index: test/ELF/Inputs/map-file2.s
>> > ===================================================================
>> > --- test/ELF/Inputs/map-file2.s
>> > +++ test/ELF/Inputs/map-file2.s
>> > @@ -6,3 +6,7 @@
>> > .section .text.zed,"ax", at progbits
>> > .global zed
>> > zed:
>> > +.section .strings,"MS", at progbits,1
>> > +.align 2
>> > +.asciz "AAA"
>> > +.asciz "AAA"
>> > Index: ELF/SyntheticSections.h
>> > ===================================================================
>> > --- ELF/SyntheticSections.h
>> > +++ ELF/SyntheticSections.h
>> > @@ -682,6 +682,8 @@
>> > public:
>> > void addSection(MergeInputSection *MS);
>> >
>> > + ArrayRef<MergeInputSection *> getSections() { return Sections; }
>> > +
>> > protected:
>> > MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags,
>> > uint32_t Alignment)
>> > Index: ELF/MapFile.cpp
>> > ===================================================================
>> > --- ELF/MapFile.cpp
>> > +++ ELF/MapFile.cpp
>> > @@ -27,9 +27,11 @@
>> > #include "SymbolTable.h"
>> > #include "SyntheticSections.h"
>> > #include "lld/Common/Threads.h"
>> > +#include "llvm/BinaryFormat/ELF.h"
>> > #include "llvm/Support/raw_ostream.h"
>> >
>> > using namespace llvm;
>> > +using namespace llvm::ELF;
>> > using namespace llvm::object;
>> >
>> > using namespace lld;
>> > @@ -132,6 +134,15 @@
>> > OS << indent(1) << toString(IS) << '\n';
>> > for (Defined *Sym : SectionSyms[IS])
>> > OS << SymStr[Sym] << '\n';
>> > +
>> > + // Dump synthetic mergeable sections layout.
>> > + if (!isa<SyntheticSection>(IS) || !(IS->Flags & SHF_MERGE))
>> > + continue;
>> > + MergeSyntheticSection *MS = static_cast<MergeSyntheticSection
>> > *>(IS);
>> > + for (MergeInputSection *Sec : MS->getSections()) {
>> > + writeHeader(OS, 0, Sec->getSize(), Sec->Alignment);
>> > + OS << indent(2) << toString(Sec) << '\n';
>> > + }
>> > }
>> > }
>> > }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
--
Davide
"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare
More information about the llvm-commits
mailing list