Repository navigation
edg: -C on the archive too, and the finalization pair EDG leaves open - #618
Merged
Merged
Conversation
cpfe linked and then crashed on every run with `fault read addr=0x2
pc=0x2'. `lib_src/main.c' defines `void _main(void)' -- EDG's
static-init helper, the one a target's own crt is expected to call --
and `_main' is 6l's default entry point (`6l/obj.c:305'
INITENTRY = "_main"; `arch/amd64/main9.s:3' TEXT _main(SB)). 6l makes
that name an SXREF at startup and satisfies it from the first archive
on the link line that defines it, and `cmd/edg' names libedg.a ahead
of libap. So the program's entry became EDG's helper: it ran
_Z12__call_ctorsv, which returns immediately (vars.c:49 has __head
null and munch_ctors.c defines _ctors[1] = {0}), and then executed a
plain RET.
main9.s reads the kernel's argument block at 0(SP), so 0(SP) at entry
holds argc -- which is what that RET popped and jumped to.
`cpfe --help' is argc 2. Falsifiable with no rebuild: `cpfe' alone
must have given pc=0x1 and `cpfe a b c' pc=0x4.
-C is not implicated. There was no duplicate for dupokall to
silence: main9.$O is pulled only to satisfy the entry symbol, its
other global _tos being referenced from profile.c alone, so with
libedg.a answering first that member never reached the link.
Renamed rather than dropped from OFILES: main.c is compiled with
-D_main=__edg_main. Nothing anywhere references _main, so removing
the member would have linked equally well and would have thrown away
the only entry point into EDG's static-initialisation machinery.
The static-init gap is recorded, not fixed: nothing now calls
_Z12__call_ctorsv, so a C++ program cpfe translates would not run its
static constructors. cpfe does not need it and does not emit a call
to _main either -- the name occurs in the 133-file corpus exactly
twice, both in lib_src/main.c, with no string literal of it in the
emitter.
One nm says _main is alone: all 51 lib_src files through gcc, then
nm --defined-only -g, gives exactly four external definitions that
are neither _Z-mangled nor __-prefixed -- _ctors, _dtors, _main,
_new_handler -- and the other three collide with nothing.
cmd/edg/mkfile asserted that every definition under lib_src is
_Z-mangled or __-prefixed; that sentence is the one that would have
found this, and it is corrected there.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
cpfe linked and then crashed on every run with
fault read addr=0x2 pc=0x2'.lib_src/main.c' definesvoid _main(void)' -- EDG's static-init helper, the one a target's own crt is expected to call -- and_main' is 6l's default entry point (6l/obj.c:305' INITENTRY = "_main";arch/amd64/main9.s:3' TEXT _main(SB)). 6l makes that name an SXREF at startup and satisfies it from the first archive on the link line that defines it, and `cmd/edg' names libedg.a ahead of libap. So the program's entry became EDG's helper: it ran _Z12__call_ctorsv, which returns immediately (vars.c:49 has __head null and munch_ctors.c defines _ctors[1] = {0}), and then executed a plain RET.main9.s reads the kernel's argument block at 0(SP), so 0(SP) at entry holds argc -- which is what that RET popped and jumped to.
cpfe --help' is argc 2. Falsifiable with no rebuild:cpfe' alone must have given pc=0x1 and `cpfe a b c' pc=0x4.-C is not implicated. There was no duplicate for dupokall to silence: main9.$O is pulled only to satisfy the entry symbol, its other global _tos being referenced from profile.c alone, so with libedg.a answering first that member never reached the link.
Renamed rather than dropped from OFILES: main.c is compiled with -D_main=__edg_main. Nothing anywhere references _main, so removing the member would have linked equally well and would have thrown away the only entry point into EDG's static-initialisation machinery.
The static-init gap is recorded, not fixed: nothing now calls _Z12__call_ctorsv, so a C++ program cpfe translates would not run its static constructors. cpfe does not need it and does not emit a call to _main either -- the name occurs in the 133-file corpus exactly twice, both in lib_src/main.c, with no string literal of it in the emitter.
One nm says _main is alone: all 51 lib_src files through gcc, then nm --defined-only -g, gives exactly four external definitions that are neither _Z-mangled nor __-prefixed -- _ctors, _dtors, _main, _new_handler -- and the other three collide with nothing. cmd/edg/mkfile asserted that every definition under lib_src is _Z-mangled or __-prefixed; that sentence is the one that would have found this, and it is corrected there.
Claude-Session: https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs