Skip to content

Instantly share code, notes, and snippets.

@minglotus-6
Created February 26, 2024 23:16
Show Gist options
  • Save minglotus-6/9df208e14f7c20b352cdb7f89d38c228 to your computer and use it in GitHub Desktop.
Save minglotus-6/9df208e14f7c20b352cdb7f89d38c228 to your computer and use it in GitHub Desktop.
Windows linker magic
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c b/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c
index 4800ec72c77d..a7237a03fca2 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c
@@ -28,6 +28,10 @@
/* Allocate read-only section bounds. */
#pragma section(".lprfn$A", read)
#pragma section(".lprfn$Z", read)
+#pragma section(".lprfvn$A", read, write)
+#pragma section(".lprfvn$Z", read, write)
+#pragma section(".lprfvt$A", read, write)
+#pragma section(".lprfvt$Z", read, write)
/* Allocate read-write section bounds. */
#pragma section(".lprfd$A", read, write)
@@ -44,9 +48,15 @@
__llvm_profile_data COMPILER_RT_SECTION(".lprfd$A") DataStart = {0};
__llvm_profile_data COMPILER_RT_SECTION(".lprfd$Z") DataEnd = {0};
+VTableProfData COMPILER_RT_SECTION(".lprfvt$A") VTableProfDataStart = {0};
+VTableProfData COMPILER_RT_SECTION(".lprfvt$Z") VTableProfDataEnd = {0};
+
const char COMPILER_RT_SECTION(".lprfn$A") NamesStart = '\0';
const char COMPILER_RT_SECTION(".lprfn$Z") NamesEnd = '\0';
+const char COMPILER_RT_SECTION(".lprfvn$A") VNamesStart = '\0';
+const char COMPILER_RT_SECTION(".lprfvn$Z") VNamesEnd = '\0';
+
char COMPILER_RT_SECTION(".lprfc$A") CountersStart;
char COMPILER_RT_SECTION(".lprfc$Z") CountersEnd;
char COMPILER_RT_SECTION(".lprfb$A") BitmapStart;
@@ -61,16 +71,19 @@ const __llvm_profile_data *__llvm_profile_begin_data(void) {
}
const __llvm_profile_data *__llvm_profile_end_data(void) { return &DataEnd; }
-// TODO: Implement the linker magic on Windows.
-const VTableProfData *__llvm_profile_begin_vtables(void) { return NULL; }
+const VTableProfData *__llvm_profile_begin_vtables(void) {
+ return &VTableProfDataStart + 1;
+}
-const VTableProfData *__llvm_profile_end_vtables(void) { return NULL; }
+const VTableProfData *__llvm_profile_end_vtables(void) {
+ return &VTableProfDataEnd;
+}
const char *__llvm_profile_begin_names(void) { return &NamesStart + 1; }
const char *__llvm_profile_end_names(void) { return &NamesEnd; }
-const char *__llvm_profile_begin_vtabnames(void) { return NULL; }
-const char *__llvm_profile_end_vtabnames(void) { return NULL; }
+const char *__llvm_profile_begin_vtabnames(void) { return &VNamesStart + 1; }
+const char *__llvm_profile_end_vtabnames(void) { return &VNamesEnd; }
char *__llvm_profile_begin_counters(void) { return &CountersStart + 1; }
char *__llvm_profile_end_counters(void) { return &CountersEnd; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment