Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to run redbean on MacOS Catalina 10.15.7 #54

Closed
d-e-h-i-o opened this issue Feb 26, 2021 · 5 comments
Closed

Failed to run redbean on MacOS Catalina 10.15.7 #54

d-e-h-i-o opened this issue Feb 26, 2021 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@d-e-h-i-o
Copy link

d-e-h-i-o commented Feb 26, 2021

Hi,

I could not make the redbean server work on my MacOS Catalina 10.15.7 with a 2,2 GHz Dual-Core Intel Core i7, after adding files via zip.

I tried the following steps:
curl https://justine.lol/redbean/redbean-latest.com >redbean.com
echo '<b>hello</b>' >index.html
zip redbean.com index.html
chmod +x redbean.com
bash -c './redbean.com -vv'
and I get
[1] 32656 killed ./redbean.com

Unfortunately I don't know how to find out the RIP address. Running the unmodified binary works great, though.

When adding a jpg, I get a different error message.

curl https://justine.lol/redbean/redbean-latest.com >redbean.com
zip redbean.com some_image.jpg
chmod +x redbean.com
bash -c './redbean.com -vv'

    error: Uncaught SIGSEGV on MacBook-Air
    /Users/x/y/readbean/redbean.com
    ENOSYS/err=78/errno:2/GetLastError:0

    6fffffffecf0 0000004228e9 UNKNOWN
    6fffffffff80 00000040a2f1 UNKNOWN
    6fffffffffc0 0000004027f3 UNKNOWN
    6fffffffffe0 000000402a21 UNKNOWN
    7ffeefbff990 00000040227b UNKNOWN

    RAX ffffffffffffffea RBX 0000000000000002 RDI 0000000000000000 ST(0) -nan
    RCX 0000000000000000 RDX fffffffffffeffea RSI 0000000000000000 ST(1) -nan
    RBP 00006fffffffff80 RSP 00006ffffffffe78 RIP 00000000004228e9 ST(2) 0.000000
    R8 0000000000000003 R9 0000000000000000 R10 0000000000000011 ST(3) 0.000000
    R11 0000000000000296 R12 0000000000000004 R13 00007ffeefbff9c8 ST(4) 0.000000
    R14 0000100080070000 R15 00007ffeefbff9a0 CF VF AF IF PE

    XMM0 00000000000000004152750020000000 XMM8 00000001c6e415960000000154442bd4
    XMM1 0000001400000000ffffffffffff8f80 XMM9 c7ffff0c992785596d9b49152a4acc1a
    XMM2 00000000ffffffff00000000ffffffff XMM10 00000000000000000000000000000000
    XMM3 0000000000000000ff00000000000000 XMM11 00000000000000000000000000000000
    XMM4 00000000000000000000000000000000 XMM12 00000000000000000000000000000000
    XMM5 00000000e29ed9b33e8a30a710b5f380 XMM13 00000000000000000000000000000000
    XMM6 302e322e334d2c544445355453450a01 XMM14 00000000000000000000000000000000
    XMM7 01c0c7ffff00009ebaffff0201020102 XMM15 00000000000000000000000000000000

    mm->i == 5;
    mm->p[ 0]=={0x10008000,0x10008000}; /* 1 /
    mm->p[ 1]=={0x10008001,0x10008004}; / 4 /
    mm->p[ 2]=={0x10008005,0x10008006}; / 2 /
    mm->p[ 3]=={0x10008007,0x1000800a}; / 4 /
    / 1,610,579,941 /
    mm->p[ 4]=={0x6ffffff0,0x6fffffff}; / 16 /
    / 27 frames mapped w/ 1,610,579,941 frames gapped */

    ./redbean.com -vv

Any idea what went wrong?

@pverghese
Copy link

pverghese commented Feb 26, 2021

Same error.
Dmesg the only log i found for redbean is:

[166563.139703] traps: redbean.com[1446960] general protection fault ip:423002 sp:6ffffffff4e0 error:0 in redbean.com[400000+2a000]

OS: Ubuntu 20.1 Linux kernel - 5.8.0-43-generic

@nalmeida
Copy link

Same error no MacOS 10.13.6

@smaccona
Copy link

Same on MacOS Mojave 10.14.6:

