summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/profile/InstrProfilingBuffer.c
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-05-16 01:30:24 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-05-16 01:30:24 +0000
commit084398857a76bce3c03381438ba545e3c4aa412f (patch)
treefac9227764901dad739ecf25a50672f69cf77fc3 /compiler-rt/lib/profile/InstrProfilingBuffer.c
parent912122080412e7d91ba5c7e3d3259803f8e776b3 (diff)
downloadbcm5719-llvm-084398857a76bce3c03381438ba545e3c4aa412f.tar.gz
bcm5719-llvm-084398857a76bce3c03381438ba545e3c4aa412f.zip
InstrProf: Fix shared object profiling
Change the API of the instrumented profiling library to work with shared objects. - Most things are now declared hidden, so that each executable gets its own copy. - Initialization hooks up a linked list of writers. - The raw format with shared objects that are profiled consists of a concatenated series of profiles. llvm-profdata knows how to deal with that since r208938. <rdar://problem/16918688> llvm-svn: 208940
Diffstat (limited to 'compiler-rt/lib/profile/InstrProfilingBuffer.c')
-rw-r--r--compiler-rt/lib/profile/InstrProfilingBuffer.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c
index 8c6d43e7b45..b53d4f7954b 100644
--- a/compiler-rt/lib/profile/InstrProfilingBuffer.c
+++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c
@@ -10,14 +10,18 @@
#include "InstrProfiling.h"
#include <string.h>
+__attribute__((visibility("hidden")))
uint64_t __llvm_profile_get_size_for_buffer(void) {
/* Match logic in __llvm_profile_write_buffer(). */
+ 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) +
- PROFILE_RANGE_SIZE(names) * sizeof(char);
+ NamesSize + Padding;
}
+__attribute__((visibility("hidden")))
int __llvm_profile_write_buffer(char *Buffer) {
/* Match logic in __llvm_profile_get_size_for_buffer().
* Match logic in __llvm_profile_write_file().
@@ -33,6 +37,10 @@ int __llvm_profile_write_buffer(char *Buffer) {
const uint64_t DataSize = DataEnd - DataBegin;
const uint64_t CountersSize = CountersEnd - CountersBegin;
const uint64_t NamesSize = NamesEnd - NamesBegin;
+ const uint64_t Padding = sizeof(uint64_t) - NamesSize % sizeof(uint64_t);
+
+ /* Enough zeroes for padding. */
+ const char Zeroes[sizeof(uint64_t)] = {0};
/* Create the header. */
uint64_t Header[PROFILE_HEADER_SIZE];
@@ -54,6 +62,7 @@ int __llvm_profile_write_buffer(char *Buffer) {
UPDATE_memcpy(DataBegin, DataSize * sizeof(__llvm_profile_data));
UPDATE_memcpy(CountersBegin, CountersSize * sizeof(uint64_t));
UPDATE_memcpy(NamesBegin, NamesSize * sizeof(char));
+ UPDATE_memcpy(Zeroes, Padding * sizeof(char));
#undef UPDATE_memcpy
return 0;
OpenPOWER on IntegriCloud