diff options
| author | Justin Bogner <mail@justinbogner.com> | 2014-12-09 22:07:25 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2014-12-09 22:07:25 +0000 |
| commit | 55248db0c98a5af6df9ee4413fd06dac07553a27 (patch) | |
| tree | 90577547364f18bf42ebe45a9ef81aaab5aeee81 /compiler-rt/lib/profile/InstrProfilingBuffer.c | |
| parent | 7f138811cd27f5835e7781d3f1cf0797b26af9b9 (diff) | |
| download | bcm5719-llvm-55248db0c98a5af6df9ee4413fd06dac07553a27.tar.gz bcm5719-llvm-55248db0c98a5af6df9ee4413fd06dac07553a27.zip | |
profile: Add low level versions of profile buffer functions
On Darwin, compiler_rt uses magic linker symbols to find the profile
counters in the __DATA segment. This is a reasonable method for
normal, hosted, userspace programs. However programs with custom
memory layouts, such as the kernel, will need to tell compiler_rt
explicitly where to find these sections.
Patch by Lawrence D'Anna. Thanks!
llvm-svn: 223840
Diffstat (limited to 'compiler-rt/lib/profile/InstrProfilingBuffer.c')
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingBuffer.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c index 3351b07ba6f..3c429c8a85e 100644 --- a/compiler-rt/lib/profile/InstrProfilingBuffer.c +++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c @@ -8,17 +8,38 @@ \*===----------------------------------------------------------------------===*/ #include "InstrProfiling.h" +#include "InstrProfilingInternal.h" + #include <string.h> __attribute__((visibility("hidden"))) uint64_t __llvm_profile_get_size_for_buffer(void) { + const __llvm_profile_data *DataBegin = __llvm_profile_begin_data(); + const __llvm_profile_data *DataEnd = __llvm_profile_end_data(); + const uint64_t *CountersBegin = __llvm_profile_begin_counters(); + const uint64_t *CountersEnd = __llvm_profile_end_counters(); + const char *NamesBegin = __llvm_profile_begin_names(); + const char *NamesEnd = __llvm_profile_end_names(); + + return __llvm_profile_get_size_for_buffer_internal( + DataBegin, DataEnd, CountersBegin, CountersEnd, NamesBegin, NamesEnd); +} + +#define PROFILE_RANGE_SIZE(Range) (Range##End - Range##Begin) + +__attribute__((visibility("hidden"))) +uint64_t __llvm_profile_get_size_for_buffer_internal( + const __llvm_profile_data *DataBegin, + const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, + const uint64_t *CountersEnd, const char *NamesBegin, + const char *NamesEnd) { /* Match logic in __llvm_profile_write_buffer(). */ - const uint64_t NamesSize = PROFILE_RANGE_SIZE(names) * sizeof(char); + const uint64_t NamesSize = PROFILE_RANGE_SIZE(Names) * sizeof(char); const uint64_t Padding = sizeof(uint64_t) - NamesSize % sizeof(uint64_t); return sizeof(uint64_t) * PROFILE_HEADER_SIZE + - PROFILE_RANGE_SIZE(data) * sizeof(__llvm_profile_data) + - PROFILE_RANGE_SIZE(counters) * sizeof(uint64_t) + - NamesSize + Padding; + PROFILE_RANGE_SIZE(Data) * sizeof(__llvm_profile_data) + + PROFILE_RANGE_SIZE(Counters) * sizeof(uint64_t) + + NamesSize + Padding; } __attribute__((visibility("hidden"))) @@ -33,6 +54,20 @@ int __llvm_profile_write_buffer(char *Buffer) { const char *NamesBegin = __llvm_profile_begin_names(); const char *NamesEnd = __llvm_profile_end_names(); + return __llvm_profile_write_buffer_internal(Buffer, DataBegin, DataEnd, + CountersBegin, CountersEnd, + NamesBegin, NamesEnd); +} + +__attribute__((visibility("hidden"))) +int __llvm_profile_write_buffer_internal( + char *Buffer, const __llvm_profile_data *DataBegin, + const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, + const uint64_t *CountersEnd, const char *NamesBegin, const char *NamesEnd) { + /* Match logic in __llvm_profile_get_size_for_buffer(). + * Match logic in __llvm_profile_write_file(). + */ + /* Calculate size of sections. */ const uint64_t DataSize = DataEnd - DataBegin; const uint64_t CountersSize = CountersEnd - CountersBegin; |

