Cross compiling glib-2.74.0 to qnx 7.0

Hello

I have cross compiled glib-2.74.0 to qnx 7.0 using the qnx gcc 5.4 cross compiler.
So far so good. But, when I compile a small test program that links to glib (it doesn’t use anything in glib, just linking) and run it on my qnx target I get a segmentation fault before the main method is invoked

Process 10940512 (DemoExe) terminated SIGSEGV code=1 fltno=11 ip=0000000100053df3(/usr/lib/ldqnx-64.so.2@_dl_debug_state+0x0000000000001893) mapaddr=0000000000053df3. ref=0000000000000008
Memory fault (core dumped)

I have had a thorough look at config and build logs, and nothing smells funny there.
My cross file looks like this:

[host_machine]
system = 'qnx'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'

[properties]
growing_stack = false
pkg_config_path = '/path_to_my_pc_files'

[binaries]
c = '/my_toolchain_dir/qnx700/host/linux/x86_64/usr/bin/ntox86_64-gcc'
cpp = '/my_toolchain_dir/qnx700/host/linux/x86_64/usr/bin/ntox86_64-g++'
ar = '/my_toolchain_dir/qnx700/host/linux/x86_64/usr/bin/ntox86_64-ar'
ld = '/my_toolchain_dir/qnx700/host/linux/x86_64/usr/bin/ntox86_64-ld'
objcopy = 'None'
strip = '/my_toolchain_dir/qnx700/host/linux/x86_64/usr/bin/ntox86_64-strip'
windres = 'windres'

Could this be a static initialization problem as the main method is never reached?
Any help or hints would be much appreciated.

Rgds
Klaus

Probably someone more knowledgable than me can give you a comprehensive answer; anyway, from what I can tell, the issue may be related to __attribute__(constructor) functions defined inside GLib.

Here’s a quick grep:

$ grep -rn --exclude-dir=".git" gconstructor.h
docs/reference/glib/meson.build:36:    'gconstructor.h',
gio/giomodule.c:76:#include "gconstructor.h"
gio/meson.build:933:    input : ['data-to-c.py', files('../glib/gconstructor.h')],
gio/tests/resources.c:24:#include "gconstructor.h"
glib/gconstructor-private.h:30:#include "gconstructor.h"
glib/gconstructor.h:62: * so that items using gconstructor.h outside of GLib (such as
glib/glib-init.c:28:#include "gconstructor.h"
gobject/gobject.c:38:#include "gconstructor.h"
gobject/gtype.c:37:#include "gconstructor.h"
NEWS:656: - !2487 gconstructor.h: Visual Studio: Only include gslist.h if needed
NEWS:3130: - !791 glib/gconstructor.h: Include stdlib.h for MSVC builds

Apart from ancillary files and tests, constructors are used in:

I’d start by commenting out the constructors one by one and test if your program runs.

@lb90, thanks for your suggestion.

Tried generating static glib libs and linking those to my test application, and it works fine.
So something is not right with generating glib dynamic libs.

This indicates to me that this is not an issue with static initialization or…?

Rgds

This indicates to me that this is not an issue with static initialization or…?

I guess so, yes.

Out of curiosity, are you linking with all of the shared libraries provided by GLib (glib, gobject, gio, gmodule, gthread), or just glib? Also, did you ever test with previous versions of GLib?

This could be an issue with the QNX loader, as the crash seems to happen in ldqnx-64.so