Skip to content

Commit 9bc7ba6

Browse files
committed
Revert "[profile] Add binary id into profiles"
This reverts commit e50a388.
1 parent 6133bb7 commit 9bc7ba6

23 files changed

+24
-256
lines changed

compiler-rt/include/profile/InstrProfData.inc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize)
137137
INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, (uintptr_t)CountersBegin)
138138
INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
139139
INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
140-
INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
141140
#undef INSTR_PROF_RAW_HEADER
142141
/* INSTR_PROF_RAW_HEADER end */
143142

@@ -646,7 +645,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
646645
(uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
647646

648647
/* Raw profile format version (start from 1). */
649-
#define INSTR_PROF_RAW_VERSION 6
648+
#define INSTR_PROF_RAW_VERSION 5
650649
/* Indexed profile format version (start from 1). */
651650
#define INSTR_PROF_INDEX_VERSION 7
652651
/* Coverage mapping format version (start from 0). */

compiler-rt/lib/profile/InstrProfilingInternal.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,4 @@ COMPILER_RT_VISIBILITY extern ValueProfNode *CurrentVNode;
193193
COMPILER_RT_VISIBILITY extern ValueProfNode *EndVNode;
194194
extern void (*VPMergeHook)(struct ValueProfData *, __llvm_profile_data *);
195195

196-
/*
197-
* Write binary ids into profiles if writer is given.
198-
* Return -1 if an error occurs, otherwise, return total size of binary ids.
199-
*/
200-
int __llvm_write_binary_ids(ProfDataWriter *Writer);
201-
202196
#endif

compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// with freestanding compilation. See `darwin_add_builtin_libraries`.
1111

1212
#include "InstrProfiling.h"
13-
#include "InstrProfilingInternal.h"
1413

1514
#if defined(__APPLE__)
1615
/* Use linker magic to find the bounds of the Data section. */
@@ -68,9 +67,4 @@ ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
6867

6968
COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &VNodesStart;
7069
COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &VNodesEnd;
71-
72-
COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
73-
return 0;
74-
}
75-
7670
#endif

compiler-rt/lib/profile/InstrProfilingPlatformLinux.c

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
#if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
1010
(defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__)
1111

12-
#include <elf.h>
13-
#include <link.h>
1412
#include <stdlib.h>
15-
#include <string.h>
1613

1714
#include "InstrProfiling.h"
18-
#include "InstrProfilingInternal.h"
1915

2016
#define PROF_DATA_START INSTR_PROF_SECT_START(INSTR_PROF_DATA_COMMON)
2117
#define PROF_DATA_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_DATA_COMMON)
@@ -76,108 +72,4 @@ COMPILER_RT_VISIBILITY ValueProfNode *__llvm_profile_end_vnodes(void) {
7672
COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &PROF_VNODES_START;
7773
COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &PROF_VNODES_STOP;
7874

79-
static size_t RoundUp(size_t size, size_t align) {
80-
return (size + align - 1) & ~(align - 1);
81-
}
82-
83-
/*
84-
* Write binary id length and then its data, because binary id does not
85-
* have a fixed length.
86-
*/
87-
int WriteOneBinaryId(ProfDataWriter *Writer, uint64_t BinaryIdLen,
88-
const uint8_t *BinaryIdData) {
89-
ProfDataIOVec BinaryIdIOVec[] = {
90-
{&BinaryIdLen, sizeof(uint64_t), 1, 0},
91-
{BinaryIdData, sizeof(uint8_t), BinaryIdLen, 0}};
92-
if (Writer->Write(Writer, BinaryIdIOVec,
93-
sizeof(BinaryIdIOVec) / sizeof(*BinaryIdIOVec)))
94-
return -1;
95-
96-
/* Successfully wrote binary id, report success. */
97-
return 0;
98-
}
99-
100-
/*
101-
* Look for the note that has the name "GNU\0" and type NT_GNU_BUILD_ID
102-
* that contains build id. If build id exists, write binary id.
103-
*
104-
* Each note in notes section starts with a struct which includes
105-
* n_namesz, n_descsz, and n_type members. It is followed by the name
106-
* (whose length is defined in n_namesz) and then by the descriptor
107-
* (whose length is defined in n_descsz).
108-
*
109-
* Note sections like .note.ABI-tag and .note.gnu.build-id are aligned
110-
* to 4 bytes, so round n_namesz and n_descsz to the nearest 4 bytes.
111-
*/
112-
int WriteBinaryIdForNote(ProfDataWriter *Writer, const ElfW(Nhdr) * Note) {
113-
int BinaryIdSize = 0;
114-
115-
const char *NoteName = (const char *)Note + sizeof(ElfW(Nhdr));
116-
if (Note->n_type == NT_GNU_BUILD_ID && Note->n_namesz == 4 &&
117-
memcmp(NoteName, "GNU\0", 4) == 0) {
118-
119-
uint64_t BinaryIdLen = Note->n_descsz;
120-
const uint8_t *BinaryIdData =
121-
(const uint8_t *)(NoteName + RoundUp(Note->n_namesz, 4));
122-
if (Writer != NULL &&
123-
WriteOneBinaryId(Writer, BinaryIdLen, BinaryIdData) == -1)
124-
return -1;
125-
126-
BinaryIdSize = sizeof(BinaryIdLen) + BinaryIdLen;
127-
}
128-
129-
return BinaryIdSize;
130-
}
131-
132-
/*
133-
* Helper function that iterates through notes section and find build ids.
134-
* If writer is given, write binary ids into profiles.
135-
* If an error happens while writing, return -1.
136-
*/
137-
int WriteBinaryIds(ProfDataWriter *Writer, const ElfW(Nhdr) * Note,
138-
const ElfW(Nhdr) * NotesEnd) {
139-
int TotalBinaryIdsSize = 0;
140-
while (Note < NotesEnd) {
141-
int Result = WriteBinaryIdForNote(Writer, Note);
142-
if (Result == -1)
143-
return -1;
144-
TotalBinaryIdsSize += Result;
145-
146-
/* Calculate the offset of the next note in notes section. */
147-
size_t NoteOffset = sizeof(ElfW(Nhdr)) + RoundUp(Note->n_namesz, 4) +
148-
RoundUp(Note->n_descsz, 4);
149-
Note = (const ElfW(Nhdr) *)((const char *)(Note) + NoteOffset);
150-
}
151-
152-
return TotalBinaryIdsSize;
153-
}
154-
155-
/*
156-
* Write binary ids into profiles if writer is given.
157-
* Return the total size of binary ids.
158-
* If an error happens while writing, return -1.
159-
*/
160-
COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
161-
extern const ElfW(Ehdr) __ehdr_start __attribute__((visibility("hidden")));
162-
const ElfW(Ehdr) *ElfHeader = &__ehdr_start;
163-
const ElfW(Phdr) *ProgramHeader =
164-
(const ElfW(Phdr) *)((uintptr_t)ElfHeader + ElfHeader->e_phoff);
165-
166-
uint32_t I;
167-
/* Iterate through entries in the program header. */
168-
for (I = 0; I < ElfHeader->e_phnum; I++) {
169-
/* Look for the notes section in program header entries. */
170-
if (ProgramHeader[I].p_type != PT_NOTE)
171-
continue;
172-
173-
const ElfW(Nhdr) *Note =
174-
(const ElfW(Nhdr) *)((uintptr_t)ElfHeader + ProgramHeader[I].p_offset);
175-
const ElfW(Nhdr) *NotesEnd =
176-
(const ElfW(Nhdr) *)((const char *)(Note) + ProgramHeader[I].p_filesz);
177-
return WriteBinaryIds(Writer, Note, NotesEnd);
178-
}
179-
180-
return 0;
181-
}
182-
18375
#endif

compiler-rt/lib/profile/InstrProfilingPlatformOther.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <stdio.h>
1515

1616
#include "InstrProfiling.h"
17-
#include "InstrProfilingInternal.h"
1817

1918
static const __llvm_profile_data *DataFirst = NULL;
2019
static const __llvm_profile_data *DataLast = NULL;
@@ -98,8 +97,4 @@ ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
9897
COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
9998
COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
10099

101-
COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
102-
return 0;
103-
}
104-
105100
#endif

compiler-rt/lib/profile/InstrProfilingPlatformWindows.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
\*===----------------------------------------------------------------------===*/
88

99
#include "InstrProfiling.h"
10-
#include "InstrProfilingInternal.h"
1110

1211
#if defined(_WIN32)
1312

@@ -66,8 +65,4 @@ ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
6665
ValueProfNode *CurrentVNode = &VNodesStart + 1;
6766
ValueProfNode *EndVNode = &VNodesEnd;
6867

69-
COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
70-
return 0;
71-
}
72-
7368
#endif

compiler-rt/lib/profile/InstrProfilingWriter.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,16 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
283283
#define INSTR_PROF_RAW_HEADER(Type, Name, Init) Header.Name = Init;
284284
#include "profile/InstrProfData.inc"
285285

