This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2407c13aa4a4: [AIX][PGO] Enable linux style PGO on AIX 
(authored by w2yehia).
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124857/new/

https://reviews.llvm.org/D124857

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/aix-ld.c
  compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
  compiler-rt/lib/profile/InstrProfilingPlatformOther.c
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/platform.ll
  llvm/test/Instrumentation/InstrProfiling/profiling.ll

Index: llvm/test/Instrumentation/InstrProfiling/profiling.ll
===================================================================
--- llvm/test/Instrumentation/InstrProfiling/profiling.ll
+++ llvm/test/Instrumentation/InstrProfiling/profiling.ll
@@ -119,9 +119,4 @@
 ; ELF_GENERIC-NEXT:   ret void
 ; ELF_GENERIC-NEXT: }
 
-; XCOFF:      define internal void @__llvm_profile_register_functions() unnamed_addr {
-; XCOFF-NEXT:   call void @__llvm_profile_register_function(i8* bitcast ({ i64, i64, i64, i8*, i8*, i32, [{{.*}} x i16] }* @__profd_foo to i8*))
-; XCOFF-NEXT:   call void @__llvm_profile_register_function(i8* bitcast ({ i64, i64, i64, i8*, i8*, i32, [{{.*}} x i16] }* @__profd_foo_weak to i8*))
-; XCOFF:   call void @__llvm_profile_register_names_function(i8* getelementptr inbounds {{.*}} @__llvm_prf_nm
-; XCOFF-NEXT:   ret void
-; XCOFF-NEXT: }
+; XCOFF-NOT:  internal void @__llvm_profile_register_functions() 
Index: llvm/test/Instrumentation/InstrProfiling/platform.ll
===================================================================
--- llvm/test/Instrumentation/InstrProfiling/platform.ll
+++ llvm/test/Instrumentation/InstrProfiling/platform.ll
@@ -50,7 +50,7 @@
 ; SOLARIS-NOT: define internal void @__llvm_profile_register_functions
 ; PS4-NOT: define internal void @__llvm_profile_register_functions
 ; WINDOWS-NOT: define internal void @__llvm_profile_register_functions
-; AIX: define internal void @__llvm_profile_register_functions
+; AIX-NOT: define internal void @__llvm_profile_register_functions
 
 ;; PR38340: When dynamic registration is used, we had a bug where we'd register
 ;; something that's not a __profd_* variable.
@@ -61,4 +61,4 @@
 ; SOLARIS-NOT: define internal void @__llvm_profile_init
 ; PS4-NOT: define internal void @__llvm_profile_init
 ; WINDOWS-NOT: define internal void @__llvm_profile_init
-; AIX: define internal void @__llvm_profile_init
+; AIX-NOT: define internal void @__llvm_profile_init
Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -855,7 +855,7 @@
   if (TT.isOSDarwin())
     return false;
   // Use linker script magic to get data/cnts/name start/end.
-  if (TT.isOSLinux() || TT.isOSFreeBSD() || TT.isOSNetBSD() ||
+  if (TT.isOSAIX() || TT.isOSLinux() || TT.isOSFreeBSD() || TT.isOSNetBSD() ||
       TT.isOSSolaris() || TT.isOSFuchsia() || TT.isPS4() || TT.isOSWindows())
     return false;
 
Index: compiler-rt/lib/profile/InstrProfilingPlatformOther.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingPlatformOther.c
+++ compiler-rt/lib/profile/InstrProfilingPlatformOther.c
@@ -8,7 +8,7 @@
 
 #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) &&     \
     !defined(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) &&       \
-    !defined(__NetBSD__) && !defined(_WIN32)
+    !defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX)
 
 #include <stdlib.h>
 #include <stdio.h>
Index: compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
+++ compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
@@ -7,10 +7,13 @@
 \*===----------------------------------------------------------------------===*/
 
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
-    (defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__)
+    (defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) || \
+    defined(_AIX)
 
+#if !defined(_AIX)
 #include <elf.h>
 #include <link.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 
@@ -227,4 +230,43 @@
 }
 #endif
 
