Files
hammer/recipes/procps-ng.toml
T
sergioandClaude Opus 4.8 6caf144d2c matar-gcc: procps-ng migrada a zig-cc — y destapa que link=static era mentira
31 migradas. La justificación escrita ("gueto, como vim/nano/htop") había
caducado: vim/nano/htop ya estaban en zig-cc. Tres problemas reales, ninguno
"zig miscompila":

1. rpl_realloc: la musl que zig bundlea (estática) devuelve NULL para
   realloc(p,0); AC_FUNC_REALLOC acierta y hace #define realloc rpl_realloc,
   pero procps-ng no trae esa función (la pide por AC_LIBOBJ y ningún
   Makefile.am usa @LIBOBJS@) ⇒ roto upstream en cualquier libc que conteste
   "no". Se suprime el renombrado por cache vars; no afirmamos que realloc sea
   GNU-compatible. Afectará a todo autoconf con AC_FUNC_REALLOC/MALLOC.

2. SIGSEGV: el binario salía musl-DINÁMICO con NEEDED libc.so. libtool lee el
   -static del lab como "usá mis .a", NO como flag al linker ⇒ link=static
   nunca se cumplió, ni con gcc. Fix con el patrón de jq/parted/shadow:
   LDFLAGS="-all-static -no-pie" en compile Y en install (libtool relinkea al
   instalar), nunca en configure.

3. UBSan: zig-cc lo activa por defecto; ps --sort=-rss aborta en sortformat.c
   (offset sobre puntero nulo, UB genuino de upstream pero inocuo). Patrón de
   libarchive/dwarves: -fno-sanitize=undefined.

Bit-repro verificado; 18 binarios responden y ps --sort da salida idéntica a gcc.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 00:12:00 -04:00

93 lines
5.2 KiB
TOML

