musl-libc on Linux works with Alpine Linux and FPC 3.2.2 but not 3.3.1 lazarus / 32-Linux ---------------------------------------------------------------------- Bogen85 · 2023-09-10 14:18 This is somewhat related to this: https://forum.lazarus.freepascal.org/index.php/topic,63680.msg I filed an issue on this here: https://gitlab.com/freepascal.org/fpc/source/-/issues/40437 FPC 3.2.2 on alpine will compile and link dynamically linked executables that work as expected. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$h+}{$codepage utf8} program hello_libc; uses ctypes; function c_write (const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external 'libc' name 'write'; var        s: string = 'hello ';begin        c_write(1, pchar(s), length(s));        writeln('alpine musl!');end.  Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ fpc hello_libc.pasFree Pascal Compiler version 3.2.2 [2022/08/07] for x86_64Copyright (c) 1993-2021 by Florian Klaempfl and othersTarget OS: Linux for x86-64Compiling hello_libc.pasLinking hello_libcWarning: "crtbegin.o" not found, this will probably cause a linking failureWarning: "crtend.o" not found, this will probably cause a linking failure16 lines compiled, 0.0 sec2 warning(s) issued $ file hello_libchello_libc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, for GNU/Linux 2.4.0, stripped $ ldd hello_libc/lib/ld-musl-x86_64.so.1 (0x7ff02d918000)libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7ff02d918000) $ ./hello_libc hello alpine musl!  So it works on 3.2.2, but not on 3.3.1, causing the build of FPC 3.3.1 on Alpine Linux to fail (hence the issue report I filed). ---------------------------------------------------------------------- Bogen85 · 2023-09-10 15:45 Quote from: Bogen85 on September 10, 2023, 04:18:09 pmI filed an issue on this here: https://gitlab.com/freepascal.org/fpc/source/-/issues/40437 FPC 3.2.2 on alpine will compile and link dynamically linked executables that work as expected. For 3.3.1 it turned out to be shared object pathing issue. Quote from: Bogen85 on September 10, 2023, 04:18:09 pmSo it works on 3.2.2, but not on 3.3.1, causing the build of FPC 3.3.1 on Alpine Linux to fail (hence the issue report I filed). I'll work on proper patch for it, but for now I can use both FPC 3.2.2 and the latest FPC 3.3.1 on Alpine Linux with musl libc. ---------------------------------------------------------------------- Joanna · 2023-09-10 23:36 Congrats ---------------------------------------------------------------------- toby · 2023-09-19 01:28 i have installed musl into /projects/musl/usr.local.musl with the /projects/musl > ls usr.local.musl/ bin  include  lib /projects/musl > ls usr.local.musl/lib crt1.o  crtn.o  libcrypt.a  libdl.a  libpthread.a  librt.a    libxnet.a       rcrt1.o crti.o  libc.a  libc.so     libm.a   libresolv.a   libutil.a  musl- gcc.specs  Scrt1.o --- i have musl static and libc static working with linklib and libc dynamic working with function external lib but none of the function 'external lib'  work for musl but none of musl dynamic work  either with function 'external lib' or linklib work could you look at the code and tell me what i am doing wrong? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program musl; // from https://forum.lazarus.freepascal.org/index.php/topic,64570.0.html uses ctypes; var s : ansistring = 'write : '; // glibc dynamic linked  good//function c_write(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external 'libc' name 'write'; // glibc static linked{$linklib /lib/libc.a} // goodfunction c_write(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external name 'write'; // glibc dynamic linked//{$linklib /lib/libc.so} // fails//{$linklib libc} // good//function c_write(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external name 'write';  // musl static linked{$linklib /projects/musl/usr.local.musl/lib/libc.a} // goodfunction c_write1(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external name 'write'; // musl dynamic linked//{$linklib /projects/musl/usr.local.musl/lib/libc.so} // fails//function c_write1(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external name 'write'; // /usr/local/bin/ld: cannot find -l/projects/musl/usr.local.musl/lib/libc.a//function c_write2(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external '/projects/musl/usr.local.musl/lib/libc.a' name 'write'; // /usr/local/bin/ld: cannot find -l/projects/musl/usr.local.musl/lib/libc//function c_write2(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external '/projects/musl/usr.local.musl/lib/libc.so' name 'write';  begin writeln; // glibcc_write(1, pchar(s), length(s));writeln('libc'); // muslc_write1(1, pchar(s), length(s));writeln('musl1');  // external musl method static and dynamic both fail//c_write2(1, pchar(s), length(s));//writeln('musli2'); writeln; end. ---------------------------------------------------------------------- Bogen85 · 2023-09-19 03:44 Quote from: toby on September 19, 2023, 03:28:14 amcould you look at the code and tell me what i am doing wrong? What compiler are you using? No official compiler for FPC supports musl-libc. There is a hack on the alpine package for fpc to make it work on alpine. I have a patch for x86_64 mainline FPC and musl libc, but I need to do some more work on it to make it work for the other architectures and build a compiler for it when other libc are present. https://gitlab.com/bogen85/source/- /compare/main...main?from_project_id=28644964#81870c36041af85b22d9720d e972572a2d733365 But there is a bit more work to do on it: https://gitlab.com/freepascal.org/fpc/source/-/issues/40437 ---------------------------------------------------------------------- toby · 2023-09-19 18:19 What compiler are you using? fpc-3.3.1 No official compiler for FPC supports musl-libc. i'm pretty sure the static musl one works with fpc // musl static linked {$linklib /projects/musl/usr.local.musl/lib/libc.a} // good function c_write1(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external name 'write'; // musl c_write1(1, pchar(s), length(s)); writeln('musl1'); ---- i'm having trouble getting it to use the dynamic library with the same linklib code // musl dynamic linked //{$linklib /projects/musl/usr.local.musl/lib/libc.so} // fails //function c_write1(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external name 'write'; or using  extenal fullpath with both musl static or dynamic // /usr/local/bin/ld: cannot find -l/projects/musl/usr.local.musl/lib/libc.a //function c_write2(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external '/projects/musl/usr.local.musl/lib/libc.a' name 'write'; // /usr/local/bin/ld: cannot find -l/projects/musl/usr.local.musl/lib/libc //function c_write2(const fd: cint; const buffer: pchar; const count: cint): cint; cdecl; external '/projects/musl/usr.local.musl/lib/libc.so' name 'write';