$ ./redbean.com -vv
W2021-02-26T07:27:10.790739:tool/net/redbean.c:1144:redbean-2021-02-25:43350] setsockopt(server, IPPROTO_TCP, TCP_FASTOPEN, &yes, sizeof(yes)) → EINVAL/err=22/errno:22/GetLastError:0
W--------------------000012:tool/net/redbean.c:1145:redbean-2021-02-25:43350] setsockopt(server, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes)) → ENOPROTOOPT/err=42/errno:42/GetLastError:0
V--------------------000011:tool/net/redbean.c:1166:redbean-2021-02-25:43350] 0.0.0.0:8080 listen
D2021-02-26T07:27:13.347579:tool/net/redbean.c:1128:redbean-2021-02-25:43352] 127.0.0.1:58322 accept
V--------------------001005:tool/net/redbean.c:940:redbean-2021-02-25:43352] 127.0.0.1:58322 GET /tool/net/redbean.html referer 
^CV2021-02-26T07:27:36.167375:tool/net/redbean.c:1183:redbean-2021-02-25:43350] 0.0.0.0:8080 terminated
D2021-02-26T07:27:36.167393:tool/net/redbean.c:1112:redbean-2021-02-25:43352] 127.0.0.1:58322 terminated
D--------------------000010:tool/net/redbean.c:1130:redbean-2021-02-25:43352] 127.0.0.1:58322 close
W--------------------000141:tool/net/redbean.c:466:redbean-2021-02-25:43350] 0.0.0.0:8080 server killed
$ echo '<html><body><b>hello</b></body></html>' >index.html
$ zip redbean.com index.html 
  adding: index.html (deflated 18%)
$ ./redbean.com -vv
Killed: 9

Not sure if it's to do with the version of zip:

$ zip -v
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.
Currently maintained by E. Gordon.  Please send bug reports to
the authors using the web page at www.info-zip.org; see README for details.

Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip,
as of above date; see http://www.info-zip.org/ for other sites.

Compiled with gcc 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14) for Unix (Mac OS X) on Feb 22 2019.

Zip special compilation options:
	USE_EF_UT_TIME       (store Universal Time)
	SYMLINK_SUPPORT      (symbolic links supported)
	LARGE_FILE_SUPPORT   (can read and write large files on file system)
	ZIP64_SUPPORT        (use Zip64 to store large files in archives)
	STORE_UNIX_UIDs_GIDs (store UID/GID sizes/values using new extra field)
	UIDGID_16BIT         (old Unix 16-bit UID/GID extra field also used)
	[encryption, version 2.91 of 05 Jan 2007] (modified for Zip 3)

Encryption notice:
	The encryption code of this program is not copyrighted and is
	put in the public domain.  It was originally written in Europe
	and, to the best of our knowledge, can be freely distributed
	in both source and object forms from any country, including
	the USA under License Exception TSU of the U.S. Export
	Administration Regulations (section 740.13(e)) of 6 June 2002.

Zip environment options:
             ZIP:  [none]
          ZIPOPT:  [none]

@jart
Copy link
Owner

jart commented Feb 27, 2021

Thanks for filing this report. I've fixed this issue in 218ef49 and pushed a new binary release here: https://justine.lol/redbean/index.html I'm marking this as a duplicate of #68 for posterity since it was an impactful issue.

@jart jart closed this as completed Feb 27, 2021
@jart jart added the duplicate This issue or pull request already exists label Feb 27, 2021
jart added a commit that referenced this issue Feb 28, 2021
Here's why we got those `Killed: 11` failures on MacOS after modifying
the contentns of the redbean.com executable. If you were inserting a
small file, such as a HelloWorld.html file, then InfoZIP might have
decreased the size of the executable to less than what the Mach-O
section had been expecting.

That's because when zipobj.com put things like time zone data in the
executable, it aligned each zip file entry on a 64-byte boundary, simply
for the sake of readability in binary dumps. But when InfoZIP edited the
file it would rewrite every entry using ZIP's usual 2-byte alignment.
Thus causing shrinkage.

The solution was to reconfigure the linker script so that zip file bits
that get put into the executable at link-time, such as timezone data,
aren't officially part of the executable image, i.e. we don't want the
operating system to load that part.

The original decision to put the linked zip files into the .data section
was mostly made so that when the executable was run in its .com.dbg form
it would still have the zip entries be accessible, even though there was
tons of GNU debug data following the central directory. We're not going
to be able to do that. The .com executable should be the canonical
executable. We have really good tools for automatically attaching and
configuring GDB correctly with debug symbols even when the .com is run.
We'll have to rely on those in cases where zip embedding is used.

See #53
See #54
See #68
@smaccona
Copy link

smaccona commented Mar 1, 2021

Confirmed this works as documented for me now. @jart your work is remarkable - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

5 participants