[compiler-rt] [Profile] Dump binary id to raw profiles on Windows. (PR #75618)

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 19 11:50:38 PST 2023


================
@@ -74,7 +74,14 @@ ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
 ValueProfNode *CurrentVNode = &VNodesStart + 1;
 ValueProfNode *EndVNode = &VNodesEnd;
 
+uint64_t BuildIdLen = 16;
+COMPILER_RT_WEAK extern uint8_t __buildid[16];
 COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
+  if (*__buildid) {
----------------
petrhosek wrote:

Not if it's an `extern` declaration, in that case it'll be just a pointer which may be `NULL` since the symbol is weak. Try the following example:
```c
#include <stdint.h>
__attribute__((weak)) extern uint8_t buildid[16];
int main() {
  if (*buildid)
    return 0;
  return 1;
}
```
```sh
$ clang a.c -o a.out
$ ./a.out
segmentation fault  ./a.out
```

https://github.com/llvm/llvm-project/pull/75618


More information about the llvm-commits mailing list