Skip to content

[zig cc] -target x86_64-linux-gnu makes event.so (php extension) segfault on exit handlers #24255

@henderkes

Description

@henderkes

Zig Version

0.15-dev

Steps to Reproduce and Observed Behavior

git clone https://github.com/crazywhalecc/static-php-cli.git
cd static-php-cli
export CC="zig cc -target x86_64-linux-gnu"
export SPC_LIBC=glibc
bin/spc doctor
bin/spc download -e "bcmath,event"
bin/spc build "bcmath" --build-shared="event" --enable-zts --build-cli --build-embed --no-strip 

useful gdb info (?)

[m@M-TH pkg-config]$ gdb --args /home/m/static-php-cli/buildroot/bin/php -n -d extension_dir=/home/m/static-php-cli/buildroot/modules -d extension=event --ri event
gdb: warning: error finding working directory: No such file or directory
GNU gdb (AlmaLinux Kitten) 14.2-4.el10
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/m/static-php-cli/buildroot/bin/php...
warning: File "/home/m/static-php-cli/buildroot/bin/php" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
        add-auto-load-safe-path /home/m/static-php-cli/buildroot/bin/php
line to your configuration file "/home/m/.config/gdb/gdbinit".
To completely disable this security protection add
        set auto-load safe-path /
line to your configuration file "/home/m/.config/gdb/gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
        info "(gdb)Auto-loading safe path"
(gdb) break __run_exit_handlers
Function "__run_exit_handlers" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (__run_exit_handlers) pending.
(gdb) run
Starting program: /home/m/static-php-cli/buildroot/bin/php -n -d extension_dir=/home/m/static-php-cli/buildroot/modules -d extension=event --ri event
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

event

Event support => enabled
Sockets support => disabled
Debug support => disabled
Extra functionality support including HTTP, DNS, and RPC => enabled
OpenSSL support => enabled
Thread safety support => disabled
Extension version => 3.0.8
libevent2 headers version => 2.1.12-stable

Breakpoint 1, __run_exit_handlers (status=0, listp=0x7ffff7f02680 <__exit_funcs>,
    run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:38
38      {
(gdb) set $funcs = (struct exit_function_list *) 0x7ffff7f02680
(gdb) p *$funcs
$1 = {next = 0x7ffff7f03fc0 <initial>, idx = 140737353087776, fns = {{flavor = 0, func = {at = 0x0, on = {fn = 0x0,
          arg = 0x7ffff7f02030 <randtbl+16>}, cxa = {fn = 0x0, arg = 0x7ffff7f02030 <randtbl+16>,
          dso_handle = 0x7ffff7f02024 <randtbl+4>}}}, {flavor = 140737353097252, func = {at = 0x1f00000003, on = {
          fn = 0x1f00000003, arg = 0x3}, cxa = {fn = 0x1f00000003, arg = 0x3,
          dso_handle = 0x7ffff7f020a0 <pa_next_type>}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0},
        cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0},
        cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0},
        cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0},
        cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0},
        cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0},
        cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0},
        cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0,
          arg = 0x7ffff7f01248 <_IO_wfile_jumps>}, cxa = {fn = 0x0, arg = 0x7ffff7f01248 <_IO_wfile_jumps>,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x7ffff7f01248 <_IO_wfile_jumps>},
        cxa = {fn = 0x0, arg = 0x7ffff7f01248 <_IO_wfile_jumps>, dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0,
        on = {fn = 0x0, arg = 0xfbad2088}, cxa = {fn = 0x0, arg = 0xfbad2088, dso_handle = 0x0}}}, {flavor = 0,
      func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0,
      func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0,
      func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0, dso_handle = 0x0}}}, {flavor = 0,
      func = {at = 0xffffffffffffffff, on = {fn = 0xffffffffffffffff, arg = 0x0}, cxa = {fn = 0xffffffffffffffff,
          arg = 0x0, dso_handle = 0x7ffff7f04780 <_IO_stdfile_0_lock>}}}, {flavor = -1, func = {at = 0x0, on = {
          fn = 0x0, arg = 0x7ffff7f029c0 <_IO_wide_data_0>}, cxa = {fn = 0x0, arg = 0x7ffff7f029c0 <_IO_wide_data_0>,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x7ffff7f01050 <_IO_file_jumps>, on = {
          fn = 0x7ffff7f01050 <_IO_file_jumps>, arg = 0x0}, cxa = {fn = 0x7ffff7f01050 <_IO_file_jumps>, arg = 0x0,
--Type <RET> for more, q to quit, c to continue without paging--
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}, {flavor = 0, func = {at = 0x0, on = {fn = 0x0, arg = 0x0}, cxa = {fn = 0x0, arg = 0x0,
          dso_handle = 0x0}}}}}
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) n
Program not restarted.
(gdb) continue
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7753354 in ?? ()
(gdb) bt full
#0  0x00007ffff7753354 in ?? ()
No symbol table info available.
#1  0x00007ffff7d756e0 in __run_exit_handlers (status=0, listp=0x7ffff7f02680 <__exit_funcs>,
    run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:108
        atfct = <optimized out>
        onfct = <optimized out>
        cxafct = <optimized out>
        arg = <optimized out>
        f = <optimized out>
        new_exitfn_called = 3
        cur = 0x7ffff7f03fc0 <initial>
        restart = <optimized out>
