Forum

× General discussions, feature requests for CodeTyphon Project and discussions that don't fit in any of the other specific CodeTyphon forum categories.

Question ctri.oi and ctrn.o in multi-arch OS

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 3 weeks ago - 3 months 3 weeks ago #11866 by fredvs
ctri.oi and ctrn.o in multi-arch OS was created by fredvs
Hello Sternas.

When trying to build fpc 32 on a multi-arch OS (like Arch, Mint, Debian,...) it fails to link.
And this even if the 32 bit libraries are installed and the correct path for library 32 bit was assigned for the linker.

Here the result of link.res (using -sh parameter to get the script to linker):

SEARCH_DIR("/lib/")
SEARCH_DIR("/usr/lib/")
SEARCH_DIR("/usr/lib32/")
SEARCH_DIR("/usr/lib/gcc/x86_64-pc-linux-gnu/8.1.1/32/")
...
INPUT(
/lib/crti.o
/usr/lib32/crtbegin.o
...
/usr/lib32/crtend.o
/lib/crtn.o
...
)

It is because the system cannot recognize the correct ELF 32 bit of ctri.o and ctrn.o (and assign some crti.o + crtn.o 64 bit) .

It can be easy fix adding that fpc parameter at compilation: -Xd (= do not use the standard library path).

Now the result of link.res adding -Xd parameter:

SEARCH_DIR("/usr/lib32/")
SEARCH_DIR("/usr/lib/gcc/x86_64-pc-linux-gnu/8.1.1/32/")
...
INPUT(
/usr/lib32/crti.o
/usr/lib32/crtbegin.o
...
/usr/lib32/crtend.o
/usr/lib32/crtn.o
...
)

And with this -Xd parameter, the right crti.o and crtn.o are used and the link can be done.

PS: I did add -Xd parameter in the CodeTpyphon buit fpc 32 bit makefile and now, the compilation + link of fpc 32 bit on a 64 bit OS works out of the box.
Maybe you can add this -Xd parameter in next CT release.

Fre;D
Last edit: 3 months 3 weeks ago by fredvs.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 3 weeks ago #11869 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
> PS: I did add -Xd parameter in the CodeTpyphon buit fpc 32 bit makefile

Huh, there is a easier way!

In fpc.cnf of fpc-bootstrap ---> add this at end:
# Dont load default path of system libraries.
-Xd

Yep, now fpc 32 can be compiled + linked in a multiarch-system.

And for the users that want to compile a 32 bit application in a 64 multi-arch system:

---> Add -Xd into /codetyphon/fpc/fpc32/bin/i386-linux/fpc.cnf

;-)

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 months 3 weeks ago #11870 by Sternas Stefanos
Replied by Sternas Stefanos on topic ctri.oi and ctrn.o in multi-arch OS
Thanks Sir
we will add and test

CodeTyphon Architect and Programmer

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 months 3 weeks ago - 3 months 3 weeks ago #11873 by Sternas Stefanos
Replied by Sternas Stefanos on topic ctri.oi and ctrn.o in multi-arch OS
@fredvs
We test your suggestion
on Debian 9.5 , Debian 10.x (SID), Ubuntu 18.04 Desktop and Fedora 28.
GCC (crti.o, crtbegin.o, crtend.o, crtn.o) installation directory is NOT the same on these Distributions.

We must "Hunting" crti.o, crtbegin.o, crtend.o, crtn.o files. :silly: it's a "drama"

-Xd Freepascal parameter is only for special cases.

I think the last 2 years Linux and GCC has serious problem...

PS: In our lab we test every day a lot of OSes, today we test (again) NetBSD 8.0 final.
The general "OSes status and quality Picture" in our LAB is very disappointing
at this time of century...:huh:

CodeTyphon Architect and Programmer
Last edit: 3 months 3 weeks ago by Sternas Stefanos.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 3 weeks ago - 3 months 3 weeks ago #11875 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS

GCC (crti.o, crtbegin.o, crtend.o, crtn.o) installation directory is NOT the same on these Distributions.
We must "Hunting" crti.o, crtbegin.o, crtend.o, crtn.o files. :silly: it's a "drama"


Sternas, the problem is **only** for crti.o and crtn.o, **not** for crtbegin.o, crtend.o and all other libraries.

It is because crti.o and crtn.o have ELF that is not correctly recognized by the system.

with -Xd parameter, the search path /lib and /usr/lib (that have 64 bit libraries) is not added in the list of search path.

With -Xd parameter, only /usr/lib32 (and all defined with -Fu) are added.

And that way, the correct /usr/lib32/ctri.o +/usr/lib32/ctrn.o are used.

-Xd Freepascal parameter is only for special cases.


Exactly and using fpc32 in a 64 bit OS is a perfect example how to use it (not use the default search path of the 64 bit system).

Fre;D
Last edit: 3 months 3 weeks ago by fredvs.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago - 3 months 2 weeks ago #11879 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Hello Sternas.

OK, I get a more elegant solution without use of the -Xd parameter:

In /fpcsrc/compiler/systems/t_linux.pas, line 155:

