Claude/upgrade ape c library mm z gd#148
Conversation
…sets cpos() = seek(cout,0,1) returns the OS file position, which does not account for bytes still in cbuf. After the data write loop there may be a partial unflushed buffer, so dwarfabbrevo/dwarflineo/etc. would be recorded at the wrong (too-low) offset. The ELF section headers would then point to garbage. Fix: explicit cflush() before dwarfemitdebugsections() so that cpos() inside writeabbrev()/writelines()/etc. returns the true next-write position. https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
Symbols needed: xreallocarray/xnmalloc/xcharalloc/x2realloc/xpalloc/xzalloc (xmalloc.c), get_errno, last_component (basename-lgpl.c), unicode_to_mb (unicodeio.c), bitset_stats_enable/dump (bitset/stats.c), create_pipe_bidi (spawn-pipe.c), fstrcmp_bounded (fstrcmp.c), at/block/unblock_fatal_signals (fatal-signal.c), gethrxtime, find_in_given_path (findprog-in.c), gl_scratch_buffer_dupfree (malloc/scratch_buffer_dupfree.c), seen_file/record_file (file-set.c), xalloc_die (xalloc-die.c). Also add gnulib-deps.sh: automation script that reads mk link errors from stdin and outputs the object file names needed, by grepping each undefined symbol in the package's gnulib lib/ directory. Usage: mk 2>&1 | sh gnulib-deps.sh ../../../external/bison/lib libbison_a https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
Symbols needed (all defined in patch/lib/): quotearg/quotearg_n/set_quoting_style -> quotearg.c set_program_name/program_name -> progname.c xstdopen -> xstdopen.c argmatch/argmatch_invalid -> argmatch.c get_version/find_backup_file_name -> backup-find.c last_component -> basename-lgpl.c hash_string/initialize/lookup/etc. -> hash.c gettime -> gettime.c parse_datetime -> parse-datetime.c try_tempname -> tempname.c exit_failure (via quotearg) -> exitfail.c https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
print_start/end_colorize/should_colorize/init_colorize -> colorize-posix.c close_stdout -> closeout.c excluded_file_name/new_exclude/add_exclude* -> exclude.c safe_read -> safe-read.c openat_safer -> openat-safer.c case_folded_counterparts/init_localeinfo -> localeinfo.c strip_trailing_slashes -> stripslash.c memchr2 -> memchr2.c gl_dynarray_at_failure/emplace_enlarge/resize/finalize -> malloc/dynarray_*.c cycle_check_init/cycle_check -> cycle-check.c https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
xfprintf/xprintf -> xprintf.c execute -> execute.c create_pipe_in -> spawn-pipe.c wait_subprocess -> wait-process.c mkstemp_safer -> mkstemp-safer.c memchr2 -> memchr2.c close_stream -> close-stream.c fopen_safer -> fopen-safer.c emit_bug_reporting_address/version_etc -> version-etc.c + version-etc-fsf.c c_stack_action -> c-stack.c proper_name_utf8 -> propername.c close_stream_temp/cleanup_temp_dir/register_temp_file/ fopen_temp/unregister_temp_file/cleanup_temp_file/ create_temp_dir(=create_dir?) -> clean-temp.c + clean-temp-simple.c file_name_concat -> filenamecat.c at_fatal_signal (via execute/spawn-pipe) -> fatal-signal.c Note: clean-temp-simple.c has threading deps; may need further iteration. Note: create_dir may be pcc truncation of create_temp_dir (15->10 chars). https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
Add the gnulib modules needed to resolve first-round link errors for cmp/diff/diff3/sdiff: xmalloc, xalloc-die, xstrtoimax, quotearg, diagnose, version-etc, version-etc-fsf, progname, c-stack, xstdopen, propername-lite, cmpbuf, exitfail. https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
xmalloc+xalloc_die were already in libap's malloc/xmalloc.c. Add exitfail.c (int volatile exit_failure = EXIT_FAILURE) and exitfail.h to libap's malloc/ so packages don't need their own copies. Remove xmalloc.$O, xalloc-die.$O, exitfail.$O from bison, diff, grep, m4, and patch gnulib object lists — they are now satisfied by libap.a. Note: xmalloca.$O in m4 stays (xmalloca() is not in libap). https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
There was a problem hiding this comment.
Code Review
This pull request introduces a utility script, gnulib-deps.sh, to identify missing gnulib dependencies and updates the build configurations (mkfiles) for bison, diff, grep, m4, and patch to include necessary object files. Additionally, it adds exit_failure support to the APE library and includes a fix in the 6l linker to ensure proper file flushing before DWARF emission. Review feedback identifies a logic bug in the dependency script where multiple grep commands compete for standard input and a syntax error in the patch mkfile caused by an erroneous trailing backslash.
| extract_symbols() { | ||
| grep ': undefined:' | sed 's/.*: undefined: //;s/ in .*//' | ||
| grep "undefined reference to" | sed "s/.*undefined reference to \`//;s/'.*//" | ||
| } |
There was a problem hiding this comment.
The extract_symbols function contains a logic bug: the first grep command consumes the entire standard input stream. Consequently, the second grep command will never receive any data to process, and symbols in the undefined reference to format will be missed. You should use a single tool like sed to process the input stream once and handle both patterns.
| extract_symbols() { | |
| grep ': undefined:' | sed 's/.*: undefined: //;s/ in .*//' | |
| grep "undefined reference to" | sed "s/.*undefined reference to \`//;s/'.*//" | |
| } | |
| extract_symbols() { | |
| sed -n 's/.*: undefined: \([^ ]*\).*/\1/p; s/.*undefined reference to `\([^'\'' ]*\)'\''.*/\1/p' | |
| } |
| progname.$O\ | ||
| quotearg.$O\ | ||
| tempname.$O\ | ||
| xstdopen.$O\ |
No description provided.