GCC Version requirements to compile FB

Linux specific questions.
Axle
Posts: 67
Joined: May 31, 2022 6:49
Location: Australia

GCC Version requirements to compile FB

Post by Axle »

Hi Board

I am attempting to confirm the minimum/Maximum GCC version requirements for compiling FreeBASIC V1.09.0 on Ubuntu.

For example FB Win V1.09.0 is compiled with "winlibs-mingw-w64-x86_64-9.3.0-7.0.0-r3-sjlj.7z"

I am targeting Ubuntu 20.04.1 with a default version of GCC 9.3.0. The current version is GCC 9.4.0.
But will likely need to step up to Ubuntu 22.04 soon. I think the GCC version is about 11.x.x atm

This is mainly for compiling shared libraries for FB so I assume that GCC V 9.4.0 should be fine, but just want to confirm in case there are any gotchas to watch for?

I am checking for additional dependencies as well, for example https://documentation.help/FreeBASIC/DevBuildLinux.html
And for X11, no Wayland at this time.

Axle
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: GCC Version requirements to compile FB

Post by Coolman »

hello. always use the default gcc version of a linux distribution to compile programs. for example i installed in a lxd container (ubuntu 20.04) gcc version 11 to test compare the speed of a program... when i transferred it to the real system, it didn't work because it was incompatible with GLIBC. note that with gcc 10, it worked. probably this version doesn't depend on a different version of GLIBC. in any case, to avoid problems, stick to the official gcc version.
Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: GCC Version requirements to compile FB

Post by Avata »

I did compile with GCC 11.2 & GCC 12.1. and found out the function dir not working fine in OS windows 64 bits.

Code: Select all

#include "dir.bi" '' provides constants to match the attributes against

'' set input attribute,,,,, mask to allow files that are normal, hidden, system or directory
Const attrib_mask = fbNormal Or fbHidden Or fbSystem Or fbDirectory ' = &h37

Dim As LongInt Out_Attr '' unsigned integer to hold retrieved attributes

Dim As String fname '' file/directory name returned with
Dim As Integer filecount, dircount

fname = Dir("*.*", attrib_mask, Out_Attr) '' Get first file name/attributes, according to supplied file spec and attribute mask

Print "File listing in ???" & CurDir & ":"

Do Until Len(fname) = 0 '' loop until Dir returns empty string
	
	If (fname <> ".") And (fname <> "..") Then '' ignore current and parent directory entries
		
		Print fname
		
		If (Out_Attr And fbDirectory) <> 0 Then
			Print "- directory"
			dircount += 1
		Else
			Print "- file"
			filecount += 1
		End If
		If (Out_Attr And fbReadOnly) <> 0 Then Print ", read-only"
		If (Out_Attr And fbHidden  ) <> 0 Then Print ", hidden"
		If (Out_Attr And fbSystem  ) <> 0 Then Print ", system"
		If (Out_Attr And fbArchive ) <> 0 Then Print ", archived"
		
		
	End If
	fname= ""
	fname = Dir(Out_Attr) '' find next name/attributes
	
Loop

Print "Found " & filecount & " files and " & dircount & " subdirs"
Sleep(1000)
End
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: GCC Version requirements to compile FB

Post by TeeEmCee »

It's uncommon for there to be any problem when mixing object files compiled with different GCC versions on Linux but I've seen it happen a few times. It also matters whether you're using .so files (usually backward compatible), or .o and .a files (gcc and glibc devs do not try too hard to support linking old objects).
It's very common for there to be a problem on Windows if you mix different toolchains, because the mingw-w64/mingw.org version and build configuration may also be different, and there are many possible incompatibilities.

I don't believe the GCC requirement is documented anywhere or even known, but I compiled with GCC 5.0.3 not too long ago. The main problem with using older GCC versions seems to be that they might throw an error about an unrecognised -W flag that fbc passes. Last year a patch of mine to restore support for GCC 4.5 by avoiding certain such flags was merged but GCC 4.5 may not currently work.

Also, newer GCC versions often will add new warnings, which are annoying but harmless to FB users. Rare for it to cause a break.
Avata wrote: Jul 03, 2022 10:59 I did compile with GCC 11.2 & GCC 12.1. and found out the function dir not working fine in OS windows 64 bits.
What's the problem? Have you already reported it?
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: GCC Version requirements to compile FB

Post by srvaldez »

the newer versions of gcc do more aggressive optimizations, it can render a valid program non-functional, I suggest that if you encounter problems using the gcc backend that you compile using O1 or O0 and see if that works
Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: GCC Version requirements to compile FB

Post by Avata »

TeeEmCee wrote:
What's the problem? Have you already reported it?
I did not report this bug and would like confirmation from others. Running the 64-bit binaries will crash but 32 -bit is OK in OS Windows.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: GCC Version requirements to compile FB

Post by srvaldez »

I don't know what the problem is exactly but it's related to binutils >2.35.1, I just tried it with the latest Git repo built with gcc-13.0, binutils-2.37 and the 64-bit exe would crash regardless whether using gen gcc or gas64 optimazation options didn't make a difference but if I replace ld-2.37 with ld-2.35.1 then it ran ok
Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: GCC Version requirements to compile FB

Post by Avata »

