[compiler-rt] ff42790 - [NFC][profile] Move writeMMappedFile to ELF ifdef block

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 19 23:13:21 PDT 2021


Author: Petr Hosek
Date: 2021-07-19T23:13:13-07:00
New Revision: ff427909caa6f1ec8392800087a90cc6a0664153

URL: https://github.com/llvm/llvm-project/commit/ff427909caa6f1ec8392800087a90cc6a0664153
DIFF: https://github.com/llvm/llvm-project/commit/ff427909caa6f1ec8392800087a90cc6a0664153.diff

LOG: [NFC][profile] Move writeMMappedFile to ELF ifdef block

This avoids the compiler warning on Darwin where that function is unused.

Added: 
    

Modified: 
    compiler-rt/lib/profile/InstrProfilingFile.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 88adb86bddbc9..518447e3e422a 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -426,34 +426,6 @@ static void truncateCurrentFile(void) {
   fclose(File);
 }
 
-static int writeMMappedFile(FILE *OutputFile, char **Profile) {
-  if (!OutputFile)
-    return -1;
-
-  /* Write the data into a file. */
-  setupIOBuffer();
-  ProfDataWriter fileWriter;
-  initFileWriter(&fileWriter, OutputFile);
-  if (lprofWriteData(&fileWriter, NULL, 0)) {
-    PROF_ERR("Failed to write profile: %s\n", strerror(errno));
-    return -1;
-  }
-  fflush(OutputFile);
-
-  /* Get the file size. */
-  uint64_t FileSize = ftell(OutputFile);
-
-  /* Map the profile. */
-  *Profile = (char *)mmap(
-      NULL, FileSize, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(OutputFile), 0);
-  if (*Profile == MAP_FAILED) {
-    PROF_ERR("Unable to mmap profile: %s\n", strerror(errno));
-    return -1;
-  }
-
-  return 0;
-}
-
 // TODO: Move these functions into InstrProfilingPlatform* files.
 #if defined(__APPLE__)
 static void assertIsZero(int *i) {
@@ -631,6 +603,34 @@ COMPILER_RT_VISIBILITY extern intptr_t INSTR_PROF_PROFILE_COUNTER_BIAS_VAR
                              INSTR_PROF_PROFILE_COUNTER_BIAS_DEFAULT_VAR))));
 #endif
 
+static int writeMMappedFile(FILE *OutputFile, char **Profile) {
+  if (!OutputFile)
+    return -1;
+
+  /* Write the data into a file. */
+  setupIOBuffer();
+  ProfDataWriter fileWriter;
+  initFileWriter(&fileWriter, OutputFile);
+  if (lprofWriteData(&fileWriter, NULL, 0)) {
+    PROF_ERR("Failed to write profile: %s\n", strerror(errno));
+    return -1;
+  }
+  fflush(OutputFile);
+
+  /* Get the file size. */
+  uint64_t FileSize = ftell(OutputFile);
+
+  /* Map the profile. */
+  *Profile = (char *)mmap(
+      NULL, FileSize, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(OutputFile), 0);
+  if (*Profile == MAP_FAILED) {
+    PROF_ERR("Unable to mmap profile: %s\n", strerror(errno));
+    return -1;
+  }
+
+  return 0;
+}
+
 static void initializeProfileForContinuousMode(void) {
   if (!__llvm_profile_is_continuous_mode_enabled())
     return;


        


More information about the llvm-commits mailing list