[compiler-rt] 896f797 - [profile] Remove dependence on getpagesize from InstrProfilingBuffer.c.o
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 16:22:48 PDT 2020
Author: Vedant Kumar
Date: 2020-07-30T16:22:40-07:00
New Revision: 896f797b8bb7683f7e52c6dc94979f3c449bc37d
URL: https://github.com/llvm/llvm-project/commit/896f797b8bb7683f7e52c6dc94979f3c449bc37d
DIFF: https://github.com/llvm/llvm-project/commit/896f797b8bb7683f7e52c6dc94979f3c449bc37d.diff
LOG: [profile] Remove dependence on getpagesize from InstrProfilingBuffer.c.o
InstrProfilingBuffer.c.o is generic code that must support compilation
into freestanding projects. This gets rid of its dependence on the
_getpagesize symbol from libc, shifting it to InstrProfilingFile.c.o.
This fixes a build failure seen in a firmware project.
rdar://66249701
Added:
Modified:
compiler-rt/lib/profile/InstrProfiling.h
compiler-rt/lib/profile/InstrProfilingBuffer.c
compiler-rt/lib/profile/InstrProfilingFile.c
compiler-rt/test/profile/instrprof-without-libc.c
Removed:
################################################################################
diff --git a/compiler-rt/lib/profile/InstrProfiling.h b/compiler-rt/lib/profile/InstrProfiling.h
index d7a7c32332c1..7d1c77a3fab3 100644
--- a/compiler-rt/lib/profile/InstrProfiling.h
+++ b/compiler-rt/lib/profile/InstrProfiling.h
@@ -54,6 +54,15 @@ int __llvm_profile_is_continuous_mode_enabled(void);
*/
void __llvm_profile_enable_continuous_mode(void);
+/*!
+ * \brief Set the page size.
+ *
+ * This is a pre-requisite for enabling continuous mode. The buffer size
+ * calculation code inside of libprofile cannot simply call getpagesize(), as
+ * it is not allowed to depend on libc.
+ */
+void __llvm_profile_set_page_size(unsigned PageSize);
+
/*!
* \brief Get number of bytes necessary to pad the argument to eight
* byte boundary.
diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c
index 800ae22f2746..07bb4d4e4f1b 100644
--- a/compiler-rt/lib/profile/InstrProfilingBuffer.c
+++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c
@@ -21,14 +21,22 @@
* layering is violated. */
static int ContinuouslySyncProfile = 0;
+/* The system page size. Only valid when non-zero. If 0, the page size is
+ * unavailable. */
+static unsigned PageSize = 0;
+
COMPILER_RT_VISIBILITY int __llvm_profile_is_continuous_mode_enabled(void) {
- return ContinuouslySyncProfile;
+ return ContinuouslySyncProfile && PageSize;
}
COMPILER_RT_VISIBILITY void __llvm_profile_enable_continuous_mode(void) {
ContinuouslySyncProfile = 1;
}
+COMPILER_RT_VISIBILITY void __llvm_profile_set_page_size(unsigned PS) {
+ PageSize = PS;
+}
+
COMPILER_RT_VISIBILITY
uint64_t __llvm_profile_get_size_for_buffer(void) {
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
@@ -52,8 +60,7 @@ uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
/// Calculate the number of padding bytes needed to add to \p Offset in order
/// for (\p Offset + Padding) to be page-aligned.
-static uint64_t calculateBytesNeededToPageAlign(uint64_t Offset,
- unsigned PageSize) {
+static uint64_t calculateBytesNeededToPageAlign(uint64_t Offset) {
uint64_t OffsetModPage = Offset % PageSize;
if (OffsetModPage > 0)
return PageSize - OffsetModPage;
@@ -75,15 +82,13 @@ void __llvm_profile_get_padding_sizes_for_counters(
// In continuous mode, the file offsets for headers and for the start of
// counter sections need to be page-aligned.
- unsigned PageSize = getpagesize();
uint64_t DataSizeInBytes = DataSize * sizeof(__llvm_profile_data);
uint64_t CountersSizeInBytes = CountersSize * sizeof(uint64_t);
*PaddingBytesBeforeCounters = calculateBytesNeededToPageAlign(
- sizeof(__llvm_profile_header) + DataSizeInBytes, PageSize);
+ sizeof(__llvm_profile_header) + DataSizeInBytes);
*PaddingBytesAfterCounters =
- calculateBytesNeededToPageAlign(CountersSizeInBytes, PageSize);
- *PaddingBytesAfterNames =
- calculateBytesNeededToPageAlign(NamesSize, PageSize);
+ calculateBytesNeededToPageAlign(CountersSizeInBytes);
+ *PaddingBytesAfterNames = calculateBytesNeededToPageAlign(NamesSize);
}
COMPILER_RT_VISIBILITY
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 9e1a54a0c373..8c7bb0c25de1 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -751,6 +751,7 @@ static int parseFilenamePattern(const char *FilenamePat,
return -1;
}
+ __llvm_profile_set_page_size(getpagesize());
__llvm_profile_enable_continuous_mode();
I++; /* advance to 'c' */
} else {
diff --git a/compiler-rt/test/profile/instrprof-without-libc.c b/compiler-rt/test/profile/instrprof-without-libc.c
index 6e9c1dde01e6..cd9fb5e1dd8e 100644
--- a/compiler-rt/test/profile/instrprof-without-libc.c
+++ b/compiler-rt/test/profile/instrprof-without-libc.c
@@ -72,3 +72,4 @@ int main(int argc, const char *argv[]) {
// CHECK-SYMBOLS-NOT: {{ }}_free
// CHECK-SYMBOLS-NOT: {{ }}free
// CHECK-SYMBOLS-NOT: {{ }}_open
+// CHECK-SYMBOLS-NOT: {{ }}_getpagesize
More information about the llvm-commits
mailing list