1 // Set these requirements to ensure that we have an 8-byte binary ID.
4 // This will generate a 20-byte build ID, which requires 4-byte padding.
5 // RUN: %clang_profgen -Wl,--build-id=sha1 -o %t %s
6 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
7 // RUN: %run %t %t.profraw
21 #define VALUE_PROF_KIND(Enumerator, Value, Descr) Enumerator = Value,
22 #include "profile/InstrProfData.inc"
25 typedef struct __llvm_profile_header
{
26 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name;
27 #include "profile/InstrProfData.inc"
28 } __llvm_profile_header
;
30 typedef void *IntPtrT
;
31 typedef struct __llvm_profile_data
{
32 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
33 #include "profile/InstrProfData.inc"
34 } __llvm_profile_data
;
36 void bail(const char* str
) {
37 fprintf(stderr
, "%s %s\n", str
, strerror(errno
));
43 int main(int argc
, char** argv
) {
45 int fd
= open(argv
[1], O_RDONLY
);
50 if (stat(argv
[1], &st
))
52 uint64_t FileSize
= st
.st_size
;
54 char* Buf
= (char *)mmap(NULL
, FileSize
, PROT_READ
, MAP_SHARED
, fd
, 0);
55 if (Buf
== MAP_FAILED
)
58 __llvm_profile_header
*Header
= (__llvm_profile_header
*)Buf
;
59 if (Header
->BinaryIdsSize
!= 32)
60 bail("Invalid binary ID size");
62 char *BinaryIdsStart
= Buf
+ sizeof(__llvm_profile_header
);
64 uint64_t BinaryIdSize
= *((uint64_t *)BinaryIdsStart
);
65 if (BinaryIdSize
!= 20)
66 bail("Expected a binary ID of size 20");
68 // Skip the size and the binary ID itself to check padding.
69 BinaryIdsStart
+= 8 + 20;
70 if (*((uint32_t *)BinaryIdsStart
))
71 bail("Found non-zero binary ID padding");
73 if (munmap(Buf
, FileSize
))