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

tcmalloc incompatible with macOS Monterey? #1312

Closed
ravenAtSafe opened this issue Oct 29, 2021 · 7 comments
Closed

tcmalloc incompatible with macOS Monterey? #1312

ravenAtSafe opened this issue Oct 29, 2021 · 7 comments

Comments

@ravenAtSafe
Copy link

Previous to Monterey tcmalloc was incompatible with apps launched from the Dock. As of Monterey tcmalloc causes apps to crash even when launched from the command line. I've tried 2.7 and 2.9.1.

See also https://trac.macports.org/ticket/63242 which I assume is the same issue.

The resulting stack is pretty useless as far as I can tell, but here you go.

Process 56526 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000000000000
error: memory read failed for 0x0
Target 0: (myapp) stopped.
(lldb) thread backtrace
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000000000000
    frame #1: 0x00007ff818508bb2 libobjc.A.dylib`load_images + 1358
    frame #2: 0x000000010006341c dyld`dyld4::RuntimeState::notifyObjCInit(dyld4::Loader const*) + 170
    frame #3: 0x0000000100068bfd dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 167
    frame #4: 0x0000000100068beb dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 149
    frame #5: 0x0000000100068beb dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 149
    frame #6: 0x0000000100068beb dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 149
    frame #7: 0x0000000100068cac dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 108
    frame #8: 0x000000010007c32e dyld`dyld4::APIs::runAllInitializersForMain() + 222
    frame #9: 0x000000010005a358 dyld`dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3438
    frame #10: 0x00000001000594b4 dyld`start + 388
@natale-p
Copy link
Contributor

natale-p commented Nov 4, 2021

Confirmed with a c++ proprietary program, linked to log4cxx (https://logging.apache.org/log4cxx/latest_stable/). We're trying to set up a minimal reproducible example.

@bkirnum
Copy link

bkirnum commented Nov 4, 2021

Attached a highly simplified application which replicates the crash using log4cxx as @natale-p suggested. This simply uses log4cxx and instantiates a logger. It crashes in the registerClass method when adding an element to the map for the ClassNamePatternConverter class. This is the 11th entry being added to the map.

  1. Install log4cxx from brew, from source with the link from natale-p, etc.
  2. Uncompress on a Mac with Monterey.
  3. 'cd test/build'
  4. 'cmake ..'
  5. 'make'
  6. 'src/test'

test.zip

@bkirnum
Copy link

bkirnum commented Nov 4, 2021

An even simpler version which does not require log4cxx.

  1. Uncompress on a Mac with Monterey.
  2. 'cd test/build'
  3. 'cmake .. -DCMAKE_BUILD_TYPE=Debug'
  4. 'make'
  5. 'src/test'

test 2.zip

@natale-p
Copy link
Contributor

The root cause is a missing implementation for a macOS method that is documented as "optional" while is actually used in the code. For example, the following code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    void *ptr = malloc(128);
    printf("malloc(128) returned %p\n",ptr);
    free(ptr);
    return 0;
}

When linked with tcmalloc is crashing (see https://developer.apple.com/forums/thread/693430?answerId=695428022#695428022). With the patch proposed here (#1315) the code compiles & runs fine.

mbautin added a commit to yugabyte/yugabyte-db-thirdparty that referenced this issue Nov 23, 2021
… flags; fix min macOS version (#90)

This commit fixes 3 issues and contains various other improvements.

1. yugabyte/yugabyte-db#10533 (incorrectly using libuv from Homebrew):
- Explicitly specify libuv search path when building Cassandra C++ driver. This prevents us from using Homebrew-provided libuv even if it is installed.
- Do not allow Homebrew library paths to appear in `otool -L` output when checking dynamic libraries. This enforces that the resulting thirdparty package does not depend on any Homebrew libraries, e.g. libuv.

2. yugabyte/yugabyte-db#10448 (tcmalloc issue on macOS Monterey):
Update gperftools with a patch that fixes tcmalloc on macOS Monterey.
Upstream gperftools issue: gperftools/gperftools#1312, fix: gperftools/gperftools#1315

3. yugabyte/yugabyte-db#10661 (incorrectly setting min macOS version):
Add validation that libraries are built for the correct target version of macOS by examining the output of `otool -l`.
As part of looking into this, I found out that Boost previously did not even use the compiler and linker flags that we were providing. Fixed this by specifying the `toolset=...` parameter to b2. Also fixed Boost build on x86_64 macOS (after the arm64 commit landed, we would always specify the arm64 architecture). Another dependency that required changes was crypt_blowfish (needed to pass `-mmacosx-version-min=...` in LDFLAGS and ASFLAGS). I noticed that specifying min macOS version as 10.14 (Mojave) does not work when building for arm64, so I specified min macOS version as 11.2 there for now. Also specifying minimum macOS version does not seem to work correctly when building on macOS 10.15 (Catalina) on GitHub Actions, but works well on Big Sur (11.x) so we will look into upgrading our build workers, and we may have to release a few packages manually.

Other improvements: 
- Specify patch_strip as 1 by default so we don't have to specify it everywhere.
- Add a --force flag to rebuild dependencies even if the system thinks it does not need to based on "stamp" files.
- Add a --delete-build-dir to delete a dependency's build directory before attempting to build that dependency.
- Always rebuild dependencies if the build directory is missing.
- Generate convenient shell scripts allowing to re-run CMake builds manually.
- Expand the "patch marker" file naming format to include the number of patches.
- Remove unused test data for compiler version detection (we are now using the https://pypi.org/project/compiler-identification/ module).
- The redis_cli dependency used to have custom logic to patch how libhiredis refers to itself on macOS. This patching belongs in hiredis.py, and we have a standard implementation for it (fix_shared_library_references) so the custom code from redis_cli.py is being deleted.
@natale-p
Copy link
Contributor

Hello, the issue is not in compiling, but when executing with the tcmalloc library.

zchovan added a commit to zchovan/kudu that referenced this issue Jan 25, 2022
Starting with Monterey protobuf related build actions fail due to a
missing implementation of free_definite_size in tc_malloc for OSX.

Upstream issue and fix:
gperftools/gperftools#1312
gperftools/gperftools#1315
gperftools/gperftools@852fb6d

Added new patchfile for gperftools and changed download-thirdparty.sh
accordingly.
asfgit pushed a commit to apache/kudu that referenced this issue Jan 25, 2022
Starting with Monterey protobuf related build actions fail due to a
missing implementation of free_definite_size in tc_malloc for OSX.

Upstream issue and fix:
gperftools/gperftools#1312
gperftools/gperftools#1315
gperftools/gperftools@852fb6d

Added new patchfile for gperftools and changed download-thirdparty.sh
accordingly.

Change-Id: Iae7719b233083616e21e5822d4f682efc324ec40
Reviewed-on: http://gerrit.cloudera.org:8080/18172
Reviewed-by: Attila Bukor <abukor@apache.org>
Tested-by: Attila Bukor <abukor@apache.org>
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
@alk
Copy link
Contributor

alk commented May 31, 2022

I assume 852fb6d has fixed the issue ?

@alk
Copy link
Contributor

alk commented Jul 9, 2023

Closing for now. Please reopen if you're still having trouble.

@alk alk closed this as completed Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@alk @natale-p @ravenAtSafe @bkirnum and others