[PATCH] D14468: Add zero size dummy data to ensure section symbol is always created

David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 6 15:47:02 PST 2015


davidxl created this revision.
davidxl added a reviewer: vsk.
davidxl added a subscriber: llvm-commits.

There is a scenario where a user does not specify -fprofile-instr-generate on compilation command but on the linker command only for various reasons. In such cases, since no object is instrumented, the llvm_prof_xxx sections won't exist and linker won't generate __start__.. and _stop__.. symbols leading to linker time unsat. 

Making __start_../__stop_.. weak extern symbols solve the problem when building executable, but PC relative dynamic reloc is not allowed so shared library case will still fail.

THis simple patch fixes the problem. It won't have any effect on regular use cases.

It has another added benefit -- it allows us to conditionally turn off generation of name sections completely (depending on user option) to reduce binary/profile data size -- that feature will come later.

http://reviews.llvm.org/D14468

Files:
  lib/profile/InstrProfilingPlatformLinux.c

Index: lib/profile/InstrProfilingPlatformLinux.c
===================================================================
--- lib/profile/InstrProfilingPlatformLinux.c
+++ lib/profile/InstrProfilingPlatformLinux.c
@@ -21,6 +21,13 @@
 extern char __start___llvm_prf_names __attribute__((visibility("hidden")));
 extern char __stop___llvm_prf_names __attribute__((visibility("hidden")));
 
+/* Add dummy data to ensure the section is always created. */
+__llvm_profile_data __llvm_prof_sect_data[0]
+    __attribute__((section("__llvm_prf_data")));
+uint64_t __llvm_prof_cnts_sect_data[0]
+    __attribute__((section("__llvm_prf_cnts")));
+char __llvm_prof_nms_sect_data[0] __attribute__((section("__llvm_prf_names")));
+
 __attribute__((visibility("hidden"))) const __llvm_profile_data *
 __llvm_profile_begin_data(void) {
   return &__start___llvm_prf_data;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14468.39604.patch
Type: text/x-patch
Size: 853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151106/3775cc3b/attachment.bin>


More information about the llvm-commits mailing list