InstrProfilingPlatformWindows.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*===- InstrProfilingPlatformWindows.c - Profile data on Windows ----------===*\
  2. |*
  3. |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. |* See https://llvm.org/LICENSE.txt for license information.
  5. |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. |*
  7. \*===----------------------------------------------------------------------===*/
  8. #include "InstrProfiling.h"
  9. #include "InstrProfilingInternal.h"
  10. #if defined(_WIN32)
  11. #if defined(_MSC_VER)
  12. /* Merge read-write sections into .data. */
  13. #pragma comment(linker, "/MERGE:.lprfb=.data")
  14. #pragma comment(linker, "/MERGE:.lprfd=.data")
  15. #pragma comment(linker, "/MERGE:.lprfv=.data")
  16. #pragma comment(linker, "/MERGE:.lprfnd=.data")
  17. /* Do *NOT* merge .lprfn and .lcovmap into .rdata. llvm-cov must be able to find
  18. * after the fact.
  19. * Do *NOT* merge .lprfc .rdata. When binary profile correlation is enabled,
  20. * llvm-cov must be able to find after the fact.
  21. */
  22. /* Allocate read-only section bounds. */
  23. #pragma section(".lprfn$A", read)
  24. #pragma section(".lprfn$Z", read)
  25. /* Allocate read-write section bounds. */
  26. #pragma section(".lprfd$A", read, write)
  27. #pragma section(".lprfd$Z", read, write)
  28. #pragma section(".lprfc$A", read, write)
  29. #pragma section(".lprfc$Z", read, write)
  30. #pragma section(".lprfb$A", read, write)
  31. #pragma section(".lprfb$Z", read, write)
  32. #pragma section(".lorderfile$A", read, write)
  33. #pragma section(".lprfnd$A", read, write)
  34. #pragma section(".lprfnd$Z", read, write)
  35. #endif
  36. __llvm_profile_data COMPILER_RT_SECTION(".lprfd$A") DataStart = {0};
  37. __llvm_profile_data COMPILER_RT_SECTION(".lprfd$Z") DataEnd = {0};
  38. const char COMPILER_RT_SECTION(".lprfn$A") NamesStart = '\0';
  39. const char COMPILER_RT_SECTION(".lprfn$Z") NamesEnd = '\0';
  40. char COMPILER_RT_SECTION(".lprfc$A") CountersStart;
  41. char COMPILER_RT_SECTION(".lprfc$Z") CountersEnd;
  42. char COMPILER_RT_SECTION(".lprfb$A") BitmapStart;
  43. char COMPILER_RT_SECTION(".lprfb$Z") BitmapEnd;
  44. uint32_t COMPILER_RT_SECTION(".lorderfile$A") OrderFileStart;
  45. ValueProfNode COMPILER_RT_SECTION(".lprfnd$A") VNodesStart;
  46. ValueProfNode COMPILER_RT_SECTION(".lprfnd$Z") VNodesEnd;
  47. const __llvm_profile_data *__llvm_profile_begin_data(void) {
  48. return &DataStart + 1;
  49. }
  50. const __llvm_profile_data *__llvm_profile_end_data(void) { return &DataEnd; }
  51. const char *__llvm_profile_begin_names(void) { return &NamesStart + 1; }
  52. const char *__llvm_profile_end_names(void) { return &NamesEnd; }
  53. char *__llvm_profile_begin_counters(void) { return &CountersStart + 1; }
  54. char *__llvm_profile_end_counters(void) { return &CountersEnd; }
  55. char *__llvm_profile_begin_bitmap(void) { return &BitmapStart + 1; }
  56. char *__llvm_profile_end_bitmap(void) { return &BitmapEnd; }
  57. uint32_t *__llvm_profile_begin_orderfile(void) { return &OrderFileStart; }
  58. ValueProfNode *__llvm_profile_begin_vnodes(void) { return &VNodesStart + 1; }
  59. ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
  60. ValueProfNode *CurrentVNode = &VNodesStart + 1;
  61. ValueProfNode *EndVNode = &VNodesEnd;
  62. /* lld-link provides __buildid symbol which ponits to the 16 bytes build id when
  63. * using /build-id flag. https://lld.llvm.org/windows_support.html#lld-flags */
  64. #define BUILD_ID_LEN 16
  65. COMPILER_RT_WEAK uint8_t __buildid[BUILD_ID_LEN];
  66. COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
  67. if (*__buildid) {
  68. if (Writer &&
  69. lprofWriteOneBinaryId(Writer, BUILD_ID_LEN, __buildid, 0) == -1)
  70. return -1;
  71. return sizeof(uint64_t) + BUILD_ID_LEN;
  72. }
  73. return 0;
  74. }
  75. #endif