Skip to content
New issue

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

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

Already on GitHub? # to your account

Update README-mac.md #963

Merged
merged 1 commit into from
Dec 21, 2024
Merged

Update README-mac.md #963

merged 1 commit into from
Dec 21, 2024

Conversation

tshu-w
Copy link
Contributor

@tshu-w tshu-w commented Dec 19, 2024

Add instruction to install from HomeBrew directly.

Additional Info

Currently, the official HomeBrew formula doesn't not support working with emacs-rime, but this customize formula work.

Here, effort/help is needed to make the official formula with depends_on work.

Add instruction to install from homebrew directly.
@lotem
Copy link
Member

lotem commented Dec 20, 2024

Why not working?
Let's prioritize fixing the bug, instead of documenting work-arounds.

Maybe not working due to this bug:
#964

@tshu-w tshu-w marked this pull request as draft December 20, 2024 05:19
@tshu-w
Copy link
Contributor Author

tshu-w commented Dec 20, 2024

The difference is using dynamic linking with depend_on (official formula) or static linking with make deps workaround formula?

I have little knowledge about this, so I raised this draft PR to draw attention to see if anyone can help to fix this issue.

@ksqsf
Copy link
Member

ksqsf commented Dec 20, 2024

All crash stacktraces look like this

  * frame #0: 0x0000000134943f9d libtcmalloc.4.dylib`tcmalloc::Log(tcmalloc::LogMode, char const*, int, tcmalloc::LogItem, tcmalloc::LogItem, tcmalloc::LogItem, tcmalloc::LogItem) + 541
    frame #1: 0x000000013493fa9d libtcmalloc.4.dylib`(anonymous namespace)::InvalidFree(void*) + 106
    frame #2: 0x00007ff817a96f9e CoreFoundation`_CFRelease + 1243
    frame #3: 0x00007ff81751ed42 libobjc.A.dylib`AutoreleasePoolPage::releaseUntil(objc_object**) + 186
    frame #4: 0x00007ff81751c05a libobjc.A.dylib`objc_autoreleasePoolPop + 235
    frame #5: 0x00007ff81798e8a5 CoreFoundation`_CFAutoreleasePoolPop + 22
    frame #6: 0x00007ff8189b5a87 Foundation`-[NSAutoreleasePool release] + 131
    frame #7: 0x00000001002415f9 emacs`ns_read_socket_1(terminal=<unavailable>, hold_quit=0x00007ff7bfefc8f0, no_release=NO) at nsterm.m:4834:4
    frame #8: 0x00000001000f2310 emacs`gobble_input at keyboard.c:7919:17
    frame #9: 0x00000001000f26a5 emacs`process_pending_signals at keyboard.c:8158:19
    frame #10: 0x00000001000f26a0 emacs`process_pending_signals at keyboard.c:8172:3
    frame #11: 0x000000010017c614 emacs`probably_quit at eval.c:1794:5
    frame #12: 0x00000001001797a9 emacs`Ffuncall [inlined] maybe_quit at lisp.h:3946:5
    frame #13: 0x0000000100179787 emacs`Ffuncall(nargs=3, args=(struct Lisp_Symbol *) $8 = 0x00007ff8c0782730) at eval.c:3076:3
    frame #14: 0x00000001001b44f8 emacs`module_funcall(env=0x00007ff7bfefdbb8, func=<unavailable>, nargs=2, args=0x00007ff7bfefcaf8) at emacs-module.c:682:44
    frame #15: 0x00000001290d76f8 librime-emacs.dylib`emacs_defun(env=0x00007ff7bfefdbb8, rime=0x00000001357345a0, cfunc=0x00000001290d6c90, func_name="rime-lib-version", doc="Version", min=0, max=0) at lib.c:450:3

Only leveldb is linked to tcmalloc.

❯ otool -L /usr/local/opt/leveldb/lib/libleveldb.1.23.0.dylib
/usr/local/opt/leveldb/lib/libleveldb.1.23.0.dylib:
	/usr/local/opt/leveldb/lib/libleveldb.1.dylib (compatibility version 1.0.0, current version 1.23.0)
	/usr/local/opt/snappy/lib/libsnappy.1.dylib (compatibility version 1.0.0, current version 1.1.10)
	/usr/local/opt/gperftools/lib/libtcmalloc.4.dylib (compatibility version 10.0.0, current version 10.16.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1700.255.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.100.2)

Break on tc_free:

* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
  * frame #0: 0x000000013490e980 libtcmalloc.4.dylib`tc_free
    frame #1: 0x000000013490e937 libtcmalloc.4.dylib`TCMallocGuard::TCMallocGuard() + 553
    frame #2: 0x0000000134922bfc libtcmalloc.4.dylib`RAW_VLOG(int, char const*, ...) (.cold.1) + 44
    frame #3: 0x00007ff81756f959 dyld`invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 241
    frame #4: 0x00007ff8175a8b69 dyld`invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 241
    frame #5: 0x00007ff81759d1e3 dyld`invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 543
    frame #6: 0x00007ff81755707b dyld`dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 249
    frame #7: 0x00007ff81759c258 dyld`dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 176
    frame #8: 0x00007ff8175a8744 dyld`dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 470
    frame #9: 0x00007ff81756f7f2 dyld`dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 150
    frame #10: 0x00007ff817575ed7 dyld`dyld4::JustInTimeLoader::runInitializers(dyld4::RuntimeState&) const + 21
    frame #11: 0x00007ff81756fb58 dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&, dyld3::Array<dyld4::Loader const*>&) const + 276
    frame #12: 0x00007ff81756fb03 dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&, dyld3::Array<dyld4::Loader const*>&) const + 191
    frame #13: 0x00007ff81756fb03 dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&, dyld3::Array<dyld4::Loader const*>&) const + 191
    frame #14: 0x00007ff81756fb03 dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&, dyld3::Array<dyld4::Loader const*>&) const + 191
    frame #15: 0x00007ff817573371 dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_0::operator()() const + 147
    frame #16: 0x00007ff81756fbec dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 90
    frame #17: 0x00007ff817586753 dyld`dyld4::APIs::dlopen_from(char const*, int, void*) + 1859
    frame #18: 0x00000001001b26f3 emacs`Fmodule_load(file=(struct Lisp_String *) $4 = 0x00007fb9b281fdc0) at emacs-module.c:1201:12

Debug prints from dyld:

