Bug 22284

Summary: -pg -pie doesn't work
Product: glibc Reporter: H.J. Lu <hjl.tools>
Component: libcAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: drepper.fsp
Priority: P2 Flags: fweimer: security-
Version: 2.27   
Target Milestone: 2.27   
Host: Target:
Build: Last reconfirmed:

Description H.J. Lu 2017-10-12 01:16:33 UTC
[hjl@gnu-efi-2 gcc]$ cat x.c
#include <stdio.h>

void
foo (void)
{
  printf ("hello\n");
}

int
main ()
{
  foo ();
  return 0;
}
[hjl@gnu-efi-2 gcc]$ gcc  -pg -fpie -pie x.c
[hjl@gnu-efi-2 gcc]$ ./a.out 
hello
[hjl@gnu-efi-2 gcc]$ gprof --brief a.out 
Flat profile:

Each sample counts as 0.01 seconds.
 no time accumulated

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    


			Call graph


granularity: each sample hit covers 2 byte(s) no time propagated

index % time    self  children    called     name


Index by function name

[hjl@gnu-efi-2 gcc]$ gcc  -pg  x.c
[hjl@gnu-efi-2 gcc]$ ./a.out 
hello
[hjl@gnu-efi-2 gcc]$ gprof --brief a.out 
Flat profile:

Each sample counts as 0.01 seconds.
 no time accumulated

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
  0.00      0.00     0.00        1     0.00     0.00  foo


			Call graph


granularity: each sample hit covers 2 byte(s) no time propagated

index % time    self  children    called     name
                0.00    0.00       1/1           main [7]
[1]      0.0    0.00    0.00       1         foo [1]
-----------------------------------------------


Index by function name

   [1] foo
[hjl@gnu-efi-2 gcc]$
Comment 1 H.J. Lu 2017-10-12 10:51:15 UTC
Fixed for 2.27.
Comment 2 cvs-commit@gcc.gnu.org 2017-10-12 10:51:15 UTC
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, master has been updated
       via  d165ca64980f90ccace088670652cc203d1b5411 (commit)
      from  bc9620d040b7494f457ccb750c9797b47ed76ada (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d165ca64980f90ccace088670652cc203d1b5411

commit d165ca64980f90ccace088670652cc203d1b5411
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/Makefile [$(have-fpie)$(build-shared) == yesyes] (tests,
    	tests-pie): Add tst-gmon-pie.
    	(CFLAGS-tst-gmon-pie.c): New.
    	(CRT-tst-gmon-pie): Likewise.
    	(tst-gmon-pie-ENV): Likewise.
    	[$(have-fpie)$(build-shared) == yesyes] (tests-special): Likewise.
    	($(objpfx)tst-gmon-pie.out): Likewise.
    	(clean-tst-gmon-pie-data): Likewise.
    	($(objpfx)tst-gmon-pie-gprof.out): Likewise.
    	* 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>

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

Summary of changes:
 ChangeLog           |   20 ++++++++++++++++++++
 gmon/Makefile       |   21 +++++++++++++++++++++
 gmon/gmon.c         |   47 +++++++++++++++++++++++++++++++++++++----------
 gmon/tst-gmon-pie.c |    1 +
 4 files changed, 79 insertions(+), 10 deletions(-)
 create mode 100644 gmon/tst-gmon-pie.c
Comment 3 cvs-commit@gcc.gnu.org 2017-10-12 22:58:58 UTC
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 -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;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)

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