Skip to content

Commit 4a5ddf8

Browse files
committedApr 14, 2017
[Profile] Make host tool aware of object format when quering prof section names
Differential Revision: https://reviews.llvm.org/D32073 llvm-svn: 300352
1 parent 9c27d79 commit 4a5ddf8

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed
 

‎llvm/include/llvm/ProfileData/InstrProf.h

+14
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,21 @@ std::string getInstrProfCountersSectionName(const Module *M = nullptr);
6363
/// the host machine, nor will segment prefix be added.
6464
std::string getInstrProfNameSectionName(const Module *M = nullptr);
6565

66+
/// Similar to the above, but used by host tool (e.g, coverage) which has
67+
/// object format information. The section name returned is not prefixed
68+
/// with segment name.
69+
std::string getInstrProfNameSectionNameInObject(bool isCoff);
70+
6671
/// Return the name of the data section containing per-function control
6772
/// data. If M is null, the target platform is assumed to be the same as
6873
/// the host machine, and the segment prefix will not be added.
6974
std::string getInstrProfDataSectionName(const Module *M = nullptr);
7075

76+
/// Similar to the above, but used by host tool (e.g, coverage) which has
77+
/// object format information. The section name returned is not prefixed
78+
/// with segment name.
79+
std::string getInstrProfDataSectionNameInObject(bool isCoff);
80+
7181
/// Return the name of data section containing pointers to value profile
7282
/// counters/nodes. If M is null, the target platform is assumed to be
7383
/// the same as the host machine, and the segment prefix will not be added.
@@ -92,6 +102,10 @@ inline StringRef getInstrProfValueRangeProfFuncName() {
92102
/// Return the name of the section containing function coverage mapping
93103
/// data.
94104
std::string getInstrProfCoverageSectionName(const Module *M = nullptr);
105+
/// Similar to the above, but used by host tool (e.g, coverage) which has
106+
/// object format information. The section name returned is not prefixed
107+
/// with segment name.
108+
std::string getInstrProfCoverageSectionNameInObject(bool isCoff);
95109

96110
/// Return the name prefix of variables containing instrumented function names.
97111
inline StringRef getInstrProfNameVarPrefix() { return "__profn_"; }

‎llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,8 @@ getELFKindForNamedSection(StringRef Name, SectionKind K) {
132132
// section(".eh_frame") gcc will produce:
133133
//
134134
// .section .eh_frame,"a",@progbits
135-
136-
// TODO: to support Win->ELF cross compilation with coverage properly,
137-
// need to pass the module pointer to the following call.
138-
if (Name == getInstrProfCoverageSectionName())
135+
136+
if (Name == getInstrProfCoverageSectionNameInObject(false /*not coff*/))
139137
return SectionKind::getMetadata();
140138

141139
if (Name.empty() || Name[0] != '.') return K;

‎llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "llvm/ProfileData/Coverage/CoverageMappingReader.h"
1516
#include "llvm/ADT/ArrayRef.h"
1617
#include "llvm/ADT/DenseMap.h"
17-
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/STLExtras.h"
19+
#include "llvm/ADT/SmallVector.h"
1920
#include "llvm/ADT/StringRef.h"
20-
#include "llvm/ADT/Triple.h"
21+
#include "llvm/ADT/Triple.h"
2122
#include "llvm/Object/Binary.h"
23+
#include "llvm/Object/COFF.h"
2224
#include "llvm/Object/Error.h"
2325
#include "llvm/Object/MachOUniversal.h"
2426
#include "llvm/Object/ObjectFile.h"
25-
#include "llvm/ProfileData/Coverage/CoverageMappingReader.h"
2627
#include "llvm/ProfileData/InstrProf.h"
2728
#include "llvm/Support/Casting.h"
2829
#include "llvm/Support/Debug.h"
30+
#include "llvm/Support/Endian.h"
2931
#include "llvm/Support/Error.h"
3032
#include "llvm/Support/ErrorHandling.h"
31-
#include "llvm/Support/Endian.h"
3233
#include "llvm/Support/LEB128.h"
3334
#include "llvm/Support/MathExtras.h"
3435
#include "llvm/Support/raw_ostream.h"
@@ -648,15 +649,13 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,
648649
: support::endianness::big;
649650

650651
// Look for the sections that we are interested in.
651-
// TODO: with the current getInstrProfXXXSectionName interfaces, the
652-
// the coverage reader host tool is limited to read coverage section on
653-
// binaries with compatible profile section naming scheme as the host
654-
// platform. Currently, COFF format binaries have different section
655-
// naming scheme from the all the rest.
656-
auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName());
652+
bool IsCoff = (dyn_cast<COFFObjectFile>(OF.get()) != nullptr);
653+
auto NamesSection =
654+
lookupSection(*OF, getInstrProfNameSectionNameInObject(IsCoff));
657655
if (auto E = NamesSection.takeError())
658656
return E;
659-
auto CoverageSection = lookupSection(*OF, getInstrProfCoverageSectionName());
657+
auto CoverageSection =
658+
lookupSection(*OF, getInstrProfCoverageSectionNameInObject(IsCoff));
660659
if (auto E = CoverageSection.takeError())
661660
return E;
662661

‎llvm/lib/ProfileData/InstrProf.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ const char *InstrProfSectNamePrefix[] = {
173173
#include "llvm/ProfileData/InstrProfData.inc"
174174
};
175175

176-
std::string getInstrProfSectionName(const Module *M, InstrProfSectKind Kind) {
176+
std::string getInstrProfSectionName(bool isCoff, InstrProfSectKind Kind) {
177+
return isCoff ? InstrProfSectNameCoff[Kind] : InstrProfSectNameCommon[Kind];
178+
}
177179

180+
std::string getInstrProfSectionName(const Module *M, InstrProfSectKind Kind) {
178181
if (!M)
179182
return InstrProfSectName[Kind];
180183

@@ -206,10 +209,18 @@ std::string getInstrProfNameSectionName(const Module *M) {
206209
return getInstrProfSectionName(M, IPSK_name);
207210
}
208211

212+
std::string getInstrProfNameSectionNameInObject(bool isCoff) {
213+
return getInstrProfSectionName(isCoff, IPSK_name);
214+
}
215+
209216
std::string getInstrProfDataSectionName(const Module *M) {
210217
return getInstrProfSectionName(M, IPSK_data);
211218
}
212219

220+
std::string getInstrProfDataSectionNameInObject(bool isCoff) {
221+
return getInstrProfSectionName(isCoff, IPSK_data);
222+
}
223+
213224
std::string getInstrProfValuesSectionName(const Module *M) {
214225
return getInstrProfSectionName(M, IPSK_vals);
215226
}
@@ -222,6 +233,10 @@ std::string getInstrProfCoverageSectionName(const Module *M) {
222233
return getInstrProfSectionName(M, IPSK_covmap);
223234
}
224235

236+
std::string getInstrProfCoverageSectionNameInObject(bool isCoff) {
237+
return getInstrProfSectionName(isCoff, IPSK_covmap);
238+
}
239+
225240
void SoftInstrProfErrors::addError(instrprof_error IE) {
226241
if (IE == instrprof_error::success)
227242
return;

0 commit comments

Comments
 (0)
Please sign in to comment.