can you spot the problem?

General FreeBASIC programming questions.
srvaldez
Posts: 1892
Joined: Sep 25, 2005 21:54

can you spot the problem?

Postby srvaldez » Jan 15, 2019 15:41

trying to compile FB in macOS Mojave gives the following error (the runtime libraries build ok)

Code: Select all

make FBFLAGS="-asm att" ENABLE_XQUARTZ=1 compiler
FBC src/compiler/obj/fb.o
src/compiler/obj/fb.c:1362:2: error: indirect goto in function with no address-of-label expressions
        goto *vr$4;
        ^
src/compiler/obj/fb.c:2512:3: error: indirect goto in function with no address-of-label expressions
                goto *vr$36;
                ^
src/compiler/obj/fb.c:2820:2: error: indirect goto in function with no address-of-label expressions
        goto *vr$122;
        ^
3 errors generated.
make: *** [src/compiler/obj/fb.o] Error 1

the errors occur in the sub's fbInit, fbCompile and fbIncludeFile
the source code is from a branch by TeeEmCee https://github.com/rversteegen/fbc/tree ... 8132d23bbd
I would use the latest git version but there are numerous Mac specific changes made by TeeEmCee in his branch
gcc version:
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix

Code: Select all

sub fbInit( byval ismain as integer, byval restarts as integer, byval entry as zstring ptr )
   strsetInit( @env.libs, FB_INITLIBNODES \ 4 )
   strsetInit( @env.libpaths, FB_INITLIBNODES \ 4 )

   env.restarts = restarts
   env.dorestart = FALSE

   redim infileTb( 0 to FB_MAXINCRECLEVEL-1 )

   env.includerec = 0
   env.main.proc = NULL
   env.entry = *entry

   env.opt.explicit = (env.clopt.lang = FB_LANG_FB)

   '' data type remapping
   if( env.clopt.lang <> FB_LANG_QB ) then
      '' In FB, the INTEGER keyword produces FB_DATATYPE_INTEGER
      env.lang.integerkeyworddtype = FB_DATATYPE_INTEGER

      '' In FB, both 16bit/32bit number literals are made INTEGERs,
      '' and floats are DOUBLE by default.
      env.lang.int15literaldtype = FB_DATATYPE_INTEGER
      env.lang.int16literaldtype = FB_DATATYPE_UINT
      env.lang.int31literaldtype = FB_DATATYPE_INTEGER
      env.lang.int32literaldtype = FB_DATATYPE_UINT
      if( fbIs64bit( ) ) then
         env.lang.int63literaldtype = FB_DATATYPE_INTEGER
         env.lang.int64literaldtype = FB_DATATYPE_UINT
      else
         env.lang.int63literaldtype = FB_DATATYPE_LONGINT
         env.lang.int64literaldtype = FB_DATATYPE_ULONGINT
      end if
      env.lang.floatliteraldtype = FB_DATATYPE_DOUBLE
   else
      '' In QB, the INTEGER keyword produces FB_DATATYPE_SHORT
      '' (Note: FB_DATATYPE_INTEGER remains unchanged, it's just that
      '' FB_DATATYPE_SHORT is being used instead in some places)
      env.lang.integerkeyworddtype = FB_DATATYPE_SHORT

      '' In QB, 16bit number literals are made SHORTs (i.e. QB's
      '' 16bit INTEGERs), and 32bit number literals are 32bit LONGs,
      '' not FB 32bit/64bit INTEGERs. Floats are SINGLEs by default.
      env.lang.int15literaldtype = FB_DATATYPE_SHORT
      env.lang.int16literaldtype = FB_DATATYPE_USHORT
      env.lang.int31literaldtype = FB_DATATYPE_LONG
      env.lang.int32literaldtype = FB_DATATYPE_ULONG
      env.lang.int63literaldtype = FB_DATATYPE_LONGINT
      env.lang.int64literaldtype = FB_DATATYPE_ULONGINT
      env.lang.floatliteraldtype = FB_DATATYPE_SINGLE
   end if

   env.opt.parammode       = FB_PARAMMODE_BYREF
   env.opt.procpublic      = TRUE
   env.opt.escapestr      = FALSE
   env.opt.dynamic         = FALSE
   env.opt.base = 0
   env.opt.gosub = (env.clopt.lang = FB_LANG_QB)

   env.fbctinf_started = FALSE

   '' Leading underscore needed on ASM symbols?
   '' Yes for dos/cygwin-x86/win32/xbox, but not win64/cygwin-x86_64/linux-*/etc.
   env.underscoreprefix = FALSE
   select case( env.clopt.target )
   case FB_COMPTARGET_DOS, FB_COMPTARGET_XBOX, FB_COMPTARGET_DARWIN
      env.underscoreprefix = TRUE
   case FB_COMPTARGET_CYGWIN, FB_COMPTARGET_WIN32
      env.underscoreprefix = not fbIs64bit( )
   end select

   '' set by symbDataInit()
   env.pointersize = 0

   parserSetCtx( )
   symbInit( ismain )
   errInit( )
   astInit( )
   irInit( )

   '' After symbInit(), we can use typeGetSize()
   env.wchar_doconv = (sizeof( wstring ) = typeGetSize( env.target.wchar ))

   hashInit( @env.incfilehash, FB_INITINCFILES )
   hashInit( @env.inconcehash, FB_INITINCFILES )

   stackNew( @parser.stmt.stk, FB_INITSTMTSTACKNODES, len( FB_CMPSTMTSTK ), FALSE )
   lexInit( FALSE )
   parserInit( )
   rtlInit( )
end sub

the generated C code is, (I added the line numbers)

Code: Select all

1351 void FBINIT( int64 ISMAIN$1, int64 RESTARTS$1, uint8* ENTRY$1 )
1352 {
1353    int64 TMP$132$1;
1354    label$20:;
1355    STRSETINIT( (struct $7TSTRSET*)((uint8*)&ENV$ + 1432ll), 5ll );
1356    STRSETINIT( (struct $7TSTRSET*)((uint8*)&ENV$ + 1520ll), 5ll );
1357 *(int64*)((uint8*)&ENV$ + 1416ll) = RESTARTS$1;
1358    *(int64*)((uint8*)&ENV$ + 1424ll) = 0ll;
1359    int32 vr$2 = fb_ArrayRedimEx( (struct $7FBARRAYIvE*)&INFILETB$, 296ull, -1, 0, 1ull, 0ll, 15ll );
1360    if( (int64)vr$2 == 0ll ) goto label$22;
1361    void* vr$4 = fb_ErrorThrowAt( 308, (uint8*)"src/compiler/fb.bas", (void*)0ull, (void*)0ull );
1362 goto *vr$4;
   label$22:;
   *(int64*)((uint8*)&ENV$ + 1136ll) = 0ll;
   *(struct $8FBSYMBOL**)((uint8*)&ENV$ + 1272ll) = (struct $8FBSYMBOL*)0ull;
   fb_StrAssign( (void*)((uint8*)&ENV$ + 1144ll), 128ll, (void*)ENTRY$1, 0ll, 0 );
   *(int64*)((uint8*)&ENV$ + 1376ll) = (int64)-(*(int64*)((uint8*)&ENV$ + 272ll) == 0ll);
   if( *(int64*)((uint8*)&ENV$ + 272ll) == 3ll ) goto label$24;
   {
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1296ll) = 8ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1304ll) = 8ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1312ll) = 9ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1320ll) = 8ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1328ll) = 9ll;
      int64 vr$7 = FBIS64BIT(  );
      if( vr$7 == 0ll ) goto label$26;
      {
         *($11FB_DATATYPE*)((uint8*)&ENV$ + 1336ll) = 8ll;
         *($11FB_DATATYPE*)((uint8*)&ENV$ + 1344ll) = 9ll;
      }
      goto label$25;
      label$26:;
      {
         *($11FB_DATATYPE*)((uint8*)&ENV$ + 1336ll) = 13ll;
         *($11FB_DATATYPE*)((uint8*)&ENV$ + 1344ll) = 14ll;
      }
      label$25:;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1352ll) = 16ll;
   }
   goto label$23;
   label$24:;
   {
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1296ll) = 5ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1304ll) = 5ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1312ll) = 6ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1320ll) = 11ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1328ll) = 12ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1336ll) = 13ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1344ll) = 14ll;
      *($11FB_DATATYPE*)((uint8*)&ENV$ + 1352ll) = 15ll;
   }
   label$23:;
   *(int64*)((uint8*)&ENV$ + 1368ll) = 2ll;
   *(int64*)((uint8*)&ENV$ + 1384ll) = -1ll;
   *(int64*)((uint8*)&ENV$ + 1392ll) = 0ll;
   *(int64*)((uint8*)&ENV$ + 1400ll) = 0ll;
   *(int64*)((uint8*)&ENV$ + 1360ll) = 0ll;
   *(int64*)((uint8*)&ENV$ + 1408ll) = (int64)-(*(int64*)((uint8*)&ENV$ + 272ll) == 3ll);
   *(int64*)((uint8*)&ENV$ + 1608ll) = 0ll;
   *(int64*)((uint8*)&ENV$ + 472ll) = 0ll;
   {
      $13FB_COMPTARGET TMP$131$2;
      TMP$131$2 = *($13FB_COMPTARGET*)((uint8*)&ENV$ + 216ll);
      if( TMP$131$2 == 3ll ) goto label$29;
      label$30:;
      if( TMP$131$2 == 4ll ) goto label$29;
      label$31:;
      if( TMP$131$2 != 7ll ) goto label$28;
      label$29:;
      {
         *(int64*)((uint8*)&ENV$ + 472ll) = -1ll;
      }
      goto label$27;
      label$28:;
      if( TMP$131$2 == 1ll ) goto label$33;
      label$34:;
      if( TMP$131$2 != 0ll ) goto label$32;
      label$33:;
      {
         int64 vr$9 = FBIS64BIT(  );
         *(int64*)((uint8*)&ENV$ + 472ll) = ~vr$9;
      }
      label$32:;
      label$27:;
   }
   *(int64*)((uint8*)&ENV$ + 480ll) = 0ll;
   PARSERSETCTX(  );
   SYMBINIT( ISMAIN$1 );
   ERRINIT(  );
   ASTINIT(  );
   IRINIT(  );
   if( (*(int64*)((uint8*)&ENV$ + 432ll) & 480ll) == 0ll ) goto label$35;
   TMP$132$1 = 23ll;
   goto label$36;
   label$35:;
   TMP$132$1 = *(int64*)((uint8*)&ENV$ + 432ll) & 31ll;
   label$36:;
   *(int64*)((uint8*)&ENV$ + 464ll) = (int64)-(*(int64*)(((uint8*)SYMB_DTYPETB$ + (TMP$132$1 * 56ll)) + 8ll) == 4ll);
   HASHINIT( (struct $5THASH*)((uint8*)&ENV$ + 1088ll), 256ll, 0ll );
   HASHINIT( (struct $5THASH*)((uint8*)&ENV$ + 1112ll), 256ll, 0ll );
   STACKNEW( (struct $6TSTACK*)&PARSER$, 128ll, 176ll, 0ll );
   LEXINIT( 0ll );
   PARSERINIT(  );
   RTLINIT(  );
   label$21:;
}
srvaldez
Posts: 1892
Joined: Sep 25, 2005 21:54