#2  0x00007ffff7d757ae in __GI_exit (status=<optimized out>) at exit.c:138
No locals.
#3  0x0000555557b26d08 in main (argc=8, argv=0x555557fc4c60)
    at /home/m/static-php-cli/source/php-src/sapi/cli/php_cli.c:1346
        c = -1
        exit_status = 0
        module_started = 1
        sapi_started = 1
        php_optarg = 0x555557fc4dd0 "d2\251\002PU"
        php_optind = 8
        use_extended_info = 0
        ini_path_override = 0x0
        ini_builder = {value = 0x555557fc8360 "x\223M\rPU", length = 183}
        ini_ignore = 1
        sapi_module = 0x555557fa1b70 <cli_sapi_module>
(gdb) info registers
rax            0x7ffff7753354      140737345041236
rbx            0x7ffff7f03fa8      140737353105320
rcx            0x1                 1
rdx            0x1                 1
rsi            0x0                 0
rdi            0x0                 0
rbp            0x7fffffffd470      0x7fffffffd470
rsp            0x7fffffffd418      0x7fffffffd418
r8             0x0                 0
r9             0x7                 7
r10            0x555557fc4c60      93825036733536
r11            0x574175876be199d1  6287435779276904913
r12            0x3                 3
r13            0x0                 0
r14            0x7ffff7f02680      140737353098880
r15            0x7ffff7f03fc0      140737353105344
rip            0x7ffff7753354      0x7ffff7753354
eflags         0x10246             [ PF ZF IF RF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
fs_base        0x7ffff7d0c880      140737351043200
gs_base        0x0                 0
(gdb) x/10i $rip
info frame
A syntax error in expression, near `info frame
'.
(gdb) x/10i $rip
=> 0x7ffff7753354:      Cannot access memory at address 0x7ffff7753354
(gdb) info frame
Stack level 0, frame at 0x7fffffffd420:
 rip = 0x7ffff7753354; saved rip = 0x7ffff7d756e0
 called by frame at 0x7fffffffd480
 Arglist at 0x7fffffffd410, args:
 Locals at 0x7fffffffd410, Previous frame's sp is 0x7fffffffd420
 Saved registers:
  rip at 0x7fffffffd418
(gdb) info proc mappings
process 1545
Mapped address spaces:

          Start Addr           End Addr       Size     Offset  Perms  objfile
      0x555555554000     0x555555a8f000   0x53b000        0x0  r--p   /home/m/static-php-cli/buildroot/bin/php
      0x555555a8f000     0x555557e9b000  0x240c000   0x53a000  r-xp   /home/m/static-php-cli/buildroot/bin/php
      0x555557e9b000     0x555557f9e000   0x103000  0x2945000  r--p   /home/m/static-php-cli/buildroot/bin/php
      0x555557f9e000     0x555557fa8000     0xa000  0x2a47000  rw-p   /home/m/static-php-cli/buildroot/bin/php
      0x555557fa8000     0x5555581c1000   0x219000        0x0  rw-p   [heap]
      0x7ffff7c11000     0x7ffff7c32000    0x21000        0x0  rw-p
      0x7ffff7c8b000     0x7ffff7cac000    0x21000        0x0  rw-p
      0x7ffff7cac000     0x7ffff7cb3000     0x7000        0x0  r--s   /usr/lib64/gconv/gconv-modules.cache
      0x7ffff7cb3000     0x7ffff7d0c000    0x59000        0x0  r--p   /usr/lib/locale/C.utf8/LC_CTYPE
      0x7ffff7d0c000     0x7ffff7d0f000     0x3000        0x0  rw-p
      0x7ffff7d0f000     0x7ffff7d12000     0x3000        0x0  r--p   /usr/lib64/libresolv.so.2
      0x7ffff7d12000     0x7ffff7d1b000     0x9000     0x3000  r-xp   /usr/lib64/libresolv.so.2
      0x7ffff7d1b000     0x7ffff7d1d000     0x2000     0xc000  r--p   /usr/lib64/libresolv.so.2
      0x7ffff7d1d000     0x7ffff7d1e000     0x1000     0xe000  r--p   /usr/lib64/libresolv.so.2
      0x7ffff7d1e000     0x7ffff7d1f000     0x1000     0xf000  rw-p   /usr/lib64/libresolv.so.2
      0x7ffff7d1f000     0x7ffff7d21000     0x2000        0x0  rw-p
      0x7ffff7d21000     0x7ffff7d22000     0x1000        0x0  r--p   /usr/lib64/libutil.so.1
      0x7ffff7d22000     0x7ffff7d23000     0x1000     0x1000  r-xp   /usr/lib64/libutil.so.1
      0x7ffff7d23000     0x7ffff7d24000     0x1000     0x2000  r--p   /usr/lib64/libutil.so.1
      0x7ffff7d24000     0x7ffff7d25000     0x1000     0x2000  r--p   /usr/lib64/libutil.so.1
      0x7ffff7d25000     0x7ffff7d28000     0x3000        0x0  rw-p
      0x7ffff7d28000     0x7ffff7d29000     0x1000        0x0  r--p   /usr/lib64/librt.so.1
      0x7ffff7d29000     0x7ffff7d2a000     0x1000     0x1000  r-xp   /usr/lib64/librt.so.1
      0x7ffff7d2a000     0x7ffff7d2b000     0x1000     0x2000  r--p   /usr/lib64/librt.so.1
      0x7ffff7d2b000     0x7ffff7d2c000     0x1000     0x2000  r--p   /usr/lib64/librt.so.1
      0x7ffff7d2c000     0x7ffff7d2d000     0x1000        0x0  rw-p
      0x7ffff7d2d000     0x7ffff7d2e000     0x1000        0x0  r--p   /usr/lib64/libdl.so.2
      0x7ffff7d2e000     0x7ffff7d2f000     0x1000     0x1000  r-xp   /usr/lib64/libdl.so.2
--Type <RET> for more, q to quit, c to continue without paging--
      0x7ffff7d2f000     0x7ffff7d30000     0x1000     0x2000  r--p   /usr/lib64/libdl.so.2
      0x7ffff7d30000     0x7ffff7d31000     0x1000     0x2000  r--p   /usr/lib64/libdl.so.2
      0x7ffff7d31000     0x7ffff7d32000     0x1000        0x0  rw-p
      0x7ffff7d32000     0x7ffff7d5a000    0x28000        0x0  r--p   /usr/lib64/libc.so.6
      0x7ffff7d5a000     0x7ffff7eb1000   0x157000    0x28000  r-xp   /usr/lib64/libc.so.6
      0x7ffff7eb1000     0x7ffff7efe000    0x4d000   0x17f000  r--p   /usr/lib64/libc.so.6
      0x7ffff7efe000     0x7ffff7f02000     0x4000   0x1cb000  r--p   /usr/lib64/libc.so.6
      0x7ffff7f02000     0x7ffff7f04000     0x2000   0x1cf000  rw-p   /usr/lib64/libc.so.6
      0x7ffff7f04000     0x7ffff7f0c000     0x8000        0x0  rw-p
      0x7ffff7f0c000     0x7ffff7f0d000     0x1000        0x0  r--p   /usr/lib64/libpthread.so.0
      0x7ffff7f0d000     0x7ffff7f0e000     0x1000     0x1000  r-xp   /usr/lib64/libpthread.so.0
      0x7ffff7f0e000     0x7ffff7f0f000     0x1000     0x2000  r--p   /usr/lib64/libpthread.so.0
      0x7ffff7f0f000     0x7ffff7f10000     0x1000     0x2000  r--p   /usr/lib64/libpthread.so.0
      0x7ffff7f10000     0x7ffff7f11000     0x1000        0x0  rw-p
      0x7ffff7f11000     0x7ffff7f21000    0x10000        0x0  r--p   /usr/lib64/libm.so.6
      0x7ffff7f21000     0x7ffff7f86000    0x65000    0x10000  r-xp   /usr/lib64/libm.so.6
      0x7ffff7f86000     0x7ffff7fbb000    0x35000    0x75000  r--p   /usr/lib64/libm.so.6
      0x7ffff7fbb000     0x7ffff7fbc000     0x1000    0xa9000  r--p   /usr/lib64/libm.so.6
      0x7ffff7fbc000     0x7ffff7fbd000     0x1000    0xaa000  rw-p   /usr/lib64/libm.so.6
      0x7ffff7fc2000     0x7ffff7fc4000     0x2000        0x0  rw-p
      0x7ffff7fc4000     0x7ffff7fc8000     0x4000        0x0  r--p   [vvar]
      0x7ffff7fc8000     0x7ffff7fca000     0x2000        0x0  r-xp   [vdso]
      0x7ffff7fca000     0x7ffff7fcb000     0x1000        0x0  r--p   /usr/lib64/ld-linux-x86-64.so.2
      0x7ffff7fcb000     0x7ffff7ff1000    0x26000     0x1000  r-xp   /usr/lib64/ld-linux-x86-64.so.2
      0x7ffff7ff1000     0x7ffff7ffb000     0xa000    0x27000  r--p   /usr/lib64/ld-linux-x86-64.so.2
      0x7ffff7ffb000     0x7ffff7ffd000     0x2000    0x31000  r--p   /usr/lib64/ld-linux-x86-64.so.2
      0x7ffff7ffd000     0x7ffff7fff000     0x2000    0x33000  rw-p   /usr/lib64/ld-linux-x86-64.so.2
      0x7ffffffdd000     0x7ffffffff000    0x22000        0x0  rw-p   [stack]
(gdb) q

Expected Behavior

Using clang and gcc, everything succeeds. I would expect zig cc to succeed, too.

debugging with gdb:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions