On Thu, 20 Aug 2026 13:34:59 -0700, Keith Thompson <
Keith.S.Thompson+u@gmail.com> wrote:
scott@slp53.sl.home (Scott Lurndal) writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
...
Without dynamic linking, main() is the first code that runs when
the program is executed. It allocates its local variables in memory >>that's been zeroed by the OS.
Even without dynamic linking, the CRT (C Run-time) code will execute
before main() (often at a symbol called _start). I don't recall
any guarantee that the CRT code won't use the stack prior to invoking main.
Certainly. Just yesterday I wrote a toy test program using static
linking that invoked code before entry to main(), using gcc's `__attribute__((constructor))`.
Another real case: On Unix the shell normally expands filename
patterns (aka wildcards or globs) and passes the actual filenames to a
program. MS-DOS didn't (and now Windows doesn't) so DJGPP had a
feature to check for wildcard in an arg and expand before calling
main(). I believe, but haven't checked, that mingw[64?] also does.
I also had a bad Heisenbug for a similar reason, but not in C, on an
earlyish (1980s) multiuser system (thus clearing user processes to
zero) where the debugger ran in userspace, and left cruft above the
userspace stack. A particular program (in COBOL) sometimes crashed in production, but not when I tried to debug it, and I eventually found
it was the difference between the initially zero stack area and the
cruft from debugger startup that masked the bug.
--- PyGate Linux v1.5.19
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)