Re: can you spot the problem?

Postby srvaldez » Jan 15, 2019 19:49

never mind, it's a bug in Apple's LLVM gcc
St_W
Posts: 1464
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: can you spot the problem?

Postby St_W » Jan 16, 2019 6:28

how did you fix it / work around it?

btw it would be nice if you could document the build process on macos like for the other OSes in our wiki. Macos is probably not ready for tge wiki yet, but when it'll be integrated in fbc's master it'd be nice to already have some docs for the wiki.
srvaldez
Posts: 1892
Joined: Sep 25, 2005 21:54

Re: can you spot the problem?

Postby srvaldez » Jan 16, 2019 9:58

hello St_W
what I did was to build just the compiler in macOS High Sierra and the runtime libs in macOS Mojave, this is certainly only a temporary solution until Apple fixes the llvm gcc compiler.
presently I am using X11 for the graphics but I don't know how long that will continue, I believe that TeeEmCee is using allegro and he is infinitely more skilled and knowledgeable than me, perhaps he will chime in and explain his build process.
my build process is: make FBFLAGS="-asm att" ENABLE_XQUARTZ=1 compiler in macOS High Sierra
and make FBFLAGS="-asm att" ENABLE_XQUARTZ=1 rtlib gfxlib2 in macOS Mojave
counting_pine
Site Admin
Posts: 6166
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: can you spot the problem?

Postby counting_pine » Jan 16, 2019 13:21

How did you find out it was a bug in the Mojave compiler?
I had a look and found this Pastebin compiling fbc in 2016 (https://pastebin.com/CTEWiacJ), but not much else.
srvaldez
Posts: 1892
Joined: Sep 25, 2005 21:54

Re: can you spot the problem?

Postby srvaldez » Jan 16, 2019 13:43

@counting_pine
I just went by this information here http://lists.llvm.org/pipermail/llvm-bu ... 32475.html
it seems to be a reoccurring bug.
counting_pine
Site Admin
Posts: 6166
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: can you spot the problem?

Postby counting_pine » Jan 16, 2019 21:02

Hmm, apparently that bug hasn't been touched since 2014.. https://bugs.llvm.org/show_bug.cgi?id=18658
That's a few years before High Sierra.

Without looking deeply, I guess it's the Redim line that probably has some error handling associated, and it's causing a potential jump to a computed label - i.e. whichever 'On Error Goto label' was last set, if any - in case of Redim failing.
jtiai
Posts: 1
Joined: Mar 20, 2019 7:02

Re: can you spot the problem?

Postby jtiai » Mar 20, 2019 18:26

How do you even compile the compiler itself. I managed to build runtime libs just fine but running make compiler I just get:

Code: Select all

$ make FBFLAGS="-asm att" ENABLE_XQUARTZ=1 compiler
FBC src/compiler/obj/ast-gosub.o
/bin/sh: fbc: command not found
make: *** [src/compiler/obj/ast-gosub.o] Error 127


Did I missed some step?

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests