Revert r362676 "[Profile]: Add runtime interface to specify file handle for profile data."
This caused instrumented Clang to become crashy. See llvm-commits thread
for repro steps.
This also reverts follow-up r362716 which added test cases.
> Author: Sajjad Mirza
>
> Differential Revision: http://reviews.llvm.org/D62541
llvm-svn: 363134
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 3a566a7..8c32bde 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -37,7 +37,7 @@
/* From where is profile name specified.
* The order the enumerators define their
* precedence. Re-order them may lead to
- * runtime behavior change. */
+ * runtime behavior change. */
typedef enum ProfileNameSpecifier {
PNS_unknown = 0,
PNS_default,
@@ -89,27 +89,9 @@
COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0, 0, 0, 0, {0},
{0}, 0, 0, 0, PNS_unknown};
-static int ProfileMergeRequested = 0;
-static int isProfileMergeRequested() { return ProfileMergeRequested; }
-static void setProfileMergeRequested(int EnableMerge) {
- ProfileMergeRequested = EnableMerge;
-}
-
-static FILE *ProfileFile = NULL;
-static FILE *getProfileFile() { return ProfileFile; }
-static void setProfileFile(FILE *File) { ProfileFile = File; }
-
-COMPILER_RT_VISIBILITY void __llvm_profile_set_file_object(FILE *File,
- int EnableMerge) {
- setProfileFile(File);
- setProfileMergeRequested(EnableMerge);
-}
-
static int getCurFilenameLength();
static const char *getCurFilename(char *FilenameBuf, int ForceUseBuf);
-static unsigned doMerging() {
- return lprofCurFilename.MergePoolSize || isProfileMergeRequested();
-}
+static unsigned doMerging() { return lprofCurFilename.MergePoolSize; }
/* Return 1 if there is an error, otherwise return 0. */
static uint32_t fileWriter(ProfDataWriter *This, ProfDataIOVec *IOVecs,
@@ -243,16 +225,11 @@
* its instrumented shared libraries dump profile data into their own data file.
*/
static FILE *openFileForMerging(const char *ProfileFileName, int *MergeDone) {
- FILE *ProfileFile = NULL;
+ FILE *ProfileFile;
int rc;
- ProfileFile = getProfileFile();
- if (ProfileFile) {
- lprofLockFileHandle(ProfileFile);
- } else {
- createProfileDir(ProfileFileName);
- ProfileFile = lprofOpenFileEx(ProfileFileName);
- }
+ createProfileDir(ProfileFileName);
+ ProfileFile = lprofOpenFileEx(ProfileFileName);
if (!ProfileFile)
return NULL;
@@ -267,16 +244,6 @@
return ProfileFile;
}
-static FILE *GetFileObject(const char *OutputName) {
- FILE *File;
- File = getProfileFile();
- if (File != NULL) {
- return File;
- }
-
- return fopen(OutputName, "ab");
-}
-
/* Write profile data to file \c OutputName. */
static int writeFile(const char *OutputName) {
int RetVal;
@@ -284,10 +251,10 @@
int MergeDone = 0;
VPMergeHook = &lprofMergeValueProfData;
- if (doMerging())
- OutputFile = openFileForMerging(OutputName, &MergeDone);
+ if (!doMerging())
+ OutputFile = fopen(OutputName, "ab");
else
- OutputFile = GetFileObject(OutputName);
+ OutputFile = openFileForMerging(OutputName, &MergeDone);
if (!OutputFile)
return -1;
@@ -298,15 +265,7 @@
initFileWriter(&fileWriter, OutputFile);
RetVal = lprofWriteData(&fileWriter, lprofGetVPDataReader(), MergeDone);
- if (doMerging()) {
- lprofUnlockFileHandle(OutputFile);
- }
-
- if (OutputFile == getProfileFile())
- fflush(OutputFile);
- else
- fclose(OutputFile);
-
+ fclose(OutputFile);
return RetVal;
}
@@ -632,7 +591,7 @@
EnvFilenamePat = getFilenamePatFromEnv();
if (EnvFilenamePat) {
- /* Pass CopyFilenamePat = 1, to ensure that the filename would be valid
+ /* Pass CopyFilenamePat = 1, to ensure that the filename would be valid
at the moment when __llvm_profile_write_file() gets executed. */
parseAndSetFilename(EnvFilenamePat, PNS_environment, 1);
return;
@@ -668,7 +627,8 @@
int PDeathSig = 0;
if (lprofProfileDumped()) {
- PROF_NOTE("Profile data not written to file: %s.\n", "already written");
+ PROF_NOTE("Profile data not written to file: %s.\n",
+ "already written");
return 0;
}