Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] gprof not working with PIE
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
astor86
n00b
n00b


Joined: 19 Feb 2016
Posts: 57

PostPosted: Thu Jan 25, 2018 3:05 pm    Post subject: [solved] gprof not working with PIE Reply with quote

[Moderator edit: Changed title to reflect the apparent solution: gprof and PIE do not mix; previous title was [solved] gprof not working with gcc >= 6. -Hu]

Hi,

gprof does not work, meaning that it does not display function names, function calls. It either print nothing
Code:
$ gprof -Q a.out gmon.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   


or (different code actually)
Code:
$ gprof -Q ../a.out gmon.out
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name   
100.31      2.79     2.79                             data_start


Do I need to have proper use flags somewhere?

Thanks


Last edited by astor86 on Fri Jan 26, 2018 8:47 am; edited 1 time in total
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Thu Jan 25, 2018 4:01 pm    Post subject: Reply with quote

Hi astor86,

there's a nice tutorial: https://www.thegeekstuff.com/2012/08/gprof-tutorial/.

Do these examples work on your computer?

Mike
Back to top
View user's profile Send private message
astor86
n00b
n00b


Joined: 19 Feb 2016
Posts: 57

PostPosted: Thu Jan 25, 2018 5:50 pm    Post subject: Reply with quote

dear mike155,

I know how to use gprof :) and indeed on an another machine it gives me the right information. so I am sure there is something wrong with my installation..
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21586

PostPosted: Fri Jan 26, 2018 2:52 am    Post subject: Reply with quote

What commands did you use to generate a.out?
Back to top
View user's profile Send private message
astor86
n00b
n00b


Joined: 19 Feb 2016
Posts: 57

PostPosted: Fri Jan 26, 2018 8:26 am    Post subject: Reply with quote

Dear Hu
Quote:
What commands did you use to generate a.out?

Code:
gcc -g -pg source_file.c
Back to top
View user's profile Send private message
astor86
n00b
n00b


Joined: 19 Feb 2016
Posts: 57

PostPosted: Fri Jan 26, 2018 8:38 am    Post subject: Reply with quote

I tried to compile with clang and gprof displays the right things.. So it may be an issue on the gcc I have. I tried both with gcc-6.4.0 and gcc-7.2.0 but without success.

I also found this bug report..

https://bugs.launchpad.net/ubuntu/+source/gcc-6/+bug/1678510
Back to top
View user's profile Send private message
astor86
n00b
n00b


Joined: 19 Feb 2016
Posts: 57

PostPosted: Fri Jan 26, 2018 8:46 am    Post subject: Reply with quote

If I add -no-pie to both compile and link flags I got the right results both with gcc-6 and gcc-7. For the sake of completeness I need to compile as follows
Code:
gcc -no-pie -g -pg -c source_file.c
gcc -no-pie -pg source_file.o -lother_libs

in this way gprof will like a.out

Thanks to everybody
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Fri Jan 26, 2018 11:08 am    Post subject: Reply with quote

Quote:
If I add -no-pie to both compile and link flags I got the right results both with gcc-6 and gcc-7.

Thanks for sharing this! I use gprof once or twice a year - and I'm sure your post will save me a couple of hours the next time I will use gprof!

But it's probably not a 'feature' or 'bug' of GCC 6 or 7. It's the consequence of the switch to profile 17.0, which enables generation of position independent code by default.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum