Gas64 (no more use of gcc, only gas) WDS / LNX

User projects written in or related to FreeBASIC.
Post Reply
dodicat
Posts: 8157
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by dodicat »

The labels are defined then undefined many times in the macro, (in the for loop 100000 times).
Labels can be defined then undefined in gas or gcc (32 and 64) bits.

However variables (in my macro) can only be defined then undefined in gas (32 and 64)
Gcc throws an error if undefining variables.

So, I was wondering if defining and undefining labels many times is OK, since none of the fb compilers complain about it.
The whole point of the exercise is to make a macro as self sufficient as possible, allowing goto (and gosub) and labels inside them.
I can scope off variables of course, or do something like :.

Code: Select all

#cmdline "-gen gas64"

#macro MyMacro(commence,limit,result)
#define finish finishlabel
#define start startlabel

#if __FB_BACKEND__ = "gas64"
dim as long x
dim as string acc
#else

#ifndef x
dim as long x
#endif

#ifndef acc
dim as string acc
#endif

#endif
    x=commence
    acc=""
	  start:
      do
      acc+=str(x)+" "
      x+=1
     if abs(x) <=limit then goto start else goto finish
 loop
finish:
result=acc
#undef startlabel
#undef finishlabel

#if __FB_BACKEND__ = "gas64"
#undef x
#undef acc
#endif

#endmacro

'==================================
dim as string z,g

for n as long=1 to 100000
MyMacro(n,0,g)
z+= g
next n
print z
print
MyMacro(8,30,g)
print g
MyMacro(56,60,g)
print g
print "backend "; __FB_BACKEND__


Sleep
  
Of course if fb had generics . . .
SARG
Posts: 1833
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

dodicat wrote: Nov 01, 2022 13:02 The labels are defined then undefined many times in the macro, (in the for loop 100000 times).
Look at the preprocessed code (with your first example) you'll not see many defined/undefined.

Code: Select all

dim as string z,g

for n as long=1 to 100000
 scope
 dim as long x=n
 g=""
 startlabel:
 do
 g+=str(x)+" "
 x+=1
 if abs(x) <=0 then goto startlabel else goto finishlabel
 loop
 end scope
 finishlabel:
#undef startlabel
#undef finishlabel
z+= g
next
print z
print
 scope
 dim as long x=8
 g=""
 startlabel:
 do
 g+=str(x)+" "
 x+=1
 if abs(x) <=30 then goto startlabel else goto finishlabel
 loop
 end scope
 finishlabel:
#undef startlabel
#undef finishlabel
print g

print "end"
Sleep
coderJeff
Site Admin
Posts: 4364
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by coderJeff »

Simplified:

Code: Select all

dim x as long
#undef x
dim x as long
Errors in the GCC backend only because the internal ID is re-used (based on scope level).
All the other backends assign a unique ID. (under the hood, see hMangleVariable() and 'varcounter')
gcc backend should probably be changed since we should expect this to work.
dodicat
Posts: 8157
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by dodicat »

SARG.
In the pre processed loop, the labels don't need undefined then re defined again, but in the macro they do.
undefining and re defining is optional in the pre processed loop, but it is done many times (as in the macro)

Considering only startlabel

Code: Select all


dim as string z,g

for n as long=1 to 10
 dim as long x=n
 g=""
 
 
#ifdef startlabel
print "startlabel defined"
#else
print "startlabel undefined"
#endif

 startlabel:
 
 #ifdef startlabel
print "startlabel defined"
#else
print "startlabel undefined"
#endif
 
 do
 g+=str(x)+" "
 x+=1
 if abs(x) <=0 then goto startlabel else goto finishlabel
 loop
 finishlabel:
#undef startlabel
#undef finishlabel

z+= g
next
print z
print
sleep 
But, in the asm file, where you have your workbench, things look completely different. (as you say).

coderjeff
I suppose it would be better for all 4 compilers to behave the same.
SARG
Posts: 1833
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

@dodicat
define and undefine are only used during the compilation so labels can't be really defined/undefined during the loop execution. It's an illusion created by (asm) jumps.

Code: Select all

   #13cmp r11, 0
   cmp rax, 0 #Optim 13
   jg .L_0010
           # new branch ? .L_0010
           # emit branch = jmp/call (gosub) to .L_0009 98 jmp
   jmp .L_0009
           # emit branch = jmp/call (gosub) to .L_000F 98 jmp
   jmp .L_000F
   .L_0010:
           # emit branch = jmp/call (gosub) to .L_0011 98 jmp
   jmp .L_0011
   .L_000F:
   .L_000D:
           # emit branch = jmp/call (gosub) to .L_000B 98 jmp
   jmp .L_000B
   .L_000C:
   .L_0011:
dodicat
Posts: 8157
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by dodicat »

Yes SARG, thanks for that.
It allows using goto/gosub and labels inside macros which can be called anywhere in a program without Duplicated definition errors.
(Whatever usefulness that is??)
Xusinboy Bekchanov
Posts: 818
Joined: Jul 26, 2018 18:28

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by Xusinboy Bekchanov »

I can't compile my library with -gen gas64. Gives the following error (both fbc 1.09.0 and fbc 1.10.0):
08:04:30: Compilation: "/mnt/media/FreeBasic/FreeBASIC-1.09.0-linux-x86_64/bin/fbc" -b "mff.bas" -exx -gen gas64 -x "../libmff64_gtk3.so" -d __USE_GTK3__ -dll -v

