Path: blob/main/contrib/llvm-project/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c
35233 views
/*===- InstrProfilingPlatformWindows.c - Profile data on Windows ----------===*\1|*2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3|* See https://llvm.org/LICENSE.txt for license information.4|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5|*6\*===----------------------------------------------------------------------===*/78#include <stddef.h>910#include "InstrProfiling.h"11#include "InstrProfilingInternal.h"1213#if defined(_WIN32)1415#if defined(_MSC_VER)16/* Merge read-write sections into .data. */17#pragma comment(linker, "/MERGE:.lprfb=.data")18#pragma comment(linker, "/MERGE:.lprfd=.data")19#pragma comment(linker, "/MERGE:.lprfv=.data")20#pragma comment(linker, "/MERGE:.lprfnd=.data")21/* Do *NOT* merge .lprfn and .lcovmap into .rdata. llvm-cov must be able to find22* after the fact.23* Do *NOT* merge .lprfc .rdata. When binary profile correlation is enabled,24* llvm-cov must be able to find after the fact.25*/2627/* Allocate read-only section bounds. */28#pragma section(".lprfn$A", read)29#pragma section(".lprfn$Z", read)3031/* Allocate read-write section bounds. */32#pragma section(".lprfd$A", read, write)33#pragma section(".lprfd$Z", read, write)34#pragma section(".lprfc$A", read, write)35#pragma section(".lprfc$Z", read, write)36#pragma section(".lprfb$A", read, write)37#pragma section(".lprfb$Z", read, write)38#pragma section(".lorderfile$A", read, write)39#pragma section(".lprfnd$A", read, write)40#pragma section(".lprfnd$Z", read, write)41#endif4243__llvm_profile_data COMPILER_RT_SECTION(".lprfd$A") DataStart = {0};44__llvm_profile_data COMPILER_RT_SECTION(".lprfd$Z") DataEnd = {0};4546const char COMPILER_RT_SECTION(".lprfn$A") NamesStart = '\0';47const char COMPILER_RT_SECTION(".lprfn$Z") NamesEnd = '\0';4849char COMPILER_RT_SECTION(".lprfc$A") CountersStart;50char COMPILER_RT_SECTION(".lprfc$Z") CountersEnd;51char COMPILER_RT_SECTION(".lprfb$A") BitmapStart;52char COMPILER_RT_SECTION(".lprfb$Z") BitmapEnd;53uint32_t COMPILER_RT_SECTION(".lorderfile$A") OrderFileStart;5455ValueProfNode COMPILER_RT_SECTION(".lprfnd$A") VNodesStart;56ValueProfNode COMPILER_RT_SECTION(".lprfnd$Z") VNodesEnd;5758const __llvm_profile_data *__llvm_profile_begin_data(void) {59return &DataStart + 1;60}61const __llvm_profile_data *__llvm_profile_end_data(void) { return &DataEnd; }6263// Type profiling isn't implemented under MSVC ABI, so return NULL (rather than64// implementing linker magic on Windows) to make it more explicit. To elaborate,65// the current type profiling implementation maps a profiled vtable address to a66// vtable variable through vtables mangled name. Under MSVC ABI, the variable67// name for vtables might not be the mangled name (see68// MicrosoftCXXABI::getAddrOfVTable in MicrosoftCXXABI.cpp for more details on69// how a vtable name is computed). Note the mangled name is still in the vtable70// IR (just not variable name) for mapping purpose, but more implementation work71// is required.72const VTableProfData *__llvm_profile_begin_vtables(void) { return NULL; }73const VTableProfData *__llvm_profile_end_vtables(void) { return NULL; }7475const char *__llvm_profile_begin_names(void) { return &NamesStart + 1; }76const char *__llvm_profile_end_names(void) { return &NamesEnd; }7778// Type profiling isn't supported on Windows, so return NULl to make it more79// explicit.80const char *__llvm_profile_begin_vtabnames(void) { return NULL; }81const char *__llvm_profile_end_vtabnames(void) { return NULL; }8283char *__llvm_profile_begin_counters(void) { return &CountersStart + 1; }84char *__llvm_profile_end_counters(void) { return &CountersEnd; }85char *__llvm_profile_begin_bitmap(void) { return &BitmapStart + 1; }86char *__llvm_profile_end_bitmap(void) { return &BitmapEnd; }87uint32_t *__llvm_profile_begin_orderfile(void) { return &OrderFileStart; }8889ValueProfNode *__llvm_profile_begin_vnodes(void) { return &VNodesStart + 1; }90ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }9192ValueProfNode *CurrentVNode = &VNodesStart + 1;93ValueProfNode *EndVNode = &VNodesEnd;9495/* lld-link provides __buildid symbol which points to the 16 bytes build id when96* using /build-id flag. https://lld.llvm.org/windows_support.html#lld-flags */97#define BUILD_ID_LEN 1698COMPILER_RT_WEAK uint8_t __buildid[BUILD_ID_LEN] = {0};99COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {100static const uint8_t zeros[BUILD_ID_LEN] = {0};101if (memcmp(__buildid, zeros, BUILD_ID_LEN) != 0) {102if (Writer &&103lprofWriteOneBinaryId(Writer, BUILD_ID_LEN, __buildid, 0) == -1)104return -1;105return sizeof(uint64_t) + BUILD_ID_LEN;106}107return 0;108}109110#endif111112113