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

minidebuginfo support for elf #38

Closed
wants to merge 7 commits into from
Closed

Conversation

@sargarass
Copy link

@sargarass sargarass commented Mar 22, 2020

Hello, I added a minidebuginfo support for elf. Please take a look.
Here is a small example of usage with boost/stacktrace that used library as backend ( 6mb version of boost included ;) )

Also I had to create few wrappers for functions like backtrace_get_view, backtrace_release_view to accept not only filedescriptors but also already mapped to memory elf. Could go with memfd_create and just open uncompressed elf file but seems like it appered in linux 3.17.
For now the wrappers just copy any part that was asked to be viewed from uncompressed to memory elf file.

@ianlancetaylor
Copy link
Owner

@ianlancetaylor ianlancetaylor commented Mar 22, 2020

Thanks, but libbacktrace must be async-signal-safe. It's hard to be confident that that is true of an external library. On my system, liblzma is compiled with -fstack-check, which is good in general but not a good idea for async-signal-safe code. It also has references to malloc, even though it won't be called, which is troubling for a library as low-level as libbacktrace. In general I think libbacktrace will need to include an LZMA decoder, just as it already has a zlib decoder.

@sargarass
Copy link
Author

@sargarass sargarass commented Mar 22, 2020

liblzma uses user's provided allocators for memory allocation (I used wrappers for backtrace_alloc/free). In case NULL was passed it goes back to malloc & free, so i think it is the reason why does it have references to malloc. Also libunwind uses lzma like this, but maybe they dont care that much about async-safety.

Anyway will consider including lzma decoder into. Maybe it will be easy to port it directly from liblzma.

@sargarass
Copy link
Author

@sargarass sargarass commented Mar 31, 2020

@ianlancetaylor what do you think about using XZ Embedded which is used directly in the Linux kernel? It is relatively small implementation with only decompression support. It could be included as a subdirectory to libbacktrace.

edit:
For async-safety all calls to free & malloc will be changed to backtrace_alloc & backtrace_free. There is userspace/xz_config.h file that used for userspace build and can be used to make those wraps without changes to other code. Now it has:

#define kmalloc(size, flags) malloc(size)
#define kfree(ptr) free(ptr)
#define vmalloc(size) malloc(size)
#define vfree(ptr) free(ptr)

edit2:
If xz embedded is a good choice should all unused files be droped so it will be even smaller (only folder lib/xz without few linux kernel only files + xz_config.h) or should all files from xz embedded be preserved?

@ianlancetaylor
Copy link
Owner

@ianlancetaylor ianlancetaylor commented Mar 31, 2020

Honestly my inclination is to just add a LZMA decoder like the existing zlib decoder.

@sargarass
Copy link
Author

@sargarass sargarass commented Apr 11, 2020

@ianlancetaylor hello. Has it become better? I used the xz embedded source code and mentioned both authors. Dropped redundant macroes, fixed codestyle (I hope I did), dropped single-call & preallocated modes, used backtrace_alloc for dictionary allocation. Everything now lives in elf.c file, so no external dependencies.I would like to believe that what you wanted?

@krlmlr
Copy link

@krlmlr krlmlr commented Aug 23, 2020

This is now in conflict due to 7206f5b. I suspect the conflict can be resolved if the xz sources are put at the end of elf.c (or in a separate file), haven't tried.

@ianlancetaylor
Copy link
Owner

@ianlancetaylor ianlancetaylor commented Sep 28, 2020

Thanks for sending this. I went in a different direction by writing a simpler and smaller version of the LZMA decoder that knows that all the data is in memory. It also doesn't use the BCJ decompressors, which should never be needed in minidebug info. The new code is in 77bcaa9. Thanks again.

@sargarass
Copy link
Author

@sargarass sargarass commented Oct 3, 2020

Thank you, @ianlancetaylor. Sounds great, I'll try it at work, where we did use this branch for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.