jemalloc / jemalloc

http://jemalloc.net/
Other
9.54k stars 1.45k forks source link

"Error allocating TSD for " in constructor on iOS #608

Open michaeleiselsc opened 7 years ago

michaeleiselsc commented 7 years ago

I've built it with:

./configure armv7 --build x86_64 --host=arm-apple-darwin10 --target=aarch64-apple-darwin CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang EXTRA_CFLAGS='-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk' EXTRA_LDFLAGS='-arch arm64'

When I run JEMalloc, I get an error with the following stack trace:

#0  0x000000018514b014 in __pthread_kill ()
#1  0x0000000185213450 in pthread_kill ()
#2  0x00000001850bf400 in abort ()
#3  0x00000001000a88f8 in je_tsd_boot1 [inlined] at /Users/michael/Developer/jemalloc/include/jemalloc/internal/tsd.h:687
#4  0x00000001000a88e8 in je_malloc_tsd_boot1 at /Users/michael/Developer/jemalloc/src/tsd.c:126
#5  0x000000010008f034 in malloc_init_hard [inlined] at /Users/michael/Developer/jemalloc/src/jemalloc.c:1512
#6  0x000000010008ef7c in malloc_init [inlined] at /Users/michael/Developer/jemalloc/src/jemalloc.c:317
#7  0x000000010008ecc4 in jemalloc_constructor at /Users/michael/Developer/jemalloc/src/jemalloc.c:2801
#8  0x00000001001e995c in ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) ()
#9  0x00000001001e9b84 in ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) ()
#10 0x00000001001e4f2c in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) ()
#11 0x00000001001e3f50 in ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) ()
#12 0x00000001001e4004 in ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) ()
#13 0x00000001001d6488 in dyld::initializeMainExecutable() ()
#14 0x00000001001da8f4 in dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) ()
#15 0x00000001001d5044 in _dyld_start ()

And it simply prints <jemalloc>: Error allocating TSD for

Any ideas what might be wrong? Thanks.

michaeleiselsc commented 7 years ago

I see, I can still have #import "jemalloc.h" at the top of my file, but once I declare any function using a JEMalloc function, e.g.:

void myFunc()
{
    je_malloc(2);
}

I get the error.

michaeleiselsc commented 7 years ago

Hmm I see that my target was strange in that case, so I had the target match the host and be arm-apple-darwin10. It still encounters the same problem, though.

victorporof commented 7 years ago

@michaeleiselsc Did you manage to figure out how to build on iOS?

michaeleisel commented 7 years ago

Still no luck

davidtgoldblatt commented 7 years ago

We don't have the ability to test on iOS, so I think we likely won't be able to debug this on our end. I think the next step would be to look into why the allocation is failing, with a debugger (preferably building at the head of dev).

michaelfairley commented 7 years ago

This appears to have been fixed by 498856f44a30b31fe713a18eb2fc7c6ecf3a9f63.

michaeleisel commented 7 years ago

Cool! I'll give it another look then

xionghengheng commented 6 years ago
ignoring file src/zone.pic.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x0C 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): src/zone.pic.o
Undefined symbols for architecture x86_64:
  "_je_free", referenced from:
      operator delete(void*) in jemalloc_cpp.pic.o
      operator delete[](void*) in jemalloc_cpp.pic.o
      operator delete(void*, std::nothrow_t const&) in jemalloc_cpp.pic.o
      operator delete[](void*, std::nothrow_t const&) in jemalloc_cpp.pic.o
  "_je_malloc", referenced from:
      operator new(unsigned long) in jemalloc_cpp.pic.o
      operator new[](unsigned long) in jemalloc_cpp.pic.o
      operator new(unsigned long, std::nothrow_t const&) in jemalloc_cpp.pic.o
      operator new[](unsigned long, std::nothrow_t const&) in jemalloc_cpp.pic.o
      handleOOM(unsigned long, bool) in jemalloc_cpp.pic.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [lib/libjemalloc.2.dylib] Error 1

what is this error ,when i run make

michaeleisel commented 6 years ago

@xionghengheng that's because that file wasn't built for an iphone architecture, so the linker ignores it. see my comment in https://github.com/jemalloc/jemalloc/issues/1138 for help. @michaelfairley jemalloc seems to be working now on ios, i believe we can close this