{$ifdef x86_64}
...
{$else}
   LibrarySearchPath.AddPath(sysrootpath,'/lib;/usr/lib;/usr/X11R6/lib',true); 
{$endif}


Could be changed with this:
(and so not oblige to use -Xd parameter, even in multi-arch)

{$ifdef x86_64}
...
{$else}
   LibrarySearchPath.AddPath(sysrootpath,'/usr/lib32;/usr/X11R6/lib;/usr/lib;/lib',true);
{$endif}


Tested and works.
IMHO, the hierarchy of search-path is better too (and follows what they did for {$ifdef x86_64}).

PS: Last commit of t_linux is from 2008, maybe in those time multi-arch was not tested.

Fre;D
Last edit: 3 months 2 weeks ago by fredvs.

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 months 2 weeks ago #11880 by Sternas Stefanos
Replied by Sternas Stefanos on topic ctri.oi and ctrn.o in multi-arch OS
Thanks
we will test this

CodeTyphon Architect and Programmer

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago #11881 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Hello.

Included t_linux.pas.

File Attachment:

File Name: t_linux.pas.tar.gz
File Size:14 KB


Fre;D
Attachments:

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 months 2 weeks ago #11882 by Sternas Stefanos
Replied by Sternas Stefanos on topic ctri.oi and ctrn.o in multi-arch OS
We put your patch to LAB CT 6.6
and test on...
Ubuntu 18.04.1, Fedora 28, ArchLinux, Debian 9.5 etc

PS: t_linux.pas from SVN FPC info

CodeTyphon Architect and Programmer
Attachments:

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago #11883 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Hello Sternas.

For all the passionates about ELF multi-arch, here how to check if a file is
a ELF and what kind.

From Wikipedia, ELF format:
...
Read the first four bytes. If they are equal to \x7fELF, it's an ELF file.
The ELF magic number is 0x7f454C46 (0x7f + "ELF")
The 5th byte is 1 for a 32 bit executable, 2 for a 64 bit executable.
...

In attachment a little fpc console program that use+demonstrate this:

File Attachment:

File Name: checkelf.pas.tar.gz
File Size:1 KB


Tested on many files, it works perfectly.

If I was the King, I would propose this for fpc:

At building of the linker-script, librarysearchpath.FindFile should do a
check if the foundfile has the correct ELF signature.

I would add a parameter for FindFile : checkelf: (unit cfileutl.pas):

--> function TSearchPathList.FindFile(const f :
TCmdStr;allowcache:boolean;var foundfile:TCmdStr; checkelf:boolean =
false):boolean;

And if checkelf = true then CheckELF(foundfile) // the function from the
attachment CheckELF program-demo.

Fre;D

PS: Whoever understood is very strong.
Attachments:

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago #11891 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Hello Sternas.

If I was the King, I would use the files included in attachment.
With this a ELF check is done when fpc built the script for linking.
So even if the ctr*.o with wrong ELF is found, the check will re-search until the good ELF is found.

The files are /fpcsrc/compiler/cfileutl.pas and /fpcsrc/compiler/system/t_linux.pas:

File Attachment:

File Name: cfileutil_...x.tar.gz
File Size:25 KB


Fre;D
Attachments:

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 months 2 weeks ago - 3 months 2 weeks ago #11892 by Sternas Stefanos
Replied by Sternas Stefanos on topic ctri.oi and ctrn.o in multi-arch OS
Ok done
Any suggestion, from which Linux distribution to start tests ?

CodeTyphon Architect and Programmer
Last edit: 3 months 2 weeks ago by Sternas Stefanos.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago - 3 months 2 weeks ago #11894 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Hello Sternas.

I did deep test on last Manjaro-Arch 64 bit.
And if findfile find a wrong ELF, it does search in a other path, till the good ELF is found.

Fre;D

PS: With FreeBSD there is also the same problem with t_bsd.pas.

Included a fixed t_bsd.pas (fixed directory-search-path for 32 bit lib).

File Attachment:

File Name: t_bsd.pas.tar.gz
File Size:8 KB
Attachments:
Last edit: 3 months 2 weeks ago by fredvs.

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 months 2 weeks ago - 3 months 2 weeks ago #11895 by Sternas Stefanos
Replied by Sternas Stefanos on topic ctri.oi and ctrn.o in multi-arch OS
done
give us time to test... :)

CodeTyphon Architect and Programmer
Last edit: 3 months 2 weeks ago by Sternas Stefanos.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago - 3 months 2 weeks ago #11902 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Hello Sternas.

Included patched files from last CT update.
[EDIT]: Was re-updloaded (the first was a not the good one).

File Attachment:

File Name: fpc_checkelf2.tar.gz
File Size:33 KB


Tested for multi-arch Linux and FreeBSD on x86_64 and for i386.

In cfileutl.pas, FindFileELF(...) :
...
{$IF (DEFINED(linux) or DEFINED(bsd)) and (DEFINED(x86_64) or DEFINED(i386))} 
          if result then
           if checkelf(pchar(FoundFile)) <> {$ifdef x86_64} 2 {$else} 1 {$endif}
            then result := false;
          {$endif}
