-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Exception::CallStack
: avoid allocations in LibC.dl_iterate_phdr
#12625
Conversation
Calling self.read_dwarf_sections directly from the C callback may lead to reallocations and deadlocks due to the internal lock held by dl_iterate_phdr (#10084). Work around this by storing object base address and passing it to self.read_dwarf_sections later when dl_iterate_phdr returns. This also fixes #12329 because there's no need to disable GC around dl_iterate_phdr anymore.
@@ -5,16 +5,19 @@ require "crystal/elf" | |||
|
|||
struct Exception::CallStack | |||
protected def self.load_debug_info_impl | |||
base_address : LibC::Elf_Addr = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid using a TypeDeclaration
here unless necessary:
base_address : LibC::Elf_Addr = 0 | |
base_address = LibC::Elf_Addr.zero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later we're passing a pointer to this variable. So IMO it makes sense to pin its type in order to prevent an accidental union type tainting the pointer.
Is it OK to only call |
@beta-ziliani No, the original code was also stopping after reading the first object. Quoting dl_iterate_phdr(3):
|
Totally missed that, thanks! |
Exception::CallStack
: avoid allocations in LibC.dl_iterate_phdr
Calling self.read_dwarf_sections directly from the C callback may lead to reallocations and deadlocks due to the internal lock held by dl_iterate_phdr (#10084). Work around this by storing object base address and passing it to self.read_dwarf_sections later when dl_iterate_phdr returns.
This also fixes #12329 because there's no need to disable GC around dl_iterate_phdr anymore.