Zig Version
affects both 0.15.2 and 0.16.0-dev.1484+d0ba6642b
Steps to Reproduce and Observed Behavior
I have the following files:
// main.zigexternfnfoo()callconv(.c)void;pubfnmain()void{foo();}
and
// foo.cxx
#include <QApplication>#include <QWidget>
static char *argv[] = { nullptr };
static int argc = 0;
extern "C" void
foo(void)
{
QApplication qapp(argc, argv);
QWidget win;
win.setWindowTitle("hello world");
win.show();
qapp.exec();
}
Compiling on my amd64 Arch Linux machine with zig build-exe -lc++ $(pkg-config --cflags --libs Qt6Widgets) main.zig foo.cxx results in a segfault when running the program:
Segmentation fault at address 0x0
???:?:?: 0x0 in ??? (???)
Unwind error at address `???:0x0` (unwind info unavailable), remaining frames may be incorrect
/home/doclic/zig-bureport/main.zig:4:8: 0x115c3a2 in main (main.zig)
foo();
^
/usr/lib/zig/lib/std/start.zig:705:22: 0x115bfa6 in callMain (std.zig)
root.main();
^
../sysdeps/nptl/libc_start_call_main.h:58:16: 0x7fdb74c27634 in __libc_start_call_main (../sysdeps/x86/libc-start.c)
../csu/libc-start.c:360:3: 0x7fdb74c276e8 in __libc_start_main_impl (../sysdeps/x86/libc-start.c)
???:?:?: 0x1177154 in ??? (???)
Aborted (core dumped)
However, it works fine if I build with -fllvm.
With GDB, I can see that this comes from the procedure linkage table, when trying to jump to the Qt function it segfaults because the address stored in the global offset table (at _ZN12QApplicationC1ERiPPci@got.plt) is 0.
Weirdly enough, I've tried with other libraries, and they all work, Qt6 is the only one that breaks.
Expected Behavior
No segmentation fault and a window opening up
### Zig Version
affects both 0.15.2 and 0.16.0-dev.1484+d0ba6642b
### Steps to Reproduce and Observed Behavior
I have the following files:
```zig
// main.zig
extern fn foo() callconv(.c) void;
pub fn main() void {
foo();
}
```
and
```cxx
// foo.cxx
#include <QApplication>
#include <QWidget>
static char *argv[] = { nullptr };
static int argc = 0;
extern "C" void
foo(void)
{
QApplication qapp(argc, argv);
QWidget win;
win.setWindowTitle("hello world");
win.show();
qapp.exec();
}
```
Compiling on my amd64 Arch Linux machine with `zig build-exe -lc++ $(pkg-config --cflags --libs Qt6Widgets) main.zig foo.cxx` results in a segfault when running the program:
```
Segmentation fault at address 0x0
???:?:?: 0x0 in ??? (???)
Unwind error at address `???:0x0` (unwind info unavailable), remaining frames may be incorrect
/home/doclic/zig-bureport/main.zig:4:8: 0x115c3a2 in main (main.zig)
foo();
^
/usr/lib/zig/lib/std/start.zig:705:22: 0x115bfa6 in callMain (std.zig)
root.main();
^
../sysdeps/nptl/libc_start_call_main.h:58:16: 0x7fdb74c27634 in __libc_start_call_main (../sysdeps/x86/libc-start.c)
../csu/libc-start.c:360:3: 0x7fdb74c276e8 in __libc_start_main_impl (../sysdeps/x86/libc-start.c)
???:?:?: 0x1177154 in ??? (???)
Aborted (core dumped)
```
However, it works fine if I build with `-fllvm`.
With GDB, I can see that this comes from the procedure linkage table, when trying to jump to the Qt function it segfaults because the address stored in the global offset table (at `_ZN12QApplicationC1ERiPPci@got.plt`) is 0.
Weirdly enough, I've tried with other libraries, and they all work, Qt6 is the only one that breaks.
### Expected Behavior
No segmentation fault and a window opening up