Skip to content

Commit

Permalink
fix(x11/firefox): fix Segmentation fault in the command "firefox -hea…
Browse files Browse the repository at this point in the history
…dless"

Fixes termux#22286

Bypasses the unstable codepath by disabling
`MOZ_HAS_REMOTE`, which does not seem to negatively affect the
existing X11 behavior, only fixes the command `firefox -headless`; I
am not 100% sure that someone else does not need that feature, but
disabling it fixes `firefox -headless` and does not seem to break
anything obvious that I have noticed from browsing with the X11 mode
for a few minutes

This patch is a dependency of my project, "How To Run Node.js
Puppeteer On Android" https://gist.github.com/robertkirkman/0c2f3426024069546ed9b7bb2f26cb99.
Which is a fully functional example of a Javascript program that
invokes the system call `firefox -headless` through the Puppeteer
library.
I am hoping to possibly upstream the patch part of the necessary code
for the headless mode on Termux of the Firefox backend of the Puppeteer Node.js
library by submitting this PR.
  • Loading branch information
robertkirkman committed Nov 16, 2024
1 parent 7ab7f49 commit d549541
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 1 deletion.
242 changes: 242 additions & 0 deletions x11-packages/firefox/0028-fix-headless-mode.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
Fixes:
~ $ gdb --args firefox -headless
GNU gdb (GDB) 15.2
Copyright (C) 2024 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 "aarch64-linux-android".
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 firefox...
(gdb) run
Starting program: /data/data/com.termux/files/usr/bin/firefox -headless
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/data/data/com.termux/files/usr/lib/libthread_db.so".
warning: section .note.gnu.build-id not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .dynsym not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .gnu.version not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .gnu.version_d not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .gnu.hash not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .dynstr not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .rela.plt not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .eh_frame_hdr not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .eh_frame not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .plt not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .dynamic not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .got.plt not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .bss not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libdl.so
warning: section .note.android.ident not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .note.gnu.build-id not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .dynsym not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .gnu.version not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .gnu.version_d not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .gnu.version_r not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .gnu.hash not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .dynstr not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .rela.dyn not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .relr.dyn not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .rela.plt not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .rodata not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .eh_frame_hdr not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .eh_frame not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .plt not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .data.rel.ro not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .fini_array not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .dynamic not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .got not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .got.plt not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .data not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .bss not found in .gnu_debugdata for /apex/com.android.runtime/lib64/bionic/libm.so
warning: section .note.android.ident not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .note.gnu.build-id not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .dynsym not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .gnu.version not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .gnu.version_r not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .gnu.hash not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .dynstr not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .rela.dyn not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .relr.dyn not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .rela.plt not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .rodata not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .eh_frame_hdr not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .eh_frame not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .plt not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .data.rel.ro not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .fini_array not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .dynamic not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .got not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .got.plt not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .data not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .bss not found in .gnu_debugdata for /system/lib64/libnetd_client.so
warning: section .note.android.ident not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .note.gnu.build-id not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .dynsym not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .gnu.version not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .gnu.version_r not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .gnu.hash not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .dynstr not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .rela.dyn not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .relr.dyn not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .rela.plt not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .rodata not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .gcc_except_table not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .eh_frame_hdr not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .eh_frame not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .plt not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .data.rel.ro not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .fini_array not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .init_array not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .dynamic not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .got not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .got.plt not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .data not found in .gnu_debugdata for /system/lib64/libc++.so
warning: section .bss not found in .gnu_debugdata for /system/lib64/libc++.so
[New Thread 0x3391 (LWP 13201)]
[Thread 0x3391 (LWP 13201) exited]
warning: section .note.android.ident not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .note.gnu.build-id not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .dynsym not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .gnu.version not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .gnu.version_d not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .gnu.version_r not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .gnu.hash not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .dynstr not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .rela.dyn not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .relr.dyn not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .rela.plt not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .rodata not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .eh_frame_hdr not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .eh_frame not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .plt not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .data.rel.ro not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .fini_array not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .init_array not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .dynamic not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .got not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .got.plt not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .data not found in .gnu_debugdata for /system/lib64/liblog.so
warning: section .bss not found in .gnu_debugdata for /system/lib64/liblog.so
[New Thread 0x3394 (LWP 13204)]
*** You are running in headless mode.
[New Thread 0x3397 (LWP 13207)]
[Detaching after fork from child process 13208]
[New Thread 0x3399 (LWP 13209)]
[New Thread 0x339a (LWP 13210)]
[New Thread 0x339b (LWP 13211)]
[New Thread 0x339c (LWP 13212)]
[New Thread 0x339d (LWP 13213)]
[New Thread 0x339e (LWP 13214)]
[New Thread 0x339f (LWP 13215)]
[New Thread 0x33a0 (LWP 13216)]
[New Thread 0x33a1 (LWP 13217)]
[New Thread 0x33a2 (LWP 13218)]
[New Thread 0x33a3 (LWP 13219)]
[New Thread 0x33a4 (LWP 13220)]
[New Thread 0x33a5 (LWP 13221)]
[Thread 0x33a5 (LWP 13221) exited]
[New Thread 0x33a6 (LWP 13222)]
[New Thread 0x33a7 (LWP 13223)]
[New Thread 0x33a8 (LWP 13224)]
[New Thread 0x33a9 (LWP 13225)]
[New Thread 0x33aa (LWP 13226)]
[New Thread 0x33ab (LWP 13227)]
[New Thread 0x33ac (LWP 13228)]
[New Thread 0x33ad (LWP 13229)]
[New Thread 0x33ae (LWP 13230)]
[New Thread 0x33af (LWP 13231)]
[New Thread 0x33b0 (LWP 13232)]
[New Thread 0x33b1 (LWP 13233)]
[New Thread 0x33b2 (LWP 13234)]
[New Thread 0x33b3 (LWP 13235)]
[Thread 0x33a7 (LWP 13223) exited]
[New Thread 0x33b4 (LWP 13236)]
[New Thread 0x33b5 (LWP 13237)]
[New Thread 0x33b6 (LWP 13238)]
[New Thread 0x33b7 (LWP 13239)]
[New Thread 0x33b8 (LWP 13240)]
[New Thread 0x33b9 (LWP 13241)]
[New Thread 0x33ba (LWP 13242)]
[New Thread 0x33bb (LWP 13243)]
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: Unable to open a connection to the X server (t=18.4544) [GFX1-]: glxtest: Unable to open a connection to the X server
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: Unable to open a connection to the X server (t=18.4544) |[1][GFX1-]: No GPUs detected via PCI
(t=18.4544) [GFX1-]: No GPUs detected via PCI

[New Thread 0x33bc (LWP 13244)]
[New Thread 0x33bd (LWP 13245)]
[New Thread 0x33be (LWP 13246)]
[New Thread 0x33bf (LWP 13247)]
[New Thread 0x33c0 (LWP 13248)]
[New Thread 0x33c1 (LWP 13249)]
[New Thread 0x33c2 (LWP 13250)]
[New Thread 0x33c3 (LWP 13251)]
[New Thread 0x33c4 (LWP 13252)]
[New Thread 0x33c5 (LWP 13253)]
[New Thread 0x33c6 (LWP 13254)]
[New Thread 0x33c7 (LWP 13255)]
[New Thread 0x33c8 (LWP 13256)]
[New Thread 0x33c9 (LWP 13257)]
[New Thread 0x33ca (LWP 13258)]
[New Thread 0x33cb (LWP 13259)]
[New Thread 0x33cc (LWP 13260)]
[New Thread 0x33cd (LWP 13261)]
[New Thread 0x33ce (LWP 13262)]
[New Thread 0x33cf (LWP 13263)]
[Detaching after fork from child process 13264]
[New Thread 0x33d4 (LWP 13268)]

Thread 1 "firefox" received signal SIGSEGV, Segmentation fault.
0x0000007d23985fd8 in XInternAtoms ()
from /data/data/com.termux/files/usr/lib/libX11.so
(gdb) bt
#0 0x0000007d23985fd8 in XInternAtoms ()
from /data/data/com.termux/files/usr/lib/libX11.so
#1 0x0000007d0ccdcc58 in nsXRemoteServer::EnsureAtoms (
this=0xb400007dda853ed0)
at /home/builder/.termux-build/firefox/src/toolkit/components/remote/nsXRemoteServer.cpp:150
#2 nsXRemoteServer::XRemoteBaseStartup (this=0xb400007dda853ed0,
aAppName=0xb400007dca8434c8 "firefox-default",
aProfileName=0xb400007e1a845338 "/data/data/com.termux/files/home/.mozilla/firefox/r8c88s3d.default-default")
at /home/builder/.termux-build/firefox/src/toolkit/components/remote/nsXRemoteServer.cpp:60
#3 0x0000007d0ccda7b0 in nsGTKRemoteServer::Startup (this=0x0,
aAppName=0x7d0eeeec30 <XAtomNames> "48\357\a}",
aProfileName=0x7 <error: Cannot access memory at address 0x7>)
at /home/builder/.termux-build/firefox/src/toolkit/components/remote/nsGTKRemoteServer.cpp:39
#4 0x0000007d0ccdb0b0 in nsRemoteService::StartupServer (
this=0xb400007e2a84abc0)
at /home/builder/.termux-build/firefox/src/toolkit/components/remote/nsRemoteService.cpp:189
#5 0x0000007d0cef5d9c in XREMain::XRE_mainRun (
this=this@entry=0x7fffffd8b0)
at /home/builder/.termux-build/firefox/src/toolkit/xre/nsAppRunner.cpp:5744
#6 0x0000007d0cef66c4 in XREMain::XRE_main (
this=this@entry=0x7fffffd8b0, argc=argc@entry=2,
argv=argv@entry=0x7fffffeb88, aConfig=...)
at /home/builder/.termux-build/firefox/src/toolkit/xre/nsAppRunner.cpp:6034
#7 0x0000007d0cef6b04 in XRE_main (argc=250539056, argv=0x7, aConfig=...)
at /home/builder/.termux-build/firefox/src/toolkit/xre/nsAppRunner.cpp:6106
#8 0x0000005555579f6c in do_main (argc=2, argv=0x7fffffeb88,
envp=<optimized out>)
at /home/builder/.termux-build/firefox/src/browser/app/nsBrowserApp.cpp:233
#9 main (argc=2, argv=0x7fffffeb88, envp=<optimized out>)
at /home/builder/.termux-build/firefox/src/browser/app/nsBrowserApp.cpp:470
(gdb)
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -2714,8 +2714,8 @@ def has_remote(toolkit):
return True


-set_config("MOZ_HAS_REMOTE", has_remote)
-set_define("MOZ_HAS_REMOTE", has_remote)
+#set_config("MOZ_HAS_REMOTE", has_remote)
+#set_define("MOZ_HAS_REMOTE", has_remote)

# RLBox Library Sandboxing wasm support
# ==============================================================
2 changes: 1 addition & 1 deletion x11-packages/firefox/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TERMUX_PKG_DESCRIPTION="Mozilla Firefox web browser"
TERMUX_PKG_LICENSE="MPL-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION="131.0.3"
TERMUX_PKG_REVISION=1
TERMUX_PKG_REVISION=2
TERMUX_PKG_SRCURL=https://archive.mozilla.org/pub/firefox/releases/${TERMUX_PKG_VERSION}/source/firefox-${TERMUX_PKG_VERSION}.source.tar.xz
TERMUX_PKG_SHA256=7a7df3f97737453efaa243ca9dbaf95d0f0f833c5dc8afacb5704ee16ef060d0
# ffmpeg and pulseaudio are dependencies through dlopen(3):
Expand Down

0 comments on commit d549541

Please sign in to comment.