Recent

Author Topic: Enable -gh flag cause linker to fail heaptrc.o  (Read 1307 times)

zamronypj

  • Full Member
  • ***
  • Posts: 133
    • Fano Framework, Free Pascal web application framework
Enable -gh flag cause linker to fail heaptrc.o
« on: June 15, 2019, 06:11:04 am »
I am trying to compile a program with Free Pascal, with -gh flag to turn on heaptrc to find out memory leak and get error message

/usr/bin/ld: /usr/local/lib/fpc/3.0.4/units/x86_64-linux/rtl/heaptrc.o: undefined reference to symbol '_end'
//usr/lib/x86_64-linux-gnu/librtmp.so.1: error adding symbols: DSO missing from command line

If I turn off -gh flag, my program successfully built.

Previously -gh flag was working fine. It seems it happens after I run Free Pascal cross compiling or after install libcurl4-gnutls-dev. I don't know and can't remember.

Why is error message triggered?

Original post
https://stackoverflow.com/questions/54806974/free-pascal-compiler-failed-to-link-with-error-heaptrc-o-undefined-reference-t
Fano Framework, Free Pascal web application framework https://fanoframework.github.io
Apache module executes Pascal program like scripting language https://zamronypj.github.io/mod_pascal/
Github https://github.com/zamronypj

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Enable -gh flag cause linker to fail heaptrc.o
« Reply #1 on: June 15, 2019, 11:59:21 am »
It seems that linking libcurl somehow hides the "_end" symbol: https://stackoverflow.com/questions/13328144/end-symbol-disappears-when-linking-to-libcurl

-gh needs this symbol to know where the initialised data section ends. I'm not sure there's anything FPC can do to fix this, since it apparently also happens with gcc (and I'm not aware of another easy way to detect that address).

tonyw

  • Sr. Member
  • ****
  • Posts: 319
    • MWA Software
Re: Enable -gh flag cause linker to fail heaptrc.o
« Reply #2 on: December 12, 2019, 12:19:48 pm »
I may be able to cast some new light on this problem.

I had this same problem when linking with heaptrc.o (under Linux) when testing out the new version of the Firebird.pas file distributed with Firebird 4 and while integrating it into IBX. There was no such problem with the current version.

I eventually traced the problem to this line in Firebird.pas:

function fb_get_master_interface : IMaster; cdecl; external 'fbclient';

It is a simple function declaration for an external function, and I had omitted to comment it out when preparing the new version. IBX dynamically loads libfbclient and hence the above is not appropriate.

Simply commenting out this line allowed the test program to link successfully with heaptrc.o.

My guess is that this linker problem is due to defining an external function in a way that is appropriate for a static library and then linking it to a library intended to be dynamically loaded.

 

TinyPortal © 2005-2018