4 ms·
I was bothered by saying that static memory is assigned on the stack (implied that it is only on the stack). As an embedded guy, at least in bare metal situatio
by phyllostachys 9y ago
I was bothered by saying that static memory is assigned on the stack (implied that it is only on the stack). As an embedded guy, at least in bare metal situations, local function statics, any const variables, and any globals are either in the read-only data section[1] or in the general data section[2], both before the heap and definitely not in the stack section.
[1] - .rodata section in gcc
[2] - I think this is in the .data and .bss sections, where .data is copied from the file and .bss is zero initialized before calling main by the crt. If you peak into a linker script, or dump one by passing --verbose to ld, you can even see where it puts all the C++ bits and pieces. A dump I did on Debian with g++ is here: https://gist.github.com/Phyllostachys/0682a3bda13ef9c6b49d0445052ec955 https://gist.github.com/Phyllostachys/0682a3bda13ef9c6b49d04...
- phyllostachys 9y agoAfter looking at that default linker script dump, I noticed it didn't have the stuff I saw in the ARM linker script that I'm used to. So I attached one for a Silicon Labs EFM32 part. It's below the x86-64 linker script and is a little easier to read.
- phyllostachys 9y agoAfter a little investigation[1][2], it seems things get weird with an OS, as would be expected with virtual memory, et al. [1] - https://stackoverflow.com/questions/16360620/find-out-whether-a-pointer-is-pointing-at-the-stack-heap-or-program-text https://stackoverflow.com/questions/16360620/find-out-whethe... [2] - http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory/ http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in...