[PATCH] D40128: [ELF] - Reveal layout of synthetic mergeable sections when producing -Map
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 06:56:31 PST 2017
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';
+ }
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40128.123175.patch
Type: text/x-patch
Size: 3809 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171116/6ec40249/attachment.bin>
More information about the llvm-commits
mailing list