OSDN Git Service

[PGO] [Coverage] put covmap into note section with no 'alloc flag' (Linux)
authorXinliang David Li <davidxl@google.com>
Thu, 14 Jan 2016 18:09:45 +0000 (18:09 +0000)
committerXinliang David Li <davidxl@google.com>
Thu, 14 Jan 2016 18:09:45 +0000 (18:09 +0000)
Coverage mapping data is not referenced by runtime, and they won't be dumped
into profile data. There is no need to allocate memory for covmap sections.
A good side effect of this change is that the coverage map data won't be mistakenly
 garbage collected by the linker (for Gold linker only, BFD linker has an issue where the a bug is filed).
Tested with clang build with instrumentation and -fcoverage-mapping and linker GC. The size of
 covmap section is ~17.6M so the text segment size will be reduced by this amount with this change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257781 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TargetLoweringObjectFileImpl.cpp

index 58ae9cc..3c9026e 100644 (file)
@@ -33,6 +33,7 @@
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSymbolELF.h"
 #include "llvm/MC/MCValue.h"
+#include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Support/COFF.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/ELF.h"
@@ -119,6 +120,10 @@ getELFKindForNamedSection(StringRef Name, SectionKind K) {
   // section(".eh_frame") gcc will produce:
   //
   //   .section   .eh_frame,"a",@progbits
+  
+  if (Name == getInstrProfCoverageSectionName(false))
+    return SectionKind::getMetadata();
+
   if (Name.empty() || Name[0] != '.') return K;
 
   // Some lame default implementation based on some magic section names.
@@ -150,6 +155,9 @@ getELFKindForNamedSection(StringRef Name, SectionKind K) {
 
 static unsigned getELFSectionType(StringRef Name, SectionKind K) {
 
+  if (Name == getInstrProfCoverageSectionName(false))
+    return ELF::SHT_NOTE;
+
   if (Name == ".init_array")
     return ELF::SHT_INIT_ARRAY;