FB breaks when upgrading to GCC 9.x without latest binutils/ld

Linux specific questions.
TeeEmCee
Posts: 261
Joined: Jul 22, 2006 0:54
Location: Auckland

FB breaks when upgrading to GCC 9.x without latest binutils/ld

Postby TeeEmCee » Jun 24, 2019 2:13

Just a small note in case this saves anyone some time and frustration:

I just wasted about 5 hours trying to figure out why FB programs compiled with -mt (multithreading support) deadlocked after upgrading to gcc 9 even when not using the gcc emitter.
It turns out that I upgraded the gcc packages for my system but not binutils. gcc 9 requires the latest binutils 2.32 on x86/x86_64 gnu/linux (specifically, the lastest ld, which is part of binutils).

The compiling documentation for gcc (for i?86-*-linux*) says only "As of GCC 3.3, binutils 2.13.1 or later is required", so I wouldn't be surprised if some linux distros don't have binutils 2.32 listed as a requirement for gcc 9.x.

Using ld 2.31 or earlier results in FB's initialisation routine (fb_hRtInit) not running, as the startup fails to process pointers in .ctor sections**. If you compiled with -mt this leads to the mutexes not being initialised and a deadlock on the first PRINT, but in non-multithreaded programs I'm sure there's lots of breakage too. I assume ld 2.31 is incompatible with crtbegin.o from gcc 9 or something like that.

** I thought that maybe support for .ctors had finally been removed, but I found this testcase which shows it's still supported.
dkl
Site Admin
Posts: 3209
Joined: Jul 28, 2005 14:45
Location: Germany

Re: FB breaks when upgrading to GCC 9.x without latest binutils/ld

Postby dkl » Jun 28, 2019 18:20

Wow, that's unfortunate... I wonder, does the fbc test suite already have a test case that would detect this?
TeeEmCee
Posts: 261
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: FB breaks when upgrading to GCC 9.x without latest binutils/ld

Postby TeeEmCee » Jul 06, 2019 23:04

You mean a testcase that will detect whether fb_hRtInit ran or not? I don't see any existing thing to check to determine that, e.g. __fb_is_inicnt isn't a global. I didn't try running the FB testcases to diagnose my problem.
dkl
Site Admin
Posts: 3209
Joined: Jul 28, 2005 14:45
Location: Germany

Re: FB breaks when upgrading to GCC 9.x without latest binutils/ld

Postby dkl » Jul 24, 2019 19:32

Yea pretty much that. Or maybe a test that checks whether a custom module-level constructor was invoked. (unless those are emitted in different sections than fb_hRtInit)
TeeEmCee
Posts: 261
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: FB breaks when upgrading to GCC 9.x without latest binutils/ld

Postby TeeEmCee » Aug 27, 2019 8:19

Yeah, that won't work, because fb_hRtInit and module constructor functions might end up in different sections:

fbc -gen gcc translates "SUB foobar() CONSTRUCTOR" to "__attribute__(( constructor )) void FOOBAR( void )", which results in GCC 9.x putting a pointer in the .init_array section, while with fbc -gen gas (or earlier gcc), fbc puts a pointer in the .ctors section.

And (except on Darwin and Android) static/fbrt0.c contains:

Code: Select all

static void * priorityhDoInit __attribute__((section(".ctors.65435"), used)) = fb_hDoInit;


Can't remember whether .ctors or .init_array has priority or whether the runtime linker merges the lists.

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 28 guests