286-
/* Write the profile header. */
287-
ProfDataIOVec IOVec[] = {{&Header, sizeof(__llvm_profile_header), 1, 0}};
288-
if (Writer->Write(Writer, IOVec, sizeof(IOVec) / sizeof(*IOVec)))
289-
return -1;
290-
291-
/* Write the binary id lengths and data. */
292-
if (__llvm_write_binary_ids(Writer) == -1)
293-
return -1;
294-
295-
/* Write the profile data. */
296-
ProfDataIOVec IOVecData[] = {
286+
/* Write the data. */
287+
ProfDataIOVec IOVec[] = {
288+
{&Header, sizeof(__llvm_profile_header), 1, 0},
297289
{DataBegin, sizeof(__llvm_profile_data), DataSize, 0},
298290
{NULL, sizeof(uint8_t), PaddingBytesBeforeCounters, 1},
299291
{CountersBegin, sizeof(uint64_t), CountersSize, 0},
300292
{NULL, sizeof(uint8_t), PaddingBytesAfterCounters, 1},
301293
{SkipNameDataWrite ? NULL : NamesBegin, sizeof(uint8_t), NamesSize, 0},
302294
{NULL, sizeof(uint8_t), PaddingBytesAfterNames, 1}};
303-
if (Writer->Write(Writer, IOVecData, sizeof(IOVecData) / sizeof(*IOVecData)))
295+
if (Writer->Write(Writer, IOVec, sizeof(IOVec) / sizeof(*IOVec)))
304296
return -1;
305297

306298
/* Value profiling is not yet supported in continuous mode. */

compiler-rt/test/profile/Linux/binary-id.c

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

compiler-rt/test/profile/Linux/corrupted-profile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ int main(int argc, char** argv) {
4343
bail("mmap");
4444

4545
// We're trying to make the first CounterPtr invalid.
46-
// 11 64-bit words as header.
46+
// 10 64-bit words as header.
4747
// CounterPtr is the third 64-bit word field.
48-
memset(&Buf[11 * 8 + 2 * 8], 0xAB, 8);
48+
memset(&Buf[10 * 8 + 2 * 8], 0xAB, 8);
4949

5050
if (munmap(Buf, FileSize))
5151
bail("munmap");

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,6 @@ namespace RawInstrProf {
11031103
// raw header.
11041104
// Version 5: Bit 60 of FuncHash is reserved for the flag for the context
11051105
// sensitive records.
1106-
// Version 6: Added binary id.
11071106
const uint64_t Version = INSTR_PROF_RAW_VERSION;
11081107

11091108
template <class IntPtrT> inline uint64_t getMagic();

llvm/include/llvm/ProfileData/InstrProfData.inc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize)
137137
INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, (uintptr_t)CountersBegin)
138138
INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
139139
INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
140-
INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
141140
#undef INSTR_PROF_RAW_HEADER
142141
/* INSTR_PROF_RAW_HEADER end */
143142

@@ -646,7 +645,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
646645
(uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
647646

648647
/* Raw profile format version (start from 1). */
649-
#define INSTR_PROF_RAW_VERSION 6
648+
#define INSTR_PROF_RAW_VERSION 5
650649
/* Indexed profile format version (start from 1). */
651650
#define INSTR_PROF_INDEX_VERSION 7
652651
/* Coverage mapping format version (start from 0). */

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ class InstrProfReader {
8282
/// Read a single record.
8383
virtual Error readNextRecord(NamedInstrProfRecord &Record) = 0;
8484

85-
/// Print binary ids on stream OS.
86-
virtual Error printBinaryIds(raw_ostream &OS) { return success(); };
87-
8885
/// Iterator over profile data.
8986
InstrProfIterator begin() { return InstrProfIterator(this); }
9087
InstrProfIterator end() { return InstrProfIterator(); }
@@ -225,9 +222,6 @@ class RawInstrProfReader : public InstrProfReader {
225222
uint32_t ValueKindLast;
226223
uint32_t CurValueDataSize;
227224

228-
uint64_t BinaryIdsSize;
229-
const uint8_t *BinaryIdsStart;
230-
231225
public:
232226
RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
233227
: DataBuffer(std::move(DataBuffer)) {}
@@ -237,7 +231,6 @@ class RawInstrProfReader : public InstrProfReader {
237231
static bool hasFormat(const MemoryBuffer &DataBuffer);
238232
Error readHeader() override;
239233
Error readNextRecord(NamedInstrProfRecord &Record) override;
240-
Error printBinaryIds(raw_ostream &OS) override;
241234

242235
bool isIRLevelProfile() const override {
243236
return (Version & VARIANT_MASK_IR_PROF) != 0;

0 commit comments

Comments
 (0)