-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[libc] Lazily initialize freelist malloc using symbols #99254
Merged
Merged
Commits on Jul 25, 2024
-
[libc] Lazily initialize freelist malloc using symbols
This allows the user to customize the size of the heap provided by overriding the weak symbol __libc_heap_limit at link time. The heap begins at _end and ends __libc_heap_limit bytes afterwards. It also prevents a completely unused heap from requiring any space. (It's reasonably common to link in malloc/free to handle exceptional situations that can never actually be encountered.) I'd think this should eventually be replaced with an implemenation based on sbrk(), with sbrk() implemented generically in terms of brk(), which would be a system call on e.g. Linux and a bump pointer from _end up to __libc_heap_limit on baremetal. This would allow the allocator to be more flexible (e.g., an implementation could swap out brk() and do dynamic memory availability checks), to manage the heap better by keeping better track of "wilderness" and to work properly as a malloc on Linux. Incidentally, this sets the default heap limit to 128KiB, from 102400 bytes, which had been reported as "1GiB".
Configuration menu - View commit details
-
Copy full SHA for 060f31f - Browse repository at this point
Copy the full SHA 060f31fView commit details -
Configuration menu - View commit details
-
Copy full SHA for b0bbb40 - Browse repository at this point
Copy the full SHA b0bbb40View commit details -
- Move preprocessor check to assembly file - Add LIBC_CONSTINIT back to heap definition; make non-constexpr cast from &__heap_limit to size_t occur at init time to restore constexpr init.
Configuration menu - View commit details
-
Copy full SHA for 3e6faed - Browse repository at this point
Copy the full SHA 3e6faedView commit details -
Configuration menu - View commit details
-
Copy full SHA for d032238 - Browse repository at this point
Copy the full SHA d032238View commit details -
Make __libc_heap_limit an end symbol, not a size
This is more conventional and it dodges the issue of needing to provide a default size entirely. Setting up a baremetal heap intrinsically requires some linker script work, and __libc_heap_limit will be an undefined reference hinting to the user that this work must be done. Once we have a morecore function, a baremetal morecore() would use __libc_heap_limit, a Linux one would use sbrk(), and a test one would use a buffer.
Configuration menu - View commit details
-
Copy full SHA for 1edd9ad - Browse repository at this point
Copy the full SHA 1edd9adView commit details -
- __libc_heap_limit -> __llvm_libc_heap_limit
Configuration menu - View commit details
-
Copy full SHA for f606dd3 - Browse repository at this point
Copy the full SHA f606dd3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9e86f73 - Browse repository at this point
Copy the full SHA 9e86f73View commit details -
Configuration menu - View commit details
-
Copy full SHA for d57848f - Browse repository at this point
Copy the full SHA d57848fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 300cdf8 - Browse repository at this point
Copy the full SHA 300cdf8View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.