Recent

Author Topic: FreeBSD shared library problems  (Read 1536 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3602
    • StrumPract is the musicians best friend
Re: FreeBSD shared library problems
« Reply #15 on: May 01, 2025, 09:27:10 pm »
I suppose you did try to debug the lib compiled with -gl parameter and to run doublecmd with gdb.

Code: Pascal  [Select][+][-]
  1. $ gdb --args doublecmd

Does it give infos when crashing after use your lib?

Hmm, I think my method of cleaning + compiling stuff with lazarus is faulty. I literally re-compiled it 3 times with cleaning before to make sure I am looking at the current version. But now after I enabled debugging in the lib and loading it, the problem no longer occurs. Not even after disabling -gl again. I thought "Clean up and build..." option with everything selected is a sure way to get everything recompiled?


Oooops, sorry, I should say it before all:

Always compile with the -B (build all) parameter, fpc is not safe without it.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

bbrtj

  • New Member
  • *
  • Posts: 11
Re: FreeBSD shared library problems
« Reply #16 on: May 01, 2025, 09:39:52 pm »
Okay, thanks. That's useful info. You've been very helpful, much appreciated.

So let me sum up the current state:
- compiling shared libraries works with the patch from my gitlab issue
- compiling LazUtils in shared libraries work after modifying LazUtf8 to use fpwidestring instead of cwstring
- with these 2 changes, compiling doublecmd zip plugin is possible
- cwstring is lava, if it is used anywhere in the shared library code then Bus error occurs

So my questions right now are:
- what are the options of persisting this configuration in fpc/lazarus sources, so that it will work out of the box?
- what are the options of fixing the cwstring Bus error?

FreeBSD community would surely enjoy doublecmd with working plugins, see problems like
https://forums.freebsd.org/threads/double-commander-cannot-load-plugins-wcx-for-zip.93650/
https://forums.freebsd.org/threads/any-double-commander-users-here-do-packers-run-for-you.84480/

Fred vS

  • Hero Member
  • *****
  • Posts: 3602
    • StrumPract is the musicians best friend
Re: FreeBSD shared library problems
« Reply #17 on: May 01, 2025, 09:47:23 pm »
Without -B fpc tends to ignore all the new {$...} instruction you added or changed in your code from previous compilation.
A good habit is to use the -B parameter for the "release" (even always if the compilation is not too long).

Quote
- what are the options of fixing the cwstring Bus error?
Ho, so it is not fixed yet ?
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

bbrtj

  • New Member
  • *
  • Posts: 11
Re: FreeBSD shared library problems
« Reply #18 on: May 01, 2025, 09:54:46 pm »
Without -B fpc tends to ignore all the new {$...} instruction you added or changed in your code from previous compilation.
A good habit is to use the -B parameter for the "release" (even always if the compilation is not too long).

Is it specifically fpc option, or is lazbuild option enough? Since lazbuild also has -B option. Though the release mode -B flag is neat.

Quote
- what are the options of fixing the cwstring Bus error?
Ho, so it is not fixed yet ?

It is worked around by removing cwstring usage from LazUtf8. I'm not sure if it is something which can be fixed (to be able to use cwstring).

Fred vS

  • Hero Member
  • *****
  • Posts: 3602
    • StrumPract is the musicians best friend
Re: FreeBSD shared library problems
« Reply #19 on: May 01, 2025, 09:54:52 pm »
Quote
- what are the options of fixing the cwstring Bus error?

Personally, I would arrange to not have to use any unit that uses cwstring, so no LCL dependencies (LazUtf8 and friends), especially for a library.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

AmatCoder

  • Jr. Member
  • **
  • Posts: 67
    • My site
Re: FreeBSD shared library problems
« Reply #20 on: May 02, 2025, 10:50:49 am »
Quote from: bbrtj
- what are the options of fixing the cwstring Bus error?

Can you test if it works with version 3.2.2?
Or as you are using fixes_3_2 branch you can try reverting this commit.

bbrtj

  • New Member
  • *
  • Posts: 11
Re: FreeBSD shared library problems
« Reply #21 on: May 02, 2025, 02:34:15 pm »
Something is still wrong when compiling my shared library:
- if I compile with debugging (-gl), it runs
- if I compile without debugging, it raises Bus error
- if I compile without debugging but with a writeln statement anywhere, it runs

I am rebuilding with -B passed to fpc, so it does not look like an issue with partial rebuilding (even though it certainly does not rebuild lazarus units).

Fred vS

  • Hero Member
  • *****
  • Posts: 3602
    • StrumPract is the musicians best friend
Re: FreeBSD shared library problems
« Reply #22 on: May 02, 2025, 02:50:10 pm »
Something is still wrong when compiling my shared library:
- if I compile with debugging (-gl), it runs
- if I compile without debugging, it raises Bus error
- if I compile without debugging but with a writeln statement anywhere, it runs

I am rebuilding with -B passed to fpc, so it does not look like an issue with partial rebuilding (even though it certainly does not rebuild lazarus units).

Did you try to compile without optimization -O-, or maximum -O1?

Also, could you try to compile without -Xs  (strip all symbols) and without  -XX (try to smartlink units)?
« Last Edit: May 02, 2025, 03:07:18 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3602
    • StrumPract is the musicians best friend
Re: FreeBSD shared library problems
« Reply #23 on: May 02, 2025, 02:55:48 pm »
Please, give us the parameters you use to compile your library.

If you are using Lazarus, menu "Project/Project Options" and click on "Show options" and copy the result + give it here.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12255
  • FPC developer.
Re: FreeBSD shared library problems
« Reply #24 on: May 02, 2025, 03:44:03 pm »
try "elfdump -n"

Looks fine to me

To me too. Anyway, the cwstrings sounds like dynamic libraries linked to libc don't work.

bbrtj

  • New Member
  • *
  • Posts: 11
Re: FreeBSD shared library problems
« Reply #25 on: May 02, 2025, 04:28:06 pm »
Please, give us the parameters you use to compile your library.

If you are using Lazarus, menu "Project/Project Options" and click on "Show options" and copy the result + give it here.

Here are my options:
Code: [Select]
/usr/home/bartosz/fpc/fixes/fpc/bin/x86_64-freebsd/fpc.sh
-MObjFPC
-Scghi
-Cg
-O1
-l
-vewnhibq
-Filib/x86_64-freebsd
-Fu/home/bartosz/prg/ovoplayer/src/ovotag
-Fu../../fpc/fixes/lazarus/components/lazutils/lib/x86_64-freebsd
-Fu../../fpc/fixes/lazarus/packager/units/x86_64-freebsd
-Fu.
-FUlib/x86_64-freebsd
-FE.
-olibtags.so
-B
-dLIBRARY

Fred vS

  • Hero Member
  • *****
  • Posts: 3602
    • StrumPract is the musicians best friend
Re: FreeBSD shared library problems
« Reply #26 on: May 02, 2025, 04:37:41 pm »
Please, give us the parameters you use to compile your library.

If you are using Lazarus, menu "Project/Project Options" and click on "Show options" and copy the result + give it here.

Here are my options:
Code: [Select]
/usr/home/bartosz/fpc/fixes/fpc/bin/x86_64-freebsd/fpc.sh
-MObjFPC
-Scghi
-Cg
-O1
-l
-vewnhibq
-Filib/x86_64-freebsd
-Fu/home/bartosz/prg/ovoplayer/src/ovotag
-Fu../../fpc/fixes/lazarus/components/lazutils/lib/x86_64-freebsd
-Fu../../fpc/fixes/lazarus/packager/units/x86_64-freebsd
-Fu.
-FUlib/x86_64-freebsd
-FE.
-olibtags.so
-B
-dLIBRARY

Hum, so you did not try adding the parameters/code from my reply #4  and #8 ...  :-\
I dont see -fPIC -Sh nor -O-
« Last Edit: May 02, 2025, 04:52:53 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

bbrtj

  • New Member
  • *
  • Posts: 11
Re: FreeBSD shared library problems
« Reply #27 on: May 02, 2025, 06:14:16 pm »
Hum, so you did not try adding the parameters/code from my reply #4  and #8 ...  :-\
I dont see -fPIC -Sh nor -O-

I added -fPIC and -Sh before, but removed them since they had no noticeable effect on the end result. I keep my sample as small as possible so that I know what helps and what doesn't.

I tried adding them again just now and they yet again make no impact. But you're right, you already gave me tons of tips that are not currently applied on my project. So I tried some of them again, and adding the cmem as the first unit seems to do the trick. Thanks and sorry.

Can you test if it works with version 3.2.2?
Or as you are using fixes_3_2 branch you can try reverting this commit.

I will try that in the coming days, at the moment I'm trying to finish this one thing I started.

Fred vS

  • Hero Member
  • *****
  • Posts: 3602
    • StrumPract is the musicians best friend
Re: FreeBSD shared library problems
« Reply #28 on: May 02, 2025, 06:39:51 pm »
... and adding the cmem as the first unit seems to do the trick. Thanks and sorry.
And it was also the first advice.  ;)

And I'm glad we won this battle.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018