Hello, Today I remembered that a few weeks ago I stumbled upon a stack overflow in the RISC5 Oberon compiler :-( When compiling this minimal example: MODULE A; TYPE X* = POINTER TO XD; XD = RECORD a*: POINTER TO XD; END; END A. MODULE B; IMPORT A; PROCEDURE P*(a: A.X); END P; END B. During writing of the symbol file of module B, a stack overflow happens in ORB.OutType (Both the vanilla version and Andreas' Extended Oberon version). It does not occur if you change either one of the following: - Make type XD exported (XD*) - Make field XD.a unexported - Change field XD.a to be of type X (use the named pointer type) - Make PROCEDURE P unexported Probably this situation is pathological, and usually you probably don't want this code style, and it is easy to work around (easiest case: Just use named pointer types). I still would like to understand what causes the error. I know that cyclic types can cause infinite recursion and therefore stack overflows when you do not take precautions to break the cycles, but I do not fully understand how the code is supposed to break them and why no cycles should remain afterwards. So I cannot tell where the design is violated and needs fixing... Any ideas? Regards, Michael
Today I remembered that a few weeks ago I stumbled upon a stack overflow in the RISC5 Oberon compiler
Hi, running FPGA, how can I tell, stack overflow happens. Except for obvious locking the system? What happens to the stack, does it grow into the heap, smashing it, any LEDs we get? -- Tomas Kral <thomas.kral@email.cz>
Tomas Have a look at the memory layout and try to answer your question yourself. Chapter 8 https://people.inf.ethz.ch/wirth/ProjectOberon/PO.System.pdf Hint: the stack does NOT grow into the heap. br Jörg
Am 16.06.2020 um 06:50 schrieb Tomas Kral <thomas.kral@email.cz>:
Today I remembered that a few weeks ago I stumbled upon a stack overflow in the RISC5 Oberon compiler
Hi, running FPGA, how can I tell, stack overflow happens. Except for obvious locking the system?
What happens to the stack, does it grow into the heap, smashing it, any LEDs we get?
-- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hint: the stack does NOT grow into the heap.
Yes, I am always surprised not realising the obvious. Further to the question, how overflow can happen. I can imagine, a recursion, as return address is in the LINK register, it can be size of local variables, being on stack + number of iterations, terminal condition not met? Apologies, not getting it right, again? -- Tomas Kral <thomas.kral@email.cz>
Hello Tomas, Am 16.06.2020 um 06:49 schrieb Tomas Kral:
Today I remembered that a few weeks ago I stumbled upon a stack overflow in the RISC5 Oberon compiler
Hi, running FPGA, how can I tell, stack overflow happens. Except for obvious locking the system?
If it is locking the system and you cannot BREAK back to the system, it is quite a good chance that something overwrote your module space, likely a stack overflow. But sometimes stack overflows only overwrite parts of the module space, and then they are hard to diagnose. For me, at least once a stack overflow overwrote just enough code so that the system started to behave strangely and corrupt the filesystem. So even after a hard reset the system was no longer able to boot and I had to salvage files from the disk image manually.
What happens to the stack, does it grow into the heap, smashing it, any LEDs we get?
Sometimes you will also see rendering artifacts on screen, I am not sure if the chance is high that you get any LEDs. If you suspect a stack overflow, you can patch your compiler to check for "almost stack overflow" on every procedure entry, and TRAP in case there is one. My code at <https://github.com/schierlm/Oberon2013Modifications/tree/master/StackOverflowProtector> implements just this, and uses the (otherwise unusd) TRAP 9 for that. After patching your compiler, you need to recompile all code where you suspect the stack overflow. (So in my case the compiler again). Then try to reproduce the issue and watch out for TRAP 9. I want to make clear that this modification has some runtime penalty, so while you may want to use it when debugging, you probably do not want to use this all the time. (In an emulator, I don't care much and mostly run my "debug build" which has this and other modifications built-in). Regards, Michael
participants (3)
-
Joerg -
Michael Schierl -
Tomas Kral