# Importada de Alpine aports por `hammer import-alpine` (Etapa G). PUNTO DE PARTIDA — pero
# YA trae los parches de musl de Alpine (lo que un import de nix pierde). Pendiente: el
# sha256 del tarball (el wrapper lo calcula), y adaptar build/install del shell de abuild.
name = "procps-ng"
version = "4.0.6"
[source]
tarball = "https://sourceforge.net/projects/procps-ng/files/Production/procps-ng-4.0.6.tar.xz/download"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "c499aa14b6c94eda3a455bfe0d2d3c74c79dd718bffbd20207bd0831cb87725b83a76e4ee537a49ddf112bd1248a156d35da00035cbcd4c22037a20dcb4bdc9c"
sha256 = "67bea6fbc3a42a535a0230c9e891e5ddfb4d9d39422d46565a2990d1ace15216"
patches = ["disable-test_pids-check.patch"]
[build]
# zig-cc (default, migrado de gcc — matar-gcc 2026-07-16). La justificación previa
# ("gueto, como vim/nano/htop") caducó: vim/nano/htop ya están en zig-cc.
target = "x86_64-linux-musl"
link = "static"
flags = []
# Fase `configure` EXPLÍCITA (gotcha: si el ./configure va dentro de `compile`, hammer
# sintetiza un configure por defecto y pisa las flags). Sin utmps/gettext/systemd:
# --disable-w-from (evita utmp) y --disable-nls (evita -lintl). La ncurses del corpus es
# widec-only (libncursesw.a; sin libncurses.a) ⇒ NCURSES_LIBS=-lncursesw + --with-ncurses.
[build.phases]
configure = '''
# El parche toca un .am ⇒ make cree que debe regenerar con automake (ausente del corpus).
# Reordenamos timestamps (fuentes viejas < aclocal < *.in < configure) para saltar la regen.
find . \( -name '*.am' -o -name '*.m4' -o -name 'configure.ac' -o -name '*.in.in' \) -exec touch -t 200001010000 {} +
find . -name 'aclocal.m4' -exec touch -t 200001020000 {} +
find . \( -name '*.in' -o -name 'config.h.in' \) -exec touch -t 200001030000 {} +
find . -name 'configure' -exec touch -t 200001040000 {} +
# ncurses del corpus es static (no-PIE); sus reubicaciones R_X86_64_32 (_nc_globals) NO
# entran en un binario PIE. El lab linka static-PIE por defecto ⇒ apagamos PIE.
export CFLAGS="${CFLAGS:-} -fno-pie -fno-PIE -fno-sanitize=undefined"
export LDFLAGS="${LDFLAGS:-} -no-pie"
# -fno-sanitize=undefined (patrón de libarchive/dwarves): zig-cc activa UBSan por defecto (el lab
# no pasa -O ⇒ modo debug) y procps-ng tiene UB benigno de C viejo ⇒ los binarios ABORTABAN en
# runtime donde gcc no. Medido: `ps -eo pid,comm --sort=-rss` →
# "panic: applying non-zero offset 1 to null pointer" en src/ps/sortformat.c:421 long_sort_parse,
# que es `walk = sep_loc + 1;` con sep_loc=NULL (strpbrk no halla separador en el ÚLTIMO ítem);
# el valor queda muerto porque el while(items--) termina ⇒ inocuo, gcc lo computa y sigue.
# Apagamos UBSan (no fixeamos el UB upstream: sería whack-a-mole en paths no ejercitados).
# AC_FUNC_REALLOC (matar-gcc 2026-07-16). MEDIDO en el sandbox: la musl que zig bundlea,
# enlazada ESTÁTICA, devuelve NULL para realloc(p,0) y realloc(0,0) (la musl de Alpine+gcc
# devuelve no-NULL; por eso con gcc esto no saltaba). No es un falso negativo: el test de
# autoconf acierta. Pero al concluir "realloc no GNU-compatible" hace `#define realloc
# rpl_realloc`… y procps-ng NO trae esa función: su configure pide realloc.o vía AC_LIBOBJ
# (LIBOBJS='${LIBOBJDIR}realloc$U.o') pero ningún Makefile.am usa @LIBOBJS@ ni existe
# realloc.c en el árbol ⇒ `undefined symbol: rpl_realloc` al linkar (sysctl/pwdx/watch).
# procps-ng NO necesita la semántica GNU: su xrealloc() ya guarda `if (!ret && size)`
# (local/xalloc.h) ⇒ tolera NULL cuando size==0. Suprimimos sólo el renombrado.
# OJO: NO afirmamos que realloc(p,0) sea no-NULL acá — afirmamos que procps no depende de eso.
export ac_cv_func_realloc_0_nonnull=yes
export ac_cv_func_malloc_0_nonnull=yes
export NCURSES_CFLAGS="$(pkg-config --cflags ncursesw)"
export NCURSES_LIBS="-lncursesw"
./configure \
--build=$CBUILD \
--host=$CHOST \
--prefix=/usr \
--bindir=/bin \
--sbindir=/sbin \
--mandir=/usr/share/man \
--sysconfdir=/etc \
--localstatedir=/var \
--datarootdir=/usr/share \
--disable-nls \
--without-systemd \
--disable-shared \
--enable-static \
--disable-w-from \
--disable-rpath \
--with-ncurses
'''
# -all-static (patrón de jq/parted/shadow): procps-ng linka sus binarios CON LIBTOOL, que lee el
# `-static` del lab como "usá los .a de libtool", NO como flag al linker ⇒ el ejecutable salía
# musl-DINÁMICO. Con gcc eso colaba (NEEDED libc.musl-x86_64.so.1, presente en el rootfs); con
# zig-cc el NEEDED sale `libc.so` (el soname de la musl que bundlea zig, que no existe como
# libc del sistema) ⇒ SIGSEGV al arrancar. `-all-static` va SÓLO acá y en install (en configure
# rompería los link-tests, que no pasan por libtool), y en install porque libtool RELINKEA el
# binario al instalar. -no-pie: se pierde al pisar LDFLAGS y la ncurses static del corpus es no-PIE.
compile = 'make LDFLAGS="-all-static -no-pie" -j"$(nproc)"'
# de package() de Alpine (traducido $pkgdir→/out), simplificado (sin overrides de busybox):
install = '''
make -j1 DESTDIR="/out" install="install -D" LDFLAGS="-all-static -no-pie" install
# pkill es idéntico a pgrep.
ln -sf pgrep "/out"/bin/pkill 2>/dev/null || true
'''
[deps]
build = ["ncurses", "linux-headers", "pkgconf", "make"]