4 ms·
I would like the see the source code for libmymalloc.so, however, I don't see anything in the blog post. Nor do I see anything in his GitHub profile: https://g
by throwaway2037 8mo ago
I would like the see the source code for libmymalloc.so, however, I don't see anything in the blog post. Nor do I see anything in his GitHub profile: https://github.com/jsikstro https://github.com/jsikstro
Also, I cannot find his email address anywhere (to ask him to share it on GitHub).
Am I missing something?
- joelsiks 8mo agoThe exact implementation of mymalloc isn't relevant to the post. I have an old allocator published at https://github.com/joelsiks/jsmalloc https://github.com/joelsiks/jsmalloc that I did as part of my Master's thesis, which uses a similar debug-logging mechanism that is described in the post.
- nly 8mo agodlsym() with the RTLD_NEXT flag basically: https://catonmat.net/simple-ld-preload-tutorial-part-two https://catonmat.net/simple-ld-preload-tutorial-part-two There's actually a better way to hook GNUs malloc: https://www.man7.org/linux/man-pages/man3/malloc_hook.3.html https://www.man7.org/linux/man-pages/man3/malloc_hook.3.html This is better because you can disable the hook inside the callback, and therefore use malloc within your malloc hook (no recursion) But you can't use this mechanism before main()
- Joker_vD 8mo agoThe use of these hook functions is not safe in multithreaded programs, and they are now deprecated. From glibc 2.24 onwards, the __malloc_initialize_hook variable has been removed from the API, and from glibc 2.34 onwards, all the hook variables have been removed from the API. Programmers should instead preempt calls to the relevant functions by defining and exporting malloc(), free(), realloc(), and calloc().
- nly 8mo agoYeah. Shame though because it gave you the option to control exactly when you hooked and didn't hook, which let stop and start debugging allocations based on arbitrary triggers. The global variable approach was very useful and pretty low overhead.
- jeffbee 8mo agoIf you only wanted to observe the behavior the post is discussing, it seems like `ltrace -e malloc` is a lot easier.
- fweimer 8mo agoYou can still override malloc and call __libc_malloc if you do not want to bother with dlsym/RTLD_NEXT. These function aliases are undocumented, but for a quick experiment, that shouldn't matter.