zlmediakit 在 aarch64 编译 遇到 Segmentation fault（核心已转储）
> 系统版本：openEuler 24.03 (LTS-SP1) aarch64 > 前提 在安装流程编译完zlmediakit 之后运行 .\MediaServer.exe -d 提示 Segmentation fault（核心已转储） 提示 Segmentation fault（核心已转储） 后面开始排查： #### 1. 开启 core dump ulimit -c unlimited #### 2. 查看 core 生成方式 cat /proc/sys/kernel/core_pattern #### 3. 前台运行看日志 ./MediaServer #### 4. 若有 core 文件 gdb ./MediaServer core #### 5. 若用 systemd-coredump coredumpctl list coredumpctl debug ./MediaServer ###交给模型分析 ```shell [root@service3 Debug]# coredumpctl debug 2601134 PID: 2601134 (MediaServer) UID: 0 (root) GID: 0 (root) Signal: 11 (SEGV) Timestamp: Tue 2025-12-23 09:17:45 CST (2min 34s ago) Command Line: ./MediaServer Executable: /www/spy/ZLMediaKit/release/linux/Debug/MediaServer Control Group: /user.slice/user-0.slice/session-18053.scope Unit: session-18053.scope Slice: user-0.slice Session: 18053 Owner UID: 0 (root) Boot ID: 61b92c204f12426c963ee1299b6544e1 Machine ID: 718781f979de4f48b1806e83960ef003 Hostname: service3 Storage: /var/lib/systemd/coredump/core.MediaServer.0.61b92c204f12426c963ee1299b6544e1.2601134.1766452665000000.lz4 (present) Size on Disk: 290.0K Message: Process 2601134 (MediaServer) of user 0 dumped core. GNU gdb (GDB) openEuler 14.1-3.oe2403sp1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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 "aarch64-openEuler-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /www/spy/ZLMediaKit/release/linux/Debug/MediaServer... [New LWP 2601134] [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib64/libthread_db.so.1". Core was generated by `./MediaServer'. Program terminated with signal SIGSEGV, Segmentation fault. #0 extent_arena_get (extent=0xffffffff94407000) at include/jemalloc/internal/atomic.h:55 warning: 55 include/jemalloc/internal/atomic.h: No such file or directory Missing separate debuginfos, use: dnf debuginfo-install glibc-2.38-47.oe2403sp1.aarch64 libgcc-12.3.1-64.oe--Type for more, q to quit, c to continue without paging-- 2403sp1.aarch64 libstdc++-12.3.1-64.oe2403sp1.aarch64 openssl-libs-3.0.12-15.oe2403sp1.aarch64 zlib-1.2.13-4.oe2403sp1.aarch64 (gdb) bt #0 extent_arena_get (extent=0xffffffff94407000) at include/jemalloc/internal/atomic.h:55 #1 extent_can_coalesce (outer=0xffffffff94407000, inner=0xffff94407080, extents=, arena=0xffff94400980) at src/extent.c:1310 #2 extent_try_coalesce (tsdn=tsdn@entry=0xffff953897b0, arena=arena@entry=0xffff94400980, r_extent_hooks=r_extent_hooks@entry=0xffffe074dc08, rtree_ctx=rtree_ctx@entry=0xffff953897d0, extents=extents@entry=0xffff944033c8, extent=extent@entry=0xffff94407080, coalesced=coalesced@entry=0x0, growing_retained=) at src/extent.c:1401 #3 0x0000ffff9511238c in extent_record (tsdn=tsdn@entry=0xffff953897b0, arena=arena@entry=0xffff94400980, r_extent_hooks=r_extent_hooks@entry=0xffffe074dc08, extents=extents@entry=0xffff944033c8, extent=0xffff94407080, growing_retained=true) at src/extent.c:1448 #4 0x0000ffff95112b5c in extent_grow_retained (tsdn=tsdn@entry=0xffff953897b0, arena=arena@entry=0xffff94400980, r_extent_hooks=r_extent_hooks@entry=0xffffe074dc08, size=size@entry=28672, pad=pad@entry=4096, alignment=alignment@entry=64, slab=slab@entry=false, szind=szind@entry=39, zero=zero@entry=0xffffe074dc6f, commit=commit@entry=0xffffe074dc07) at src/extent.c:1145 #5 0x0000ffff9511412c in extent_alloc_retained (commit=0xffffe074dc07, zero=0xffffe074dc6f, szind=39, slab=false, alignment=64, pad=4096, size=28672, new_addr=0x0, r_extent_hooks=0xffffe074dc08, arena=0xffff94400980, tsdn=0xffff953897b0) at src/extent.c:1238 #6 je_extent_alloc_wrapper (tsdn=tsdn@entry=0xffff953897b0, arena=arena@entry=0xffff94400980, r_extent_hooks=r_extent_hooks@entry=0xffffe074dc08, new_addr=new_addr@entry=0x0, size=size@entry=28672, pad=pad@entry=4096, alignment=alignment@entry=64, slab=slab@entry=false, szind=szind@entry=39, zero=zero@entry=0xffffe074dc6f, commit=commit@entry=0xffffe074dc07) --Type for more, q to quit, c to continue without paging-- at src/extent.c:1296 #7 0x0000ffff950f2758 in je_arena_extent_alloc_large (tsdn=tsdn@entry=0xffff953897b0, arena=arena@entry=0xffff94400980, usize=usize@entry=28672, alignment=64, zero=zero@entry=0xffffe074dc6f) at src/arena.c:527 #8 0x0000ffff95115d04 in je_large_palloc (tsdn=0xffff953897b0, arena=, usize=28672, alignment=, zero=) at src/large.c:47 #9 0x0000ffff95124788 in ipallocztm (arena=, is_internal=true, tcache=0x0, zero=true, alignment=64, usize=, tsdn=0xffff953897b0) at include/jemalloc/internal/jemalloc_internal_inlines_c.h:58 #10 je_tsd_tcache_data_init (tsd=tsd@entry=0xffff953897b0) at src/tcache.c:388 #11 0x0000ffff95124ee0 in je_tsd_tcache_enabled_data_init (tsd=tsd@entry=0xffff953897b0) at src/tcache.c:339 #12 0x0000ffff95125e5c in tsd_data_init (tsd=0xffff953897b0) at src/tsd.c:74 #13 je_tsd_fetch_slow (tsd=0xffff953897b0, minimal=) at src/tsd.c:121 #14 0x0000ffff95125fb0 in tsd_fetch_impl (minimal=false, init=true) at include/jemalloc/internal/tsd.h:263 #15 tsd_fetch () at include/jemalloc/internal/tsd.h:289 #16 je_malloc_tsd_boot0 () at src/tsd.c:256 #17 0x0000ffff950e8180 in malloc_init_hard () at src/jemalloc.c:1469 #18 0x0000ffff950e9740 in malloc_init () at src/jemalloc.c:216 #19 imalloc (dopts=, sopts=) at src/jemalloc.c:1927 #20 malloc (size=72704) at src/jemalloc.c:1977 #21 0x0000ffff94a5ea08 in ?? () from /usr/lib64/libstdc++.so.6 #22 0x0000ffff9536a65c in ?? () from /lib/ld-linux-aarch64.so.1 --Type for more, q to quit, c to continue without paging--info registers #23 0x0000ffff9536a754 in ?? () from /lib/ld-linux-aarch64.so.1 #24 0x0000ffff9537f4b8 in ?? () from /lib/ld-linux-aarch64.so.1 (gdb) info registers x0 0xffffffff94407000 -1807716352 x1 0x0 0 x2 0x0 0 x3 0x20d565b2bf87ea62 2365908997645003362 x4 0xffff95389760 281473185257312 x5 0x1490 5264 x6 0xea46c429a730de46 -1565348137286967738 x7 0x1377330e14c12fe2 1402645944519962594 x8 0x20d565b2afed58bb 2365908997383215291 x9 0x178 376 x10 0xffbb60f9eee728a1 -19315146821785439 x11 0xea46c429d213bc52 -1565348136567456686 x12 0xffbb60f9913a98dd -19315148393375523 x13 0x0 0 x14 0x0 0 x15 0x1 1 x16 0x1 1 x17 0x27ffff94407000 11258997260709888 x18 0x465bceb23a17cff9 5069873070409764857 x19 0xffff94407080 281473168994432 x20 0xffff944033c8 281473168978888 x21 0xffff953897b0 281473185257392 x22 0x0 0 --Type for more, q to quit, c to continue without paging-- x23 0xc4ceb9fe1a85ec53 -4265267296055464877 x24 0xff51afd7ed558ccd -49064778989728563 x25 0xffff953897d0 281473185257424 x26 0xffff94400980 281473168968064 x27 0xffffffff94407000 -1807716352 x28 0xffff95150500 281473182926080 x29 0xffffe074d640 281474447496768 x30 0xffff95111ef8 281473182670584 sp 0xffffe074d640 0xffffe074d640 pc 0xffff95111f00 0xffff95111f00 cpsr 0x60001000 [ EL=0 BTYPE=0 SSBS C Z ] fpsr 0x0 [ ] fpcr 0x0 [ Len=0 Stride=0 RMode=0 ] tpidr 0xffff95389760 0xffff95389760 tpidr2 0x0 0x0 (gdb) ``` ### 初步判断是： > ZLMediaKit 静态链接了 jemalloc，但与 openEuler 24.03 的 glibc 或内核存在兼容性问题 ZLMediaKit 默认会 内置编译并链接自己的 jemalloc（位于 3rdpart/jemalloc 子模块） 而 openEuler 24.03 使用较新的 glibc 2.38 + 内核 6.x，对内存布局、ASLR、指针加密（PAC）等有更严格要求 旧版 jemalloc（尤其是 ZLMediaKit 自带的版本）在 aarch64 + 新系统上可能因指针对齐、原子操作或虚拟地址假设错误而崩溃 #### 解决方法： > 修改 CMakeLists.txt 强制跳过 jemalloc 编辑 /ZLMediaKit/CMakeLists.txt，找到类似这段代码 ```shell find_library(JEMALLOC_LIBRARIES NAMES jemalloc) if(JEMALLOC_LIBRARIES) message(STATUS "found library: ${JEMALLOC_LIBRARIES}") message(STATUS "jemalloc will be used to avoid memory fragmentation") target_link_libraries(${PROJECT_NAME} PRIVATE ${JEMALLOC_LIBRARIES}) endif() ``` #### 注释掉或删除整个 if(JEMALLOC_LIBRARIES) 块： ```shell # find_library(JEMALLOC_LIBRARIES NAMES jemalloc) # if(JEMALLOC_LIBRARIES) # message(STATUS "found library: ${JEMALLOC_LIBRARIES}") # message(STATUS "jemalloc will be used to avoid memory fragmentation") # target_link_libraries(${PROJECT_NAME} PRIVATE ${JEMALLOC_LIBRARIES}) # endif() ``` #### 然后重新 cmake + make。 重新编译之后可正常运行。