Re:Undefined behavior in C is a reading error
by vyodaiken on Thursday May 20, 2021 @05:51PM
(#27227842)
That's good example, because nobody would complain if stack layouts changed and those programs failed. But if the compiler chooses to "optimize away" checks on stack layout, that's a different thing altogether. Also note that if you use pthreads or Linux clone or you are writing an operating system you can need to rely on exact stack layouts even today.
[ Parent
| on HN ]
Re:Undefined behavior in C is a reading error
by saagarjha on Thursday May 20, 2021 @09:47PM
(#27229644)
Stack layouts are only really relevant at ABI boundaries. In these cases the layout is usually specified in extensions to C or in other ways, such as handwritten assembly.
Re:Undefined behavior in C is a reading error
by vyodaiken on Friday May 21, 2021 @06:35AM
(#27232364)
Linux clone, pthreads, and os code commonly look at stack boundaries
Re:Undefined behavior in C is a reading error
by gpderetta on Friday May 21, 2021 @08:53AM
(#27233390)
Not sure what you are referring to with stack boundaries. Of course the ABI imposes some minimal requirements at ABI visible points, but these days you can't even rely on the existence of frame pointers to traverse the stack and you have to use the DWARF unwind machinery. And the content of the stack frame itself is completely unspecified of course.
Re:Undefined behavior in C is a reading error
by vyodaiken on Friday May 21, 2021 @02:54PM
(#27238325)
So I create a thread with a custom stack which is an allocated buffer. At the top, I write a sequence of bytes in some order. Then I periodically read the top of the stack to see if the stack is getting close to overflow. Meanwhile, the thread code is also addressing the same store.