+#if defined(_AIX)
+// Empty stubs to allow linking object files using the registration-based scheme
+COMPILER_RT_VISIBILITY
+void __llvm_profile_register_function(void *Data_) {}
+
+COMPILER_RT_VISIBILITY
+void __llvm_profile_register_names_function(void *NamesStart,
+                                            uint64_t NamesSize) {}
+
+// The __start_SECNAME and __stop_SECNAME symbols (for SECNAME \in
+// {"__llvm_prf_cnts", "__llvm_prf_data", "__llvm_prf_name", "__llvm_prf_vnds"})
+// are always live when linking on AIX, regardless if the .o's being linked
+// reference symbols from the profile library (for example when no files were
+// compiled with -fprofile-generate). That's because these symbols are kept
+// alive through references in constructor functions that are always live in the
+// default linking model on AIX (-bcdtors:all). The __start_SECNAME and
+// __stop_SECNAME symbols are only resolved by the linker when the SECNAME
+// section exists. So for the scenario where the user objects have no such
+// section (i.e. when they are compiled with -fno-profile-generate), we always
+// define these zero length variables in each of the above 4 sections.
+COMPILER_RT_VISIBILITY int dummy_cnts[0] COMPILER_RT_SECTION(
+    COMPILER_RT_SEG INSTR_PROF_CNTS_SECT_NAME);
+COMPILER_RT_VISIBILITY int dummy_data[0] COMPILER_RT_SECTION(
+    COMPILER_RT_SEG INSTR_PROF_DATA_SECT_NAME);
+COMPILER_RT_VISIBILITY const int dummy_name[0] COMPILER_RT_SECTION(
+    COMPILER_RT_SEG INSTR_PROF_NAME_SECT_NAME);
+COMPILER_RT_VISIBILITY int dummy_vnds[0] COMPILER_RT_SECTION(
+    COMPILER_RT_SEG INSTR_PROF_VNODES_SECT_NAME);
+
+// Create a fake reference to avoid GC'ing of the dummy variables by the linker.
+// Ideally, we create a ".ref" of each variable inside the function
+// __llvm_profile_begin_counters(), but there's no source level construct
+// that allows us to generate that.
+__attribute__((destructor)) void keep() {
+  int volatile use = &dummy_cnts < &dummy_data && &dummy_name < &dummy_vnds;
+  (void)use;
+}
+#endif
+
 #endif
Index: clang/test/Driver/aix-ld.c
===================================================================
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -664,7 +664,7 @@
 // CHECK-PGO-NON-LTO:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-PGO-NON-LTO:     "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-PGO-NON-LTO:     "{{.*}}ld{{(.exe)?}}"
-// CHECK-PGO-NON-LTO:     "-bdbg:namedsects"
+// CHECK-PGO-NON-LTO:     "-bdbg:namedsects:ss"
 // CHECK-PGO-NON-LTO:     "-b32"
 // CHECK-PGO-NON-LTO:     "-bpT:0x10000000" "-bpD:0x20000000"
 // CHECK-PGO-NON-LTO:     "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
@@ -692,7 +692,7 @@
 // CHECK-PGO-LTO:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-PGO-LTO:     "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-PGO-LTO:     "{{.*}}ld{{(.exe)?}}"
-// CHECK-PGO-LTO:     "-bdbg:namedsects"
+// CHECK-PGO-LTO:     "-bdbg:namedsects:ss"
 // CHECK-PGO-LTO:     "-b32"
 // CHECK-PGO-LTO:     "-bpT:0x10000000" "-bpD:0x20000000"
 // CHECK-PGO-LTO:     "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
Index: clang/lib/Driver/ToolChains/AIX.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -117,7 +117,7 @@
                     options::OPT_fno_profile_generate, false) ||
        Args.hasArg(options::OPT_fcreate_profile) ||
        Args.hasArg(options::OPT_coverage))
-    CmdArgs.push_back("-bdbg:namedsects");
+    CmdArgs.push_back("-bdbg:namedsects:ss");
 
   // Specify linker output file.
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to