Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2026-03

Trying to use gprof profiler, but linking keeps failing

12 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hi. I wanted to use gprof to profile a binary of mine that has performance problems. I'm trying to recompiled the fpgui framework and the program with -O- and -pg but the framework fails at the linking stage.

Linking target/fpgui-framework
bootstrap_program.pas(126,1) Warning: "crtbegin.o" not found, this will probably cause a linking failure
bootstrap_program.pas(126,1) Warning: "crtend.o" not found, this will probably cause a linking failure
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libc_nonshared.a(atexit.oS): in function `atexit':
(.text+0x7): undefined reference to `__dso_handle' /usr/bin/ld: target/fpgui-framework: hidden symbol `__dso_handle' isn't defined
/usr/bin/ld: final link failed: bad value
bootstrap_program.pas(126,1) Error: Error while linking bootstrap_program.pas(126,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /data/devel/fpc-3.2.2/x86_64-linux/bin/ppcx64 returned an error exitcode

Any ideas? I then did a google search and Gemini came back with this:

The -pg (gprof) flag doesn't work well with Free Pascal — it tries to link against C runtime profiling infrastructure (crtbegin.o, __dso_handle) that FPC's linker setup doesn't support.

Is this true?

Regards,
Graeme

Reply by email

Michael Van Canneyt
to Unknown author
mailinglists--- wrote 31 lines
Hi. I wanted to use gprof to profile a binary of mine that has performance problems. I'm trying to recompiled the fpgui framework and the program with -O- and -pg but the framework fails at the linking stage. Linking target/fpgui-framework bootstrap_program.pas(126,1) Warning: "crtbegin.o" not found, this will probably cause a linking failure bootstrap_program.pas(126,1) Warning: "crtend.o" not found, this will probably cause a linking failure /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libc_nonshared.a(atexit.oS): in function `atexit': (.text+0x7): undefined reference to `__dso_handle' /usr/bin/ld: target/fpgui-framework: hidden symbol `__dso_handle' isn't defined /usr/bin/ld: final link failed: bad value bootstrap_program.pas(126,1) Error: Error while linking bootstrap_program.pas(126,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: /data/devel/fpc-3.2.2/x86_64-linux/bin/ppcx64 returned an error exitcode Any ideas? I then did a google search and Gemini came back with this: The -pg (gprof) flag doesn't work well with Free Pascal — it tries to link against C runtime profiling infrastructure (crtbegin.o, __dso_handle) that FPC's linker setup doesn't support. Is this true?

Yes, it is...

Michael.

Reply by email

Unknown author
to Martin Frb
Martin Frb wrote
Have you considered valgrind (tool callgrind) and kcachegrind? It takes a bit (actually significantly) longer to profile/run the app.

Thank you. Yes, that's what I did in the end. It massively slowed down my app, so not sure how accurate the results are, but its better that manual GetTickCount64 everywhere. :-D

Regards,
Graeme

Reply by email

Unknown author
to Michael Van Canneyt: Yes, it is... Michael.
Michael Van Canneyt wrote 7 lines
> The -pg (gprof) flag doesn't work well with Free Pascal — it tries to > link against C runtime profiling infrastructure (crtbegin.o, > __dso_handle) that FPC's linker setup doesn't support. > > Is this true? Yes, it is...

I found a solution - at least on my Ubuntu 24.04 system.

Add "-Fl/usr/lib/gcc/x86_64-linux-gnu/13" to the compiler options (your application or global). The ~/.fpc.cfg had -Fl/usr/lib but that was obviously not extensive enough to find the GCC libraries FPC needed.

And gprof is back in action! :)

Regards,
- Graeme -

Reply by email

Michael Van Canneyt
to Unknown author
mailinglists--- wrote 17 lines
On 2026-03-17 13:57, Michael Van Canneyt via fpc-pascal wrote: >> The -pg (gprof) flag doesn't work well with Free Pascal — it tries to >> link against C runtime profiling infrastructure (crtbegin.o, >> __dso_handle) that FPC's linker setup doesn't support. >> >> Is this true? > > Yes, it is... I found a solution - at least on my Ubuntu 24.04 system. Add "-Fl/usr/lib/gcc/x86_64-linux-gnu/13" to the compiler options (your application or global). The ~/.fpc.cfg had -Fl/usr/lib but that was obviously not extensive enough to find the GCC libraries FPC needed. And gprof is back in action! :)

Can you please add an issue to the bugtracker:

We should probably scan /usr/lib during installation for this path and add it to the default generated fpc.cfg

Michael.

Reply by email

Unknown author
to Marco van de Voort: Op 22-3-2026 om 01:06 schreef mailinglists--- via fpc-pascal: Was that a package manager…
Marco van de Voort wrote
Was that a package manager installed version of FPC? That should have run samplecfg to detect it.

I initially had FPC 3.2.2 installed via Ubuntu's package manager, but I then had issues switching between FPC 3.2.2 and FPC 3.3.1. So I uninstall the packaged version. Cloned the repos and compiled my own. I recall using samplecfg to generate the initial fpc.cfg, which I then moved to $HOME and tweaked the version string so I can easily switch between the two FPC versions, but use the same ~/.fpc.cfg file.

Regards,
G.

Reply by email

Unknown author
to Martin Frb: May I be so curious to ask how the results compared to valgrind? I know that they wont…
Martin Frb wrote
May I be so curious to ask how the results compared to valgrind?

I went back to the same commit and retested with Valgrind. The profiling results were very close: 84% (gprof) vs. 80% (Valgrind) of call time spent in one method. Both reported the same overall issue. Valgrind also listed other methods, but they primarily lead up to the actual performance culprit. Overall, I felt gprof provided clearer results.

The biggest difference, however, was performance. With gprof, the application runs normally; I couldn't visually observe a noticeable runtime difference compared to when profiling is disabled. With Valgrind, it’s like playing a game at 2 FPS vs. the normal 60 FPS. It is nearly unusable in comparison.

Regards,
- Graeme -

Reply by email

Martin Frb
to Unknown author
mailinglists--- wrote 16 lines
On 2026-03-22 07:28, Martin Frb via fpc-pascal wrote: > > May I be so curious to ask how the results compared to valgrind? I went back to the same commit and retested with Valgrind. The profiling results were very close: 84% (gprof) vs. 80% (Valgrind) of call time spent in one method. Both reported the same overall issue. Valgrind also listed other methods, but they primarily lead up to the actual performance culprit. Overall, I felt gprof provided clearer results. The biggest difference, however, was performance. With gprof, the application runs normally; I couldn't visually observe a noticeable runtime difference compared to when profiling is disabled. With Valgrind, it’s like playing a game at 2 FPS vs. the normal 60 FPS. It is nearly unusable in comparison.

Well, about what I would have expected. I don't know gprof, never took the time to set it up, but I am using valgrind.

I would expect gprof to have less granularity, so it will concentrate on the big issues, which is ok.
What I like with valgrind is, that sometimes I can even get results for individual lines in a routine.

Don't know if you know, but in case, if you ever need it, one useful trick: Start valgrind with profiling disabled. then enable it just before you start the code that needs to be profiled, and disable it as soon as it finishes (well yes, that means a few minutes of eager waiting). But that way you remove any other execution from the result.

Reply by email