...

And here code of checkelf:
function CheckELF(ObjectFilename : pchar): integer;
     var
       F: file; 
       BufferTag: array[0..4] of byte; 
     begin
     // From Wikipedia, ELF format: 
     // Read the first four bytes. If they are equal to \x7fELF, it's an ELF file. 
     // The ELF magic number is 0x7f454C46 (0x7f + "ELF") 
     // The 5th byte is 1 for a 32 bit executable, 2 for a 64 bit executable.
 
       AssignFile(F, ObjectFilename); 
       FileMode:=fmOpenRead + fmShareDenyNone;
       Reset(F, 1); 
       BlockRead(F, BufferTag, SizeOf(BufferTag)); 
       CloseFile(F);       
   
       result := -1;
   
       if (BufferTag[0] = 127) and (BufferTag[1] = 69) and 
          (BufferTag[2] = 76) and (BufferTag[3] = 70) then // It is a ELF
         if (BufferTag[4] = 1) or (BufferTag[4] = 2) then  // 32 or 64 bit
          result := BufferTag[4];
      end;

This patch does a check of the ELF before to give the script to the linker.

/fpcsrc/compiler/cfileutl.pas
/fpcsrc/compiler/systems/t_linux.pas
/fpcsrc/compiler/systems/t_bsd.pas

Fre;D
Attachments:
Last edit: 3 months 2 weeks ago by fredvs. Reason: Wrong initial attachment.

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 months 2 weeks ago - 3 months 2 weeks ago #11903 by Sternas Stefanos
Replied by Sternas Stefanos on topic ctri.oi and ctrn.o in multi-arch OS
Done, testing now

Manjaro 64
FPC32 OK
FPC64 OK
Typhon32 NO
Typhon64 OK

ArchLinux 64
FPC32 OK
FPC64 OK
Typhon32 BigIDE Build but NOT run
Typhon64 BigIDE OK

CodeTyphon Architect and Programmer
Last edit: 3 months 2 weeks ago by Sternas Stefanos.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago - 3 months 2 weeks ago #11904 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Hello Sternas.

Manjaro 64
FPC32 OK
FPC64 OK
Typhon32 NO ---> Do you mean that without my patch, it runs ok ?
Typhon64 OK

I was able to compile+link FPC32 and Typhon32 on Manjaro64.
Also able to run FPC32 but **not** run Typhon32.

After some ask+search on Manjaro forum, the guilty is fontconfig.so 32 bit that is not compatible with GTK 32 bit.
So it is not a problem of CT but of Arch.
And there are lot of post for this because users cannot run 32 bit GTK applications (like GogleEarth 32 bit) on their multi-arch os.

There is a trick to make it work (but complicated), you have to do a regression of fontconfig.so of main system, then do some copy, then re-update with last commit of fontconfig.so.

Huh, in Manjaro forum, the develop-team promised to fix this "as soon as possible".

By the way, fpGUI and MSE app-32 bit run like charm on Manjaro multi-arch.

Fre;D
Last edit: 3 months 2 weeks ago by fredvs.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago - 3 months 2 weeks ago #11905 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Re-hello Sternas.

Maybe it is only a problem of Arch + GTK 32 bit.
Did you try with Typhon compiled with a other widget ( Qt, ...) ?
(Sorry I did not try this and do not know if Qt use fontconfig.so too).

Fre;D
Last edit: 3 months 2 weeks ago by fredvs.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago - 3 months 2 weeks ago #11906 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Re-re hello Sternas.

Aaargh, see last post of this:
www.reddit.com/r/archlinux/comments/873b...13_crashes_telegram/

This is not a Telegram bug. This is a fontconfig bug.
fontconfig 2.13 breaks Telegram, Chrome, Firefox, VSCode, and much, much more.
You'll be happy to know the fontconfig devs denied responsibility, closed the bug report, and are doing nothing to fix.


Fre;D
Last edit: 3 months 2 weeks ago by fredvs.

Please Log in or Create an account to join the conversation.

  • fredvs
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
3 months 2 weeks ago - 3 months 2 weeks ago #11907 by fredvs
Replied by fredvs on topic ctri.oi and ctrn.o in multi-arch OS
Hello Sternas.

I did compile Typhon IDE 32 bit with Qt4 and see picture...:



On one screen, Typhon64 + Typhon32 running together!

Yep, Typhon32/Qt4 compiles + link + run = out-of-the-box on Manjaro Muli-arch!

Now about Gtk2...
I am very sorry for this nice widget-set but..., lot of problems my friend.

And it is only the beginning, when lot of people will have upgraded fontconfigi.so,... it will have lot of trouble.
And for all Linux distro that uses Gtk (Mint, Ubuntu, ...all) none will be multi-arch working.

But I am really happy that Typhon32/Qt4 is OK for multi-arch.

Fre;D
Attachments:
Last edit: 3 months 2 weeks ago by fredvs.

Please Log in or Create an account to join the conversation.