Getting runtime error when include cthreads lib in Lazarus/free pascal - linux

I'm trying to code a multithread application in Lazarus/free pascal, but I've noticed that when I include the "cthreads" lib (always the first line of my project.lpr file), on some Linux distros, I get a runtime error when running the application. I believe it's some broken library. However, I don't know how to identify it. Could you help me?
project1.lpr:
program project1;
uses
cthreads,
cmem;
begin
writeln('test');
end.
error:
[root#dockerinaja /]# ./project1
Runtime error 203 at $0000000000418D5C
$0000000000418D5C
$000000000040086D
ldd ./project1:
[root#dockerinaja /]# ldd /project1
linux-vdso.so.1 (0x00007ffc43fbd000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f359ff5e000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f359ff58000)
libc.so.6 => /lib64/libc.so.6 (0x00007f359fd92000)
/lib64/ld-linux-x86-64.so.2 (0x00007f359ff8b000)

I noticed that I had a very old version of Free Pascal. I just updated to version 3.2.0 and it fixed my problem. Thanks.

Related

Forcing ELF binary to use another libc.so [duplicate]

This question already has answers here:
Multiple glibc libraries on a single host
(11 answers)
Closed 6 years ago.
I need to make ELF binary file to use another version of libc.so for scientific purposes. I tried to do it with LD_PRELOAD and patchelf utility, but then binary does not run with an errors like:
./a.out: error while loading shared libraries: libc-2.15.so: cannot open shared object file: No such file or directory or Segmentation fault (core dumped).
I think that it is because I need another version of ld.so.
What is most efficient way to make binary use my version of libc?
EDIT: I do not have source code of binary.
EDIT: Error message edited. No SELinux, no AppArmor.
For me it looks that you did not spend the whole path to the new libc variant.
I did the following:
ldd example
linux-vdso.so.1 (0x00007ffe9c087000)
libstdc++.so.6 => /opt/linux-gnu_6.1.0/lib64/libstdc++.so.6 (0x00007f0cef872000)
libm.so.6 => /lib64/libm.so.6 (0x00007f0cef56f000)
libgcc_s.so.1 => /opt/linux-gnu_6.1.0/lib64/libgcc_s.so.1 (0x00007f0cef359000)
libc.so.6 => /lib64/libc.so.6 (0x00007f0ceef98000)
/lib64/ld-linux-x86-64.so.2 (0x000055ca3cb92000)
LD_PRELOAD=/tmp/bug_libc.so ldd example
linux-vdso.so.1 (0x00007ffc2cff8000)
/tmp/bug_libc.so (0x00007f56a1358000)
libstdc++.so.6 => /opt/linux-gnu_6.1.0/lib64/libstdc++.so.6 (0x00007f56a0f9a000)
libm.so.6 => /lib64/libm.so.6 (0x00007f56a0c98000)
libgcc_s.so.1 => /opt/linux-gnu_6.1.0/lib64/libgcc_s.so.1 (0x00007f56a0a82000)
/lib64/ld-linux-x86-64.so.2 (0x00005605c8a7a000)
If I replace with a non valid libc a got a different error message. Only if I gave the wrong path like:
LD_PRELOAD=/tmp/bug_libc.so2 ldd go
ERROR: ld.so: object '/tmp/bug_libc.so2' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/tmp/bug_libc.so2' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
linux-vdso.so.1 (0x00007ffedcde4000)
libstdc++.so.6 => /opt/linux-gnu_6.1.0/lib64/libstdc++.so.6 (0x00007f3ae2188000)
libm.so.6 => /lib64/libm.so.6 (0x00007f3ae1e85000)
libgcc_s.so.1 => /opt/linux-gnu_6.1.0/lib64/libgcc_s.so.1 (0x00007f3ae1c6f000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3ae18ae000)
/lib64/ld-linux-x86-64.so.2 (0x000055df54aae000)
Maybe you have some other problem by accessing your replacement libc-file.
Check the access flags on the file and also check if SELinux or AppArmor or other protection stops loading libc in your environment. Because replacing libc opens a security hole it is a candidate for SELinux & Co!
And you should check always with ldd first. Maybe your new libc requires some more (older) variants of other libs which can not be found on your system. Normaly libc did not require other libs, but I have no idea what game you are playing. Whatever: ldd gives you a more detailed answer to the things which are going on in the library loading phase.
EDIT: segfault
If you get segfault, you typically have compiled your application with incompatible header files. You have to compile with the headers which comes with the libc version you want to use. If you compile against your system headers for system libc and run any incompatible version of precompiled libc, you get any kind of memory errors by accessing wrong data structures.
This answer explains why LD_PRELOAD can not work, and suggests solutions.
I tried to do it with LD_PRELOAD and patchelf utility
It's not clear whether your use of patchelf touched only DT_RPATH, only PT_INTERP, or both. You need to do both.

Haskell linking with dynamic libraries on Ubuntu

I am having issues linking to a Haskell library we wrote. It goes wrong on Ubuntu, but not on Arch Linux. The error on Ubuntu we get is this:
/usr/bin/ld: warning: libHSdeepseq-1.3.0.0-ghc7.4.1.so, needed by /usr/lib/ghc/containers-0.4.2.1/libHScontainers-0.4.2.1-ghc7.4.1.so, not found (try using -rpath or -rpath-link)
/usr/lib/ghc/containers-0.4.2.1/libHScontainers-0.4.2.1-ghc7.4.1.so: undefined reference to 'deepseqzm1zi3zi0zi0_ControlziDeepSeq_zdfNFDataArrayzuzdcrnf1_info'
The issue seems to be caused by the fact that libHScontainers-0.4.2.1-ghc7.4.1.so is incorrectly linked as one can see by the output of ldd:
ldd /usr/lib/ghc/containers-0.4.2.1/libHScontainers-0.4.2.1-ghc7.4.1.so
linux-vdso.so.1 => (0x00007fffe95a2000)
libHSdeepseq-1.3.0.0-ghc7.4.1.so => not found
libHSbase-4.5.0.0-ghc7.4.1.so => not found
libHSghc-prim-0.2.0.0-ghc7.4.1.so => not found
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f89a5a59000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f89a569a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f89a5fd8000)
Apparently the dependent libraries can not be found. They are installed. However if I do the same on Arch:
ldd /usr/lib/ghc-7.8.3/deepseq-1.3.0.2/libHSdeepseq-1.3.0.2-ghc7.8.3.so
linux-vdso.so.1 (0x00007fff09dfe000)
libgmp.so.10 => /usr/lib/libgmp.so.10 (0x00007fb8d3e96000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007fb8d3b91000)
librt.so.1 => /usr/lib/librt.so.1 (0x00007fb8d3988000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fb8d3784000)
libffi.so.6 => /usr/lib/libffi.so.6 (0x00007fb8d357b000)
libHSarray-0.5.0.0-ghc7.8.3.so => /usr/lib/ghc-7.8.3/deepseq-1.3.0.2/../array-0.5.0.0/libHSarray-0.5.0.0-ghc7.8.3.so (0x00007fb8d32e1000)
libHSbase-4.7.0.1-ghc7.8.3.so => /usr/lib/ghc-7.8.3/deepseq-1.3.0.2/../base-4.7.0.1/libHSbase-4.7.0.1-ghc7.8.3.so (0x00007fb8d2967000)
libHSinteger-gmp-0.5.1.0-ghc7.8.3.so => /usr/lib/ghc-7.8.3/deepseq-1.3.0.2/../integer-gmp-0.5.1.0/libHSinteger-gmp-0.5.1.0-ghc7.8.3.so (0x00007fb8d274c000)
libHSghc-prim-0.3.1.0-ghc7.8.3.so => /usr/lib/ghc-7.8.3/deepseq-1.3.0.2/../ghc-prim-0.3.1.0/libHSghc-prim-0.3.1.0-ghc7.8.3.so (0x00007fb8d24cf000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007fb8d212c000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fb8d1f10000)
/usr/lib64/ld-linux-x86-64.so.2 (0x00007fb8d435f000)
The libraries are found.
As suggested I can solve this on Ubuntu by using -rpath in the application we try to link to the Haskell library. But this means that we have to do this for every Haskell package which seems wrong to me.
We can also fix this by adding a line to /etc/ld.so.conf.d/ghc.conf. But this also has to be done for every package and is not user-friendly.
A few questions I have:
What is the correct way to fix this?
Why are the packages in ghc-dynamic incorrectly linked?
Why is the linker able to find libHScontainers-0.4.2.1-ghc7.4.1.so but not libHSdeepseq-1.3.0.0-ghc7.4.1.so?
I strongly suspect that this is because the Haskell libraries installed by ghc have the locations of their dependencies (the RPATH field of their ELF header; you can verify using readelf -d) defined in terms of $ORIGIN. When library X depends on library Y, library X can indicate that library Y should be found in a location relative to its own location by using $ORIGIN. This is supported by the dynamic linker, but is not supported by the static linker.
(I'm speculating here:) Your library will define the location of its direct dependencies (in your case, I'm guessing, this includes containers) in terms of its own RPATH, which is not in terms of $ORIGIN. This is why the linker can find those, but not its transitive dependencies (again, I'm guessing, this includes deepseq in your case).
So why the difference between Arch Linux and Ubuntu? (Speculating further.) This is because unlike on Arch Linux, Ubunbu's linker uses --as-needed by default. You see, ghc will link your library against all its dependencies (including transitive ones), but then the linker will omit some of those dependencies because it doesn't directly depend on them. You could verify this by relinking with --no-as-needed.
Note that these errors by the static linkers really aren't errors, but warnings: it tries to resolve symbols, but it can't; but the dynamic linker will be able to anyway. So you can instruct the linker to ignore these errors (--unresolved-symbols=ignore-all) and all should be well.
I've been battling with adding explicit support in Cabal for generating Haskell libraries for use in C programs, and found the same problem. See https://github.com/haskell/cabal/pull/2540#issuecomment-95984067 for details.

Error ./vpdetection: /gpfs/apps/x86_64-rhel5/matlab/R2012a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found

I am now trying to run some MATLAB code in Linux environment:
Linux version is Red Hat Enterprise Linux Server release 5.9 (Tikanga).
gcc version is 4.1.2.
MALTAB version is R2012b.
The statement in MALTAB that causes the problem is:
[status, result] = system('./vpdetection lines.tmp lines.out');
I got an error as follows:
./vpdetection: /gpfs/apps/x86_64-rhel5/matlab/R2012a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found
I have googled several solutions but they all require editing system files.
Since I am running the code on server where I don't have sudo right to edit system files.
Are there any other workarounds that don't need to edit system files?
I have tried ldd command. The result is as follows:
[sxh415#cyberstar vpdetection]$ ldd matlab/vpdetection
matlab/vpdetection: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by matlab/vpdetection)
matlab/vpdetection: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by matlab/vpdetection)
matlab/vpdetection: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by matlab/vpdetection)
linux-vdso.so.1 => (0x00007ffff7ff8000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003845400000)
libm.so.6 => /lib64/libm.so.6 (0x0000003840400000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003844c00000)
libc.so.6 => /lib64/libc.so.6 (0x0000003840000000)
/lib64/ld-linux-x86-64.so.2 (0x000000383fc00000)
/gpfs/apps/x86_64-rhel5/matlab/R2012a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found
This error means: libstdc++.so.6 distributed with your version of Matlab is too old, and does not provide version `GLIBCXX_3.4.14'. The matlab version corresponds to gcc-4.5 or earlier, but you have some code that was compiled with gcc-4.6 (or later).
You must arrange for your executable to pick up a newer libstdc++.so.6.
I don't have sudo right to edit system files.
You could copy a sufficiently new version of libstdc++.so.6 to ~/lib64, then export LD_LIBRARY_PATH=$HOME/lib64.
Run ldd on your executable both inside MATLAB and outside on the system shell:
Shell
$ ldd ./vpdetection
MATLAB
>> !ldd ./vpdetection
To solve any dependency conflicts, try using LD_PRELOAD when launching either MATLAB itself or the executable:
$ LD_PRELOAD=/path/to/libstdc++.so matlab
or
>> system('LD_PRELOAD=/path/to/libstdc++.so ./vpdetection lines.tmp lines.out')

SPIKE fuzzer gives LD_LIBRARY_PATH issue on ubuntu

I am trying to configure SPIKE file fuzzer on Ubuntu machine. It gives Now you need to set your LD_LIBRARY_PATH to include the path to libdisasm.so and the path to libdlrpc.so.
I did set LD_LIBRARY_PATH using export. But it is still showing up the same error again. Seems LD_LIBRARY_PATH is not working for SPIKE. How do I solve this issue.
With your LD_LIBRARY_PATH set run ldd on the fuzzer executable (I'm assuming it's an executable). It should show you the libraries that are used and potentially missing. Keeping fixing your path until all the dependencies are met.
[user#host jobs]$ ldd `which gcc`
linux-vdso.so.1 => (0x00007fff3e193000)
libm.so.6 => /lib64/libm.so.6 (0x00007fa2c1f4c000)
libz.so.1 => /lib64/libz.so.1 (0x00007fa2c1d34000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa2c197d000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa2c2275000)

Linux module dependency

We have a linux module developed by a 3rd party, now the module runs correctly on a Fedora system but on Ubuntu the same fails. When we do an ldd for the binary the following output is received
linux-gate.so.1 => (0xffffe000)
libdl.so.2 => /lib32/libdl.so.2 (0xf76f5000)
libc.so.6 => /lib32/libc.so.6 (0xf759b000)
/lib/ld-linux.so.2 (0xf7705000)
libutf16.so => not found
I am unable to find the library libutf16 for ubuntu, where can i find this library or is it part of a bigger library.
There is no file that contains libutf16 in its name in any package in Ubuntu 10.04.

Resources