Skip to content

Commit 1f83fdb

Browse files
authored
Revert "[llvm-profgen] Support [buildid:]0xaddr format in perfscript input" (llvm#195551)
Reverts llvm#190863 due to buildbot breakage e.g., https://lab.llvm.org/buildbot/#/builders/52/builds/16951 ``` Failed Tests (1): LLVM :: tools/llvm-profgen/filter-build-id.test ``` ``` ==llvm-profgen==3809550==ERROR: AddressSanitizer: container-overflow on address 0x6e80441e1762 at pc 0x6216c3f2cdce bp 0x7fff3c3ddf60 sp 0x7fff3c3dd710 READ of size 8 at 0x6e80441e1762 thread T0 #0 0x6216c3f2cdcd in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:848:7 #1 0x6216c3f2d25c in bcmp /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:894:10 #2 0x6216c400b836 in operator== /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/StringRef.h:914:10 #3 0x6216c400b836 in operator!= /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/StringRef.h:917:69 #4 0x6216c400b836 in llvm::sampleprof::PerfScriptReader::extractCallstack(llvm::sampleprof::TraceStream&, llvm::SmallVectorImpl<unsigned long>&) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:801:36 #5 0x6216c400d37a in llvm::sampleprof::HybridPerfReader::parseSample(llvm::sampleprof::TraceStream&, unsigned long) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:881:8 #6 0x6216c40150d8 in parseSample /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1118:3 #7 0x6216c40150d8 in llvm::sampleprof::PerfScriptReader::parseEventOrSample(llvm::sampleprof::TraceStream&) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1201:5 #8 0x6216c401539a in llvm::sampleprof::PerfScriptReader::parseAndAggregateTrace() /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1210:5 #9 0x6216c4018c88 in llvm::sampleprof::PerfScriptReader::parsePerfTraces() /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1457:3 #10 0x6216c3ff2c7a in main /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/llvm-profgen.cpp:229:19 #11 0x72404502a8c0 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a8c0) (BuildId: ae327f26c123ea1374623c41e676a4bf00e5c1cb) #12 0x72404502a9d7 in __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a9d7) (BuildId: ae327f26c123ea1374623c41e676a4bf00e5c1cb) #13 0x6216c3f0f3d4 in _start (/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-profgen+0x2f083d4) 0x6e80441e1762 is located 18 bytes inside of 48-byte region [0x6e80441e1750,0x6e80441e1780) allocated by thread T0 here: #0 0x6216c3feab0d in operator new(unsigned long) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:109:35 #1 0x724045511c07 in __libcpp_allocate<char> /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/include/__new/allocate.h:42:28 #2 0x724045511c07 in allocate /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/include/__memory/allocator.h:92:14 #3 0x724045511c07 in allocate_at_least /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/include/__memory/allocator.h:99:13 #4 0x724045511c07 in allocate_at_least<std::__1::allocator<char> > /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/include/__memory/allocator_traits.h:340:22 #5 0x724045511c07 in __allocate_at_least<std::__1::allocator<char> > /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/include/__memory/allocate_at_least.h:36:16 #6 0x724045511c07 in __allocate_long_buffer /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/include/string:2259:21 #7 0x724045511c07 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::__grow_by(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/include/string:2769:25 #8 0x6216c401d90a in __grow_by_without_replace /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_install_asan/include/c++/v1/string:2795:3 #9 0x6216c401d90a in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>& std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::append[abi:sqn230000]<char const*, 0>(char const*, char const*) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_install_asan/include/c++/v1/string:1431:9 #10 0x6216c401d1a6 in std::__1::basic_istream<char, std::__1::char_traits<char>>& std::__1::getline[abi:sqn230000]<char, std::__1::char_traits<char>, std::__1::allocator<char>>(std::__1::basic_istream<char, std::__1::char_traits<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, char) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_install_asan/include/c++/v1/istream:1309:15 #11 0x6216c4014a76 in getline<char, std::__1::char_traits<char>, std::__1::allocator<char> > /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_install_asan/include/c++/v1/istream:1343:10 #12 0x6216c4014a76 in advance /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.h:52:10 #13 0x6216c4014a76 in llvm::sampleprof::PerfScriptReader::parseAggregatedCount(llvm::sampleprof::TraceStream&) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1110:13 #14 0x6216c4015095 in parseSample /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1116:20 #15 0x6216c4015095 in llvm::sampleprof::PerfScriptReader::parseEventOrSample(llvm::sampleprof::TraceStream&) /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1201:5 #16 0x6216c401539a in llvm::sampleprof::PerfScriptReader::parseAndAggregateTrace() /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1210:5 #17 0x6216c4018c88 in llvm::sampleprof::PerfScriptReader::parsePerfTraces() /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp:1457:3 #18 0x6216c3ff2c7a in main /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/tools/llvm-profgen/llvm-profgen.cpp:229:19 #19 0x72404502a8c0 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a8c0) (BuildId: ae327f26c123ea1374623c41e676a4bf00e5c1cb) #20 0x72404502a9d7 in __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a9d7) (BuildId: ae327f26c123ea1374623c41e676a4bf00e5c1cb) #21 0x6216c3f0f3d4 in _start (/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-profgen+0x2f083d4) ```
1 parent 2dccc37 commit 1f83fdb

4 files changed

Lines changed: 13 additions & 135 deletions

File tree

llvm/test/tools/llvm-profgen/Inputs/buildid-cs-noprobe.aggperfscript

Lines changed: 0 additions & 11 deletions
This file was deleted.

llvm/test/tools/llvm-profgen/Inputs/buildid-cs-noprobe.perfscript

Lines changed: 0 additions & 9 deletions
This file was deleted.

llvm/test/tools/llvm-profgen/filter-build-id.test

Lines changed: 0 additions & 57 deletions
This file was deleted.

llvm/tools/llvm-profgen/PerfReader.cpp

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ cl::opt<bool> TimeProfGen("time-profgen", cl::desc("Time llvm-profgen phases"),
6969
static const char *TimerGroupName = "profgen";
7070
static const char *TimerGroupDesc = "llvm-profgen";
7171

72-
static cl::opt<std::string> FilterBuildID(
73-
"filter-build-id",
74-
cl::desc("Override auto-detected build ID for filtering perfscript "
75-
"addresses in [buildid:]addr format. When set, only addresses "
76-
"with a matching build ID prefix are kept."),
77-
cl::cat(ProfGenCategory));
78-
7972
namespace sampleprof {
8073

8174
void VirtualUnwinder::unwindCall(UnwindState &State) {
@@ -672,37 +665,12 @@ void HybridPerfReader::unwindSamples() {
672665
}
673666

674667
/// Parse a hex address from \p Str.
675-
/// Parse an optional [buildid:] prefix into \p BuildID.
676-
static bool parseAddress(StringRef Str, uint64_t &Addr, bool HasPrefix,
677-
StringRef &BuildID) {
678-
size_t ColonPos = Str.find(':');
679-
if (ColonPos != StringRef::npos) {
680-
BuildID = Str.substr(0, ColonPos);
681-
Str = Str.substr(ColonPos + 1);
682-
}
668+
static bool parseAddress(StringRef Str, uint64_t &Addr, bool HasPrefix) {
683669
if (Str.consume_front("0x") != HasPrefix)
684670
return true;
685671
return Str.getAsInteger(16, Addr);
686672
}
687673

688-
/// Return the build ID to use for filtering perfscript addresses.
689-
/// If --filter-build-id is specified, use it as an override (with a warning
690-
/// if it doesn't match the binary's auto-detected build ID).
691-
/// Otherwise, use the auto-detected value from the binary.
692-
static StringRef getFilterBuildID(const ProfiledBinary *Binary) {
693-
StringRef BinaryBuildID = Binary->getFilterBuildID();
694-
if (FilterBuildID.getNumOccurrences() == 0)
695-
return BinaryBuildID;
696-
static bool Warned = false;
697-
if (!Warned && !BinaryBuildID.empty() && FilterBuildID != BinaryBuildID) {
698-
WithColor::warning() << "--filter-build-id=" << FilterBuildID
699-
<< " does not match binary build ID " << BinaryBuildID
700-
<< "\n";
701-
Warned = true;
702-
}
703-
return FilterBuildID;
704-
}
705-
706674
bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
707675
SmallVectorImpl<LBREntry> &LBRStack) {
708676
// The raw format of LBR stack is like:
@@ -720,9 +688,8 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
720688
// Skip the leading instruction pointer.
721689
size_t Index = 0;
722690
uint64_t LeadingAddr;
723-
StringRef LeadingBuildID;
724691
if (!Records.empty() && !Records[0].contains('/')) {
725-
if (parseAddress(Records[0], LeadingAddr, false, LeadingBuildID)) {
692+
if (parseAddress(Records[0], LeadingAddr, false)) {
726693
WarnInvalidLBR(TraceIt);
727694
TraceIt.advance();
728695
return false;
@@ -742,25 +709,19 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
742709
Token.split(Addresses, "/");
743710
uint64_t Src;
744711
uint64_t Dst;
745-
StringRef SrcBuildID, DstBuildID;
746712

747713
// Stop at broken LBR records.
748-
if (Addresses.size() < 2 ||
749-
parseAddress(Addresses[0], Src, true, SrcBuildID) ||
750-
parseAddress(Addresses[1], Dst, true, DstBuildID)) {
714+
if (Addresses.size() < 2 || parseAddress(Addresses[0], Src, true) ||
715+
parseAddress(Addresses[1], Dst, true)) {
751716
WarnInvalidLBR(TraceIt);
752717
break;
753718
}
754719

755720
// Canonicalize to use preferred load address as base address.
756721
Src = Binary->canonicalizeVirtualAddress(Src);
757722
Dst = Binary->canonicalizeVirtualAddress(Dst);
758-
// Filter by build ID.
759-
StringRef BinaryBuildID = getFilterBuildID(Binary);
760-
bool SrcIsInternal =
761-
SrcBuildID == BinaryBuildID && Binary->addressIsCode(Src);
762-
bool DstIsInternal =
763-
DstBuildID == BinaryBuildID && Binary->addressIsCode(Dst);
723+
bool SrcIsInternal = Binary->addressIsCode(Src);
724+
bool DstIsInternal = Binary->addressIsCode(Dst);
764725
if (!SrcIsInternal)
765726
Src = ExternalAddr;
766727
if (!DstIsInternal)
@@ -778,17 +739,16 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
778739
bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
779740
SmallVectorImpl<uint64_t> &CallStack) {
780741
// The raw format of call stack is like:
781-
// 4005dc # leaf frame (no buildid)
742+
// 4005dc # leaf frame
782743
// 400634
783-
// deadbeef:400684 # root frame (with buildid prefix)
744+
// 400684 # root frame
784745
// It's in bottom-up order with each frame in one line.
785746

786747
// Extract stack frames from sample
787748
while (!TraceIt.isAtEoF() && !isLBRSample(TraceIt.getCurrentLine(), true)) {
788749
StringRef FrameStr = TraceIt.getCurrentLine().ltrim();
789750
uint64_t FrameAddr = 0;
790-
StringRef FrameBuildID;
791-
if (parseAddress(FrameStr, FrameAddr, false, FrameBuildID)) {
751+
if (parseAddress(FrameStr, FrameAddr, false)) {
792752
// We might parse a non-perf sample line like empty line and comments,
793753
// skip it
794754
TraceIt.advance();
@@ -798,9 +758,7 @@ bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
798758

799759
FrameAddr = Binary->canonicalizeVirtualAddress(FrameAddr);
800760
// Currently intermixed frame from different binaries is not supported.
801-
bool IsExternal = FrameBuildID != getFilterBuildID(Binary) ||
802-
!Binary->addressIsCode(FrameAddr);
803-
if (IsExternal) {
761+
if (!Binary->addressIsCode(FrameAddr)) {
804762
if (CallStack.empty())
805763
NumLeafExternalFrame++;
806764
// Push a special value(ExternalAddr) for the external frames so that
@@ -1213,7 +1171,7 @@ void PerfScriptReader::parseAndAggregateTrace() {
12131171
// A LBR sample is like:
12141172
// 40062f 0x5c6313f/0x5c63170/P/-/-/0 0x5c630e7/0x5c63130/P/-/-/0 ...
12151173
// A heuristic for fast detection by checking whether a
1216-
// leading " 0x" or " buildid:0x" and the '/' exist.
1174+
// leading " 0x" and the '/' exist.
12171175
bool PerfScriptReader::isLBRSample(StringRef Line, bool CheckLineStart) {
12181176
// Skip the leading instruction pointer
12191177
SmallVector<StringRef, 32> Records;
@@ -1222,8 +1180,7 @@ bool PerfScriptReader::isLBRSample(StringRef Line, bool CheckLineStart) {
12221180
Line.split(Records, " ", 2, CheckLineStart);
12231181
if (Records.size() < 2)
12241182
return false;
1225-
if ((Records[1].starts_with("0x") || Records[1].contains(":0x")) &&
1226-
Records[1].contains('/'))
1183+
if (Records[1].starts_with("0x") && Records[1].contains('/'))
12271184
return true;
12281185
return false;
12291186
}
@@ -1261,10 +1218,8 @@ PerfContent PerfScriptReader::checkPerfScriptType(StringRef FileName) {
12611218

12621219
// Detect sample with call stack
12631220
int32_t Count = 0;
1264-
StringRef FrameBuildId;
12651221
while (!TraceIt.isAtEoF() &&
1266-
!parseAddress(TraceIt.getCurrentLine().ltrim(), FrameAddr, false,
1267-
FrameBuildId)) {
1222+
!parseAddress(TraceIt.getCurrentLine().ltrim(), FrameAddr, false)) {
12681223
Count++;
12691224
TraceIt.advance();
12701225
}

0 commit comments

Comments
 (0)