dyld[18688]: <9231638B-67DD-3C16-953C-0BA0D1730AA7> /Users/user/.emacs.d/elpa/rime-20241211.808/librime-emacs.dylib
dyld[18688]: <2604B5F8-98DE-3B4E-9DB9-AF645B863E4D> /usr/local/Cellar/librime/1.12.0/lib/librime.1.12.0.dylib
dyld[18688]: <22DFE32D-2078-3D42-9998-664FE0ED3008> /usr/local/Cellar/glog/0.6.0/lib/libglog.0.6.0.dylib
dyld[18688]: <A37BED3C-CB1D-399F-AFCD-AF82058E1493> /usr/local/Cellar/yaml-cpp/0.8.0/lib/libyaml-cpp.0.8.0.dylib
dyld[18688]: <A9545E5C-58C2-3967-A1F8-FB71F293FA9F> /usr/local/Cellar/gflags/2.2.2/lib/libgflags.2.2.2.dylib
dyld[18688]: <D3C695FB-1AC5-3AE8-831B-4F15759C3EF8> /usr/local/Cellar/leveldb/1.23_1/lib/libleveldb.1.23.0.dylib
dyld[18688]: <3F5254E1-7995-377A-A410-D33A60BF3625> /usr/local/Cellar/marisa/0.2.6/lib/libmarisa.0.dylib
dyld[18688]: <9D1C9FDC-44C4-312A-A6FF-DCA4D42A62E0> /usr/local/Cellar/opencc/1.1.9/lib/libopencc.1.1.9.dylib
dyld[18688]: <626398A4-88F6-3B18-B581-07632736C792> /usr/local/Cellar/snappy/1.2.1/lib/libsnappy.1.2.1.dylib
dyld[18688]: <33F156EB-956D-3EE8-A928-49A329973A42> /usr/local/Cellar/gperftools/2.16/lib/libtcmalloc.4.dylib
dyld[18688]: libtcmalloc.4.dylib has weak-def (or flat lookup) symbol used by libgflags.2.2.2.dylib, so cannot be delayed
dyld[18688]: libgflags.2.2.2.dylib has weak-def (or flat lookup) symbol used by libglog.0.6.0.dylib, so cannot be delayed
dyld[18688]: libtcmalloc.4.dylib has weak-def (or flat lookup) symbol used by libglog.0.6.0.dylib, so cannot be delayed
dyld[18688]: libtcmalloc.4.dylib has weak-def (or flat lookup) symbol used by libyaml-cpp.0.8.0.dylib, so cannot be delayed
dyld[18688]: libtcmalloc.4.dylib has weak-def (or flat lookup) symbol used by libsnappy.1.2.1.dylib, so cannot be delayed
dyld[18688]: libtcmalloc.4.dylib has weak-def (or flat lookup) symbol used by libleveldb.1.23.0.dylib, so cannot be delayed
dyld[18688]: librime.1.12.0.dylib has weak-def (or flat lookup) symbol used by libmarisa.0.dylib, so cannot be delayed
dyld[18688]: libtcmalloc.4.dylib has weak-def (or flat lookup) symbol used by libmarisa.0.dylib, so cannot be delayed
dyld[18688]: librime.1.12.0.dylib has weak-def (or flat lookup) symbol used by libopencc.1.1.9.dylib, so cannot be delayed
dyld[18688]: libtcmalloc.4.dylib has weak-def (or flat lookup) symbol used by libopencc.1.1.9.dylib, so cannot be delayed
dyld[18688]: libtcmalloc.4.dylib has weak-def (or flat lookup) symbol used by librime.1.12.0.dylib, so cannot be delayed
src/tcmalloc.cc:309] Attempt to free invalid pointer 0x6000022b0ee0
Fatal error 4: Illegal instruction
src/tcmalloc.cc:309] Attempt to free invalid pointer 0x6000022b0f50
src/tcmalloc.cc:309] Attempt to free invalid pointer 0x60000092cb00

It's likely due to the leveldb depending on tcmalloc.

edit: For reference, Debian's libleveldb does not depend on libtcmalloc so I consider this a packaging error by Homebrew. Introduced here. Please consider reporting this to Homebrew.

@tshu-w tshu-w marked this pull request as ready for review December 21, 2024 13:20
@tshu-w
Copy link
Contributor Author

tshu-w commented Dec 21, 2024

Thanks to @ksqsf for the information, this issue has been fixed by homebrew, and now librime can be installed directly through Homebrew. 🎉

@ksqsf ksqsf merged commit 3a8ed90 into rime:master Dec 21, 2024
10 checks passed
@Godalin
Copy link

Godalin commented Jan 23, 2025

I use MacOS. Can I just install librime from homebrew and use emacs-rime in Emacs directly? Do I have to set the related rime-librime-root variable now if I install librime from homebrew? If true, I am not sure where the root is.

@tshu-w
Copy link
Contributor Author

tshu-w commented Jan 23, 2025

I use MacOS. Can I just install librime from homebrew and use emacs-rime in Emacs directly? Do I have to set the related rime-librime-root variable now if I install librime from homebrew? If true, I am not sure where the root is.

The rime-librime-root should be /opt/homebrew if you are using M series CPU, i.e.,

(setq rime-librime-root "/opt/homebrew")

Or you can link /opt/homebrew/lib to the default location /usr/local/lib and you don't need to set rime-librime-root

λ ls -l /usr/local
total 0
lrwxr-xr-x 1 root wheel  17 Sep 30 21:47 bin -> /opt/homebrew/bin
lrwxr-xr-x 1 root wheel  21 Dec  9 16:58 include -> /opt/homebrew/include
lrwxr-xr-x 1 root wheel  17 Dec  9 16:52 lib -> /opt/homebrew/lib
lrwxr-xr-x 1 root wheel  18 Dec  9 16:52 sbin -> /opt/homebrew/sbin
lrwxr-xr-x 1 root wheel  19 Dec  9 16:52 share -> /opt/homebrew/share

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants