This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch hjl/pr22284/2.26 created. glibc-2.26-59-g5a951cc


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, hjl/pr22284/2.26 has been created
        at  5a951cc33ccec638bcd2a2ed44db34f2610dacd3 (commit)

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5a951cc33ccec638bcd2a2ed44db34f2610dacd3

commit 5a951cc33ccec638bcd2a2ed44db34f2610dacd3
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Oct 12 03:45:55 2017 -0700

    Support profiling PIE [BZ #22284]
    
    Since PIE can be loaded at any address, we need to subtract load address
    from PCs.
    
    	[BZ #22284]
    	* gmon/gmon.c [PIC]: Include <link.h>.
    	[PIC] (callback): New function.
    	(write_hist): Add an argument for load address.  Subtract load
    	address from PCs.
    	(write_call_graph): Likewise.
    	(write_gmon): Call __dl_iterate_phdr to get load address, pass
    	it to write_hist and write_call_graph.
    
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
    
    (cherry picked from commit d165ca64980f90ccace088670652cc203d1b5411)

diff --git a/gmon/gmon.c b/gmon/gmon.c
index f394a78..4d97ba1 100644
--- a/gmon/gmon.c
+++ b/gmon/gmon.c
@@ -46,6 +46,26 @@
 #include <libc-internal.h>
 #include <not-cancel.h>
 
+#ifdef PIC
+# include <link.h>
+
+static int
+callback (struct dl_phdr_info *info, size_t size, void *data)
+{
+  if (info->dlpi_name[0] == '\0')
+    {
+      /* The link map for the executable is created by calling
+	 _dl_new_object with "" as filename.  dl_iterate_phdr
+	 calls the callback function with filename from the
+	 link map as dlpi_name.  */
+      u_long *load_address = data;
+      *load_address = (u_long) info->dlpi_addr;
+      return 1;
+    }
+
+  return 0;
+}
+#endif
 
 /*  Head of basic-block list or NULL. */
 struct __bb *__bb_head attribute_hidden;
@@ -62,8 +82,8 @@ static int	s_scale;
 
 void moncontrol (int mode);
 void __moncontrol (int mode);
-static void write_hist (int fd) internal_function;
-static void write_call_graph (int fd) internal_function;
+static void write_hist (int fd, u_long load_address) internal_function;
+static void write_call_graph (int fd, u_long load_address) internal_function;
 static void write_bb_counts (int fd) internal_function;
 
 /*
@@ -172,7 +192,7 @@ weak_alias (__monstartup, monstartup)
 
 static void
 internal_function
-write_hist (int fd)
+write_hist (int fd, u_long load_address)
 {
   u_char tag = GMON_TAG_TIME_HIST;
 
@@ -209,8 +229,8 @@ write_hist (int fd)
 	      != offsetof (struct gmon_hist_hdr, dimen_abbrev)))
 	abort ();
 
-      thdr.low_pc = (char *) _gmonparam.lowpc;
-      thdr.high_pc = (char *) _gmonparam.highpc;
+      thdr.low_pc = (char *) _gmonparam.lowpc - load_address;
+      thdr.high_pc = (char *) _gmonparam.highpc - load_address;
       thdr.hist_size = _gmonparam.kcountsize / sizeof (HISTCOUNTER);
       thdr.prof_rate = __profile_frequency ();
       strncpy (thdr.dimen, "seconds", sizeof (thdr.dimen));
@@ -223,7 +243,7 @@ write_hist (int fd)
 
 static void
 internal_function
-write_call_graph (int fd)
+write_call_graph (int fd, u_long load_address)
 {
 #define NARCS_PER_WRITEV	32
   u_char tag = GMON_TAG_CG_ARC;
@@ -266,8 +286,9 @@ write_call_graph (int fd)
 	    }
 	  arc;
 
-	  arc.frompc = (char *) frompc;
-	  arc.selfpc = (char *) _gmonparam.tos[to_index].selfpc;
+	  arc.frompc = (char *) frompc - load_address;
+	  arc.selfpc = ((char *) _gmonparam.tos[to_index].selfpc
+			- load_address);
 	  arc.count  = _gmonparam.tos[to_index].count;
 	  memcpy (raw_arc + nfilled, &arc, sizeof (raw_arc [0]));
 
@@ -377,11 +398,17 @@ write_gmon (void)
     memset (ghdr.spare, '\0', sizeof (ghdr.spare));
     write_not_cancel (fd, &ghdr, sizeof (struct gmon_hdr));
 
+    /* Get load_address to profile PIE.  */
+    u_long load_address = 0;
+#ifdef PIC
+    __dl_iterate_phdr (callback, &load_address);
+#endif
+
     /* write PC histogram: */
-    write_hist (fd);
+    write_hist (fd, load_address);
 
     /* write call-graph: */
-    write_call_graph (fd);
+    write_call_graph (fd, load_address);
 
     /* write basic-block execution counts: */
     write_bb_counts (fd);

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]