Pinpoint plugin CU UID calculation
This commit is contained in:
parent
6f95a9cd0b
commit
d3094ce698
@ -4,18 +4,40 @@
|
||||
#include <stage1.h>
|
||||
|
||||
#include <safe-input.h>
|
||||
#include <safe-md5.h>
|
||||
#include <pinpoint_config.h>
|
||||
#include <pinpoint_error.h>
|
||||
|
||||
unsigned char cu_uid_md5[16];
|
||||
char cu_uid_hex[33];
|
||||
|
||||
static const unsigned char* calculate_cu_uid_md5() {
|
||||
if (!main_input_filename)
|
||||
return nullptr;
|
||||
|
||||
md5_buffer(main_input_filename, strlen(main_input_filename), cu_uid_md5);
|
||||
return cu_uid_md5;
|
||||
}
|
||||
|
||||
static const char* calculate_cu_uid_hex() {
|
||||
const unsigned char* digest = calculate_cu_uid_md5();
|
||||
if (!digest)
|
||||
return nullptr;
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
sprintf(cu_uid_hex + 2*i, "%02x", digest[i]);
|
||||
|
||||
cu_uid_hex[32] = '\0';
|
||||
return cu_uid_hex;
|
||||
}
|
||||
|
||||
void on_finish_unit(void* plugin_data, void* user_data) {
|
||||
/*
|
||||
TODO
|
||||
The result lbasename(...) is not unique (e.g., "file.c" and "sub/file.c")
|
||||
Calculate UID for compilation unit -> hash(main_input_filename)
|
||||
Add UID symbol to CU -> __spslr_cu_<uid>
|
||||
Then dump accumulated data for finalizer
|
||||
*/
|
||||
const char* cu_uid = calculate_cu_uid_hex();
|
||||
if (!cu_uid)
|
||||
pinpoint_fatal("on_finish_unit failed to calculate compilation unit UID");
|
||||
|
||||
std::cout << "Finishing unit \"" << lbasename(main_input_filename) << "\" ..." << std::endl;
|
||||
std::cout << " Unit UID is 0x" << cu_uid << std::endl;
|
||||
|
||||
for (const auto& [uid, target] : TargetType::all())
|
||||
std::cout << " Target " << uid << " -> \"" << target.name() << "\" (" << target.size() << ")" << std::endl;
|
||||
|
||||
8
pinpoint/safegcc/safe-md5.h
Normal file
8
pinpoint/safegcc/safe-md5.h
Normal file
@ -0,0 +1,8 @@
|
||||
#include <safe-gcc-plugin.h>
|
||||
|
||||
#ifndef SAFEGCC_MD5_H
|
||||
#define SAFEGCC_MD5_H
|
||||
|
||||
#include <md5.h>
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user