srvaldez wrote: Jul 04, 2022 1:42 I don't know what the problem is exactly but it's related to binutils >2.35.1, I just tried it with the latest Git repo built with gcc-13.0, binutils-2.37 and the 64-bit exe would crash regardless whether using gen gcc or gas64 optimazation options didn't make a difference but if I replace ld-2.37 with ld-2.35.1 then it ran ok
Yes. I compile the windows application with binutils-2.37 also and the 64-bit exe would crash.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: GCC Version requirements to compile FB

Post by dodicat »

Win 10 64 bits
gcc version 12.1.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders)

Yes, I agree the dir method crashes.
An alternative method is OK.
Alternative:

Code: Select all


Function pipeout(Byval s As String="") Byref As String
      Var f=Freefile
      Dim As String tmp
      Open Pipe s For Input As #f 
      s=""
      Do Until Eof(f)
            Line Input #f,tmp
            s+=tmp+Chr(10)
      Loop
      Close #f
      Return s
End Function 

Sub getattributes(filename As String)
      Dim As String s,char,g
      Dim As Long i
      s=pipeout("attrib /d "+ filename)
      Print s
      If Chr(s[0])="F" Then Return
      For i=0 To 20
            char=Chr(s[i])
            Select Case char
            Case "A":Print("archive")
            Case "C":Print("compressed")
            Case "H":Print("hidden")
            Case "I":Print("not content indexed")
            Case "O":Print("offline")
            Case "P":Print("pinned (Windows 10 and OneDrive only)")
            Case "R":Print("readonly")
            Case "S":Print("system")
            Case "T":Print("temperory")
            Case "U":Print("unpinned (Windows 10 and OneDrive only)")
            Case "V":Print("integrity (Windows Server 2012R2+ ReFS only0")
            Case "X":Print("no_scrub_data (Windows Server 2012R2+ ReFS only)")
            End Select
      Next i
      Print("----------------")
End Sub

Sub splitstring(Byval s As String,chars As String,result() As String)
      Redim result(0)
      Dim As String var1,var2
      Dim As Long pst,LC=Len(chars)
      #macro split(stri)
      pst=Instr(stri,chars)
      var1="":var2=""
      If pst<>0 Then
            var1=Mid(stri,1,pst-1)
            var2=Mid(stri,pst+LC)
      Else
            var1=stri
      End If
      If Len(var1) Then 
            Redim Preserve result(1 To Ubound(result)+1)
            result(Ubound(result))=var1
      End If
      #endmacro
      Do
            split(s):s=var2
      Loop Until var2=""
End Sub

Var s= pipeout("dir /b "+Curdir)

Redim As String a()
splitstring(s,Chr(10),a())
For n As Long=Lbound(a) To Ubound(a)
      a(n)=Curdir+ "\"+ a(n)
      getattributes (a(n))
Next
Print
Print "entities checked ";Ubound(a)

Sleep

'gcc version 12.1.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 
Who is going to tell Brecht?
-gen gas64 works perfectly with dir method and alternative method.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: GCC Version requirements to compile FB

Post by srvaldez »

dodicat wrote: Jul 04, 2022 10:22 Win 10 64 bits
gcc version 12.1.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders)
----
-gen gas64 works perfectly with dir method and alternative method.
sorry dodicat but Avata's code crashes here when compiled with FB-gcc-12.1.0 using -gen gas64, it's possible that your build does not include the newer binutils, check your ld version because that's the common factor, or did you simply replace gcc in an older FB distribution instead of building FB with the new toolchain ?
btw, until the issue is looked into to determine what causes the crash it's too early to point fingers at either FB, gcc or binutils
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: GCC Version requirements to compile FB

Post by SARG »

This code is enough to get the crash even with gas64 (ld version 2.38.)

Code: Select all

Dir("*.*")
print "END"
Sleep
This morning I tried to debug (low level) but nothing obvious. The 'new' linker puts things in high memory addresses so outside of 32bit area, maybe the beginning of the explanation.
I'll continue my search with the code above.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: GCC Version requirements to compile FB

Post by srvaldez »

from Jeff's explanation here viewtopic.php?p=287143#p287143 I tried using -Wl "--image-base 0x40000000" but it crashed just the same
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: GCC Version requirements to compile FB

Post by dodicat »

My ld
GNU ld (Binutils for MinGW-W64 x86_64, built by Brecht Sanders) 2.38
I have gcc 12.1 on the system path.
I used
FreeBASIC-1.09.0-win32-mingworg.7z | .zip archive - standalone package that may work better for older Win32 systems (fbc.exe)
(recently downloaded)
So this fbc.exe calls gcc.exe and ld.exe from my mingw.
So I probably have got the wrong one.

EDIT.
I tested -gen gas64 again and it crashed.
I use my quickrun app to test these things, maybe I had the wrong compiler up, but I am usually careful.
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: GCC Version requirements to compile FB

Post by SARG »

Same ld here but assembler :
GNU assembler version 2.24 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.24

I changed with assembler :
GNU assembler version 2.38 (x86_64-w64-mingw32) using BFD version (Binutils for MinGW-W64 x86_64, built by Brecht Sanders) 2.38
but also unsuccessful
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: GCC Version requirements to compile FB

Post by srvaldez »

I just built FB-1.09 with the winlibs gcc-12.1 toolchain and the crash happens in both -gen gcc and gas64
in Avata's code if you comment-out
fname = Dir(Out_Attr) '' find next name/attributes
then there's no crash but also no files are listed
Last edited by srvaldez on Jul 04, 2022 14:46, edited 1 time in total.
Post Reply