FreeBASIC Compiler - Version 1.09.0 (2022-01-01), built for linux-x86_64 (64bit)
Copyright (C) 2004-2021 The FreeBASIC development team.
target: linux-x86_64, x86-64, 64bit
backend: gas64
compiling: mff.bas -o mff.asm (main module)
assembling: as --64 --strip-local-absolute "mff.asm" -o "mff.o"
linking: ld -m elf_x86_64 -o "../libmff64_gtk3.so" -shared -hlibmff64_gtk3.so --export-dynamic -T "/mnt/media/FreeBasic/FreeBASIC-1.09.0-linux-x86_64/bin/../lib/freebasic/linux-x86_64/fbextra.x" -L "/mnt/media/FreeBasic/FreeBASIC-1.09.0-linux-x86_64/bin/../lib/freebasic/linux-x86_64" -L "." -L "/usr/lib/gcc/x86_64-linux-gnu/10" "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/10/crtbeginS.o" "/mnt/media/FreeBasic/FreeBASIC-1.09.0-linux-x86_64/bin/../lib/freebasic/linux-x86_64/fbrt0pic.o" "mff.o" "-(" -lglib-2.0 -lgtk-3 -lgdk-3 -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lpangocairo-1.0 -latk-1.0 -lfbmtpic -ltinfo -lm -ldl -lpthread -lgcc -lgcc_eh -lc "-)" "/usr/lib/gcc/x86_64-linux-gnu/10/crtendS.o" "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o"
linking failed: 'ld' terminated with exit code 1
ld: mff.o: warning: relocation against `FILENUMBERCOUNTER$' in read-only section `.text'
ld: mff.o: relocation R_X86_64_PC32 against symbol `FILENUMBERCOUNTER$' can not be used when making a shared object; перекомпилируйте с параметром -fPIC
ld: ошибка конечной ссылки: bad value

08:04:51: found Warnings (1 Pos), Messages (3 Pos)
08:04:51: Do not build file. Elapsed Time: 21.47 Seconds
Xusinboy Bekchanov
Posts: 818
Joined: Jul 26, 2018 18:28

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by Xusinboy Bekchanov »

This compilation error is only available on Linux. On Windows it compiles correctly.
SARG
Posts: 1833
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

Thanks for the report. I'll work on that later as a bit busy on another problem.
I guess a known issue with linux relocation table, it needs the adding of @GOTPCREL. The main difficulty is to find where :D
SARG
Posts: 1833
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

@Xusinboy Bekchanov
Should be fixed.
In ir-gas64.bas / sub _emitconvert line#4329++ complete the case. Test and tell me if it's ok as there are other fixes to be integrated in the master.

Code: Select all

	case IR_VREGTYPE_VAR ''format varname ofs1   local/static  ofs1 could be zero
			if symbIsStatic(v2->sym) Or symbisshared(v2->sym) then
			'=======================
				if ctx.target=FB_COMPTARGET_LINUX andalso fbGetOption( FB_COMPOPT_OUTTYPE ) = FB_OUTTYPE_DYNAMICLIB then
					op2=*symbGetMangledName(v2->sym)+"@GOTPCREL[rip]" '[rip+"+Str(v2->ofs)+"]"
				else
					op2=*symbGetMangledName(v2->sym)+"[rip+"+Str(v2->ofs)+"]"
				end if
			'======================
			else
				op2=Str(v2->ofs)+"[rbp]"
			end if
Xusinboy Bekchanov
Posts: 818
Joined: Jul 26, 2018 18:28

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by Xusinboy Bekchanov »

SARG wrote: Dec 20, 2022 9:41 @Xusinboy Bekchanov
Should be fixed.
In ir-gas64.bas / sub _emitconvert line#4329++ complete the case. Test and tell me if it's ok as there are other fixes to be integrated in the master.

Code: Select all

	case IR_VREGTYPE_VAR ''format varname ofs1   local/static  ofs1 could be zero
			if symbIsStatic(v2->sym) Or symbisshared(v2->sym) then
			'=======================
				if ctx.target=FB_COMPTARGET_LINUX andalso fbGetOption( FB_COMPOPT_OUTTYPE ) = FB_OUTTYPE_DYNAMICLIB then
					op2=*symbGetMangledName(v2->sym)+"@GOTPCREL[rip]" '[rip+"+Str(v2->ofs)+"]"
				else
					op2=*symbGetMangledName(v2->sym)+"[rip+"+Str(v2->ofs)+"]"
				end if
			'======================
			else
				op2=Str(v2->ofs)+"[rbp]"
			end if
Thanks, now it compiles.
srvaldez
Posts: 3508
Joined: Sep 25, 2005 21:54

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by srvaldez »

hello SARG :)
this refers to the latest FB git repo
something has changed in ir-gas64.bas that causes the test in tests\functions\udt_result_call.bas to fail with
functions/udt_result_call.asm:304: Error: unsupported instruction `mov'
here's line 304
mov xmm0, eax #Optim 16
SARG
Posts: 1833
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

Hi srvaldez,

Yes an already known issue, I missed one line in a change when copying then Jeff forgot to add it before pushing the commit... ;-)
Anyway thanks for the tests and the report.

In the zip file my latest changes which will be in the next Jeff's commit. https://users.freebasic-portal.de/sarg/ ... hanges.zip
srvaldez
Posts: 3508
Joined: Sep 25, 2005 21:54

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by srvaldez »

thank you SARG :D
coderJeff
Site Admin
Posts: 4364
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by coderJeff »

@srvaldez, thank you for the quick report and testing the latest. It's nice to know you are checking the quality.

I'll try to get the changes in ASAP. ya, SARG sent me the fixes and I forgot to get them all in.
Post Reply