sergio/takana
> Una distribución Linux construida con un laboratorio funcional y hermético en el > sótano, y una terminal mutable, clásica y anárquica en el piso de arriba — diseñada > desde el suelo para que una IA programadora entienda, modifique y co…
licencias: 95% (1114/1164) — la evidencia sale del tarball pineado, offline
1# elfutils 0.194 (sólo libelf) — de-Alpinización del último build-dep del kernel.
2#
3# `tools/objtool` del kernel enlaza -lelf (libelf + gelf.h) — en x86_64 las mitigaciones fuerzan
4# CONFIG_OBJTOOL. Venía de `apk add elfutils-dev` (bootstrap-lib). Esta receta construye libelf desde
5# fuente. Misma versión que Alpine 3.23 (0.194). Build-tool de build-time (objtool corre durante la
6# compilación del kernel; libelf NO se enlaza en el bzImage) ⇒ no afecta el of_tree del 4/4.
7#
8# Construimos SÓLO libelf (+ lib/libeu.a, su helper) — objtool no necesita libdw/libdwfl/src, que son
9# los que arrastran argp/obstack/fts (lo verdaderamente difícil en musl). elfutils es glibc-céntrico;
10# musl no trae <error.h>, <argp.h>, <libintl.h> ni rawmemchr. Estrategia de shims (en compat/, vía
11# CPPFLAGS/-include) en vez de los parches completos de Alpine:
12# - <libintl.h>: lo elimina --disable-nls (eu-config.h sólo lo incluye con ENABLE_NLS).
13# - <error.h>: shim con error()/error_at_line() (musl ya exporta program_invocation_short_name).
14# - <argp.h>: shim de tipos/decls — sólo lo usan lib/color.c y lib/printversion.c, cuyos .o van en
15# libeu.a pero objtool NO referencia (sólo necesita el core de libelf) ⇒ basta que
16# COMPILEN; las funcs argp quedan como undefined inertes en el .a.
17# - rawmemchr: shim inline (lo usa libelf/elf_getarsym.c), force-include global.
18# zig 0.13.0 (NO gcc): la regresión de zig 0.14 en C/musl (bisect con flex) miscompila; 0.13.0 la
19# esquiva, consistente con binutils/openssl/flex. $CC (= zig cc del lab) para los stubs y las fases.
20
21# elfutils 0.194 — VARIANTE que además construye `libdw`. NO sustituye a `recipes/elfutils.toml`.
22#
23# ── POR QUÉ VARIANTE ────────────────────────────────────────────────────────────────────────────
24# De la canónica cuelgan los CUATRO kernels (linux, linux-generic, linux-metal, linux-metal-dual):
25# su `tools/objtool` enlaza -lelf. Moverle el hash los invalidaría a todos. Esta variante existe
26# sólo para `dwarves`, que necesita `libdw` + `dwarf.h`. Mismo patrón que `openssl-threads`.
27#
28# ── LO QUE LA CANÓNICA DICE Y HAY QUE MATIZAR ───────────────────────────────────────────────────
29# La canónica avisa: «libdw/libdwfl son los que arrastran argp/obstack/fts (lo verdaderamente
30# difícil en musl)». Es cierto de `libdwfl` y de `src/`, **pero NO de `libdw` a secas**, que es lo
31# único que pide `dwarves`. Verificado sobre el fuente de 0.194:
32# · `argp_`/`fts_open` → sólo en `libdwfl/`, cero en `libdw/`.
33# · `obstack` → en `libdw/` aparece UNA vez y es **dentro de un COMENTARIO** de `libdwP.h`:
34# elfutils lleva su propia «simplified thread-local reimplementation of obstacks» y NO incluye
35# `<obstack.h>` en ningún sitio de libdw.
36# ⇒ `libdw` a secas no necesita ni argp ni fts ni obstack de verdad.
37#
38# ⚠ PERO `dwarves` SÍ necesita `libdwfl` (llama a 15 `dwfl_*` distintas desde `dwarf_loader.c`), y
39# libdwfl sí arrastra los dos: `argp-std.c` usa argp y `linux-kernel-modules.c` usa fts. Por eso
40# esta receta declara `argp-standalone` y `musl-fts`: no por libdw, por libdwfl.
41# En la práctica esos objetos casi nunca se ENLAZAN (dwarves no usa `dwfl_standard_argp` ni
42# `dwfl_linux_kernel_*`), pero tienen que COMPILAR, y para eso hacen falta `<argp.h>` y `<fts.h>`
43# de verdad — el `compat/` de la canónica trae un argp.h de mentira y NINGÚN fts.h.
44#
45name = "elfutils-libdw"
46version = "0.194"
47license = "GPL-3.0-or-later"
48
49[source]
50tarball = "https://sourceware.org/elfutils/ftp/0.194/elfutils-0.194.tar.bz2"
51sha256 = "09e2ff033d39baa8b388a2d7fbc5390bfde99ae3b7c67c7daaf7433fbcf0f01e"
52
53[build]
54compiler = "zig-cc"
55target = "x86_64-linux-musl"
56link = "dynamic"
57zig_version = "0.13.0"
58
59[deps]
60build = ["binutils", "argp-standalone", "musl-fts"]
61
62[build.phases]
63configure = """
64mkdir -p compat && \
65printf '%s\\n' \
66 '#ifndef _COMPAT_ERROR_H' '#define _COMPAT_ERROR_H' \
67 '#include <stdio.h>' '#include <stdlib.h>' '#include <stdarg.h>' '#include <string.h>' \
68 'extern char *program_invocation_short_name;' \
69 'static inline void error(int s,int e,const char*f,...){va_list a;fflush(stdout);' \
70 ' fprintf(stderr,"%s: ",program_invocation_short_name);va_start(a,f);vfprintf(stderr,f,a);va_end(a);' \
71 ' if(e)fprintf(stderr,": %s",strerror(e));fputc(0x0a,stderr);if(s)exit(s);}' \
72 'static inline void error_at_line(int s,int e,const char*fn,unsigned ln,const char*f,...){va_list a;' \
73 ' fflush(stdout);fprintf(stderr,"%s:%s:%u: ",program_invocation_short_name,fn,ln);' \
74 ' va_start(a,f);vfprintf(stderr,f,a);va_end(a);if(e)fprintf(stderr,": %s",strerror(e));' \
75 ' fputc(0x0a,stderr);if(s)exit(s);}' \
76 '#endif' > compat/error.h && \
77printf '%s\\n' \
78 '#ifndef _COMPAT_ARGP_H' '#define _COMPAT_ARGP_H' '#include <stdio.h>' '#include <errno.h>' \
79 'typedef int error_t;' \
80 'struct argp_option{const char*name;int key;const char*arg;int flags;const char*doc;int group;};' \
81 'struct argp;' \
82 'struct argp_state{const struct argp*root_argp;int argc;char**argv;int next;unsigned flags;' \
83 ' unsigned arg_num;int quoted;void*input;void**child_inputs;void*hook;char*name;FILE*err_stream;' \
84 ' FILE*out_stream;void*pstate;};' \
85 'typedef error_t(*argp_parser_t)(int,char*,struct argp_state*);' \
86 'struct argp_child;' \
87 'struct argp{const struct argp_option*options;argp_parser_t parser;const char*args_doc;' \
88 ' const char*doc;const struct argp_child*children;char*(*help_filter)(int,const char*,void*);' \
89 ' const char*argp_domain;};' \
90 'struct argp_child{const struct argp*argp;int flags;const char*header;int group;};' \
91 '#define ARGP_ERR_UNKNOWN E2BIG' '#define ARGP_KEY_ARG 0' '#define ARGP_KEY_END 0x1000001' \
92 '#define ARGP_KEY_INIT 0x1000003' '#define ARGP_KEY_FINI 0x1000007' '#define ARGP_KEY_SUCCESS 0x1000002' \
93 '#define ARGP_HELP_SEE 0x04' '#define ARGP_HELP_STD_ERR 0x2a' \
94 '#define OPTION_ARG_OPTIONAL 0x1' '#define OPTION_HIDDEN 0x2' '#define OPTION_ALIAS 0x4' \
95 '#define OPTION_DOC 0x8' '#define OPTION_NO_USAGE 0x10' '#define ARGP_IN_ORDER 0x08' \
96 '#define ARGP_NO_HELP 0x10' '#define ARGP_NO_EXIT 0x20' '#define ARGP_LONG_ONLY 0x40' \
97 'extern const char*argp_program_version;extern const char*argp_program_bug_address;' \
98 'extern void(*argp_program_version_hook)(FILE*,struct argp_state*);' \
99 'extern error_t argp_parse(const struct argp*,int,char**,unsigned,int*,void*);' \
100 'extern void argp_help(const struct argp*,FILE*,unsigned,char*);' \
101 'extern void argp_error(const struct argp_state*,const char*,...);' \
102 '#endif' > compat/argp.h && \
103printf '%s\\n' \
104 '#ifndef _COMPAT_MUSL_EXTRA_H' '#define _COMPAT_MUSL_EXTRA_H' '#include <string.h>' \
105 '#ifndef __GLIBC__' \
106 'static inline void*rawmemchr(const void*s,int c){const unsigned char*p=s;' \
107 ' for(;*p!=(unsigned char)c;p++){}' ' return(void*)p;}' \
108 '#endif' '#endif' > compat/musl-extra.h && \
109printf '%s\\n' \
110 '#ifndef _COMPAT_LIBINTL_H' '#define _COMPAT_LIBINTL_H' \
111 '#define gettext(s) (s)' '#define dgettext(d,s) (s)' '#define dcgettext(d,s,c) (s)' \
112 '#define ngettext(s,p,n) ((n)==1?(s):(p))' '#define dngettext(d,s,p,n) ((n)==1?(s):(p))' \
113 '#define bindtextdomain(d,x) ((char*)0)' '#define textdomain(d) ((char*)0)' \
114 '#define bind_textdomain_codeset(d,c) ((char*)0)' \
115 '#endif' > compat/libintl.h && \
116printf '%s\\n' \
117 '#include <stdio.h>' 'struct argp;struct argp_state;typedef int error_t;' \
118 'const char*argp_program_version;const char*argp_program_bug_address;' \
119 'void(*argp_program_version_hook)(FILE*,struct argp_state*);' \
120 'error_t argp_parse(const struct argp*a,int c,char**v,unsigned f,int*i,void*n){return 0;}' \
121 'void argp_help(const struct argp*a,FILE*s,unsigned f,char*n){}' \
122 'void argp_error(const struct argp_state*s,const char*f,...){}' \
123 'void argp_state_help(const struct argp_state*s,FILE*t,unsigned f){}' \
124 'void argp_usage(const struct argp_state*s){}' > compat/argp-stub.c && \
125$CC -c compat/argp-stub.c -o compat/argp-stub.o && ar rcs compat/libargp.a compat/argp-stub.o && \
126printf '%s\\n' \
127 'typedef struct{int x;}FTS;typedef struct{int y;}FTSENT;' \
128 'FTS*fts_open(char*const*p,int o,int(*c)(const FTSENT**,const FTSENT**)){return 0;}' \
129 'FTSENT*fts_read(FTS*f){return 0;}' 'FTSENT*fts_children(FTS*f,int o){return 0;}' \
130 'int fts_set(FTS*f,FTSENT*e,int o){return 0;}' 'int fts_close(FTS*f){return 0;}' > compat/fts-stub.c && \
131$CC -c compat/fts-stub.c -o compat/fts-stub.o && ar rcs compat/libfts.a compat/fts-stub.o && \
132printf '%s\\n' \
133 'struct obstack;void(*obstack_alloc_failed_handler)(void);int obstack_exit_failure;' \
134 'int _obstack_begin(struct obstack*o,int s,int a,void*(*c)(long),void(*f)(void*)){return 1;}' \
135 'int _obstack_begin_1(struct obstack*o,int s,int a,void*(*c)(void*,long),void(*f)(void*,void*),void*x){return 1;}' \
136 'void _obstack_newchunk(struct obstack*o,int l){}' 'int _obstack_allocated_p(struct obstack*o,void*p){return 0;}' \
137 'void _obstack_free(struct obstack*o,void*p){}' 'int _obstack_memory_used(struct obstack*o){return 0;}' \
138 > compat/obstack-stub.c && \
139$CC -c compat/obstack-stub.c -o compat/obstack-stub.o && ar rcs compat/libobstack.a compat/obstack-stub.o && \
140CFLAGS="-O2 -g -I$PWD/compat" CPPFLAGS="-I$PWD/compat" LDFLAGS="-L$PWD/compat" \
141 ./configure --prefix=/usr --libdir=/usr/lib --disable-nls --disable-demangler \
142 --disable-libdebuginfod --disable-debuginfod --program-prefix=eu-
143"""
144# El -include del shim de rawmemchr va SÓLO en compile (en configure rompe el test "undeclared builtins"
145# de autoconf). CFLAGS aquí reemplaza el de configure (mismo valor + el -include); AM_CFLAGS (warnings/
146# -Werror) se preserva.
147# ⚠ `rm -f compat/argp.h`: el shim de la canónica es sólo tipos/decls y NO declara
148# `argp_failure`, que usa `libdwfl/argp-std.c`. Esta variante SÍ trae argp de verdad
149# (`argp-standalone`), así que se borra el shim para que gane el `/usr/include/argp.h` real —
150# `-I$PWD/compat` va primero y si no lo taparía.
151compile = "rm -f compat/argp.h && make -C lib CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\" && make -C libelf libelf.a libelf.so CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\" && make -C libcpu CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\" && make -C backends CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\" && make -C libebl CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\" && make -C libdwelf CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\" && make -C libdw libdw.a CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\" && make -C libdwfl libdwfl.a CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\" && make -C libdwfl_stacktrace libdwfl_stacktrace.a CFLAGS=\"-O2 -g -I$PWD/compat -include $PWD/compat/musl-extra.h\""
152install = """
153mkdir -p /out/usr/lib/pkgconfig /out/usr/include && \
154cp -a libelf/libelf.a libelf/libelf.so* /out/usr/lib/ && \
155cp -a libelf/libelf.h libelf/gelf.h /out/usr/include/ && \
156cp -a config/libelf.pc /out/usr/lib/pkgconfig/ 2>/dev/null || true
157mkdir -p /out/usr/include/elfutils
158cp -a libdw/libdw.a /out/usr/lib/
159cp -a libdw/dwarf.h libdw/libdw.h libdw/known-dwarf.h /out/usr/include/
160cp -a libdwfl/libdwfl.h /out/usr/include/
161# libdw.a GORDA: dwarves enlaza sólo `-ldw -lelf` (su FindDWARF.cmake pone
162# DWARF_LIBRARIES = libdw + libelf y nada más), pero libdw necesita libdwfl, libebl, libdwelf,
163# los backends y libeu, que en elfutils son libs INTERNAS. En el .so de una distro van dentro;
164# acá hay que fusionarlas a mano en un solo archive o salen `undefined symbol: dwfl_begin`,
165# `eu_tsearch`, `eu_search_tree_init`… Mismo patrón que la libgtk-4.a gorda de `gtk4`.
166#
167# `error()` va también: es de <error.h> de glibc y musl no lo trae. El compat/error.h de la receta
168# es `static inline`, así que sólo sirve a las TUs que lo incluyen; los objetos que lo referencian
169# desde otra unidad necesitan un símbolo REAL. Se compila uno y se mete en el archive.
170printf '%s\n' '#include <stdio.h>' '#include <stdlib.h>' '#include <stdarg.h>' '#include <string.h>' \
171 'extern char *program_invocation_short_name;' \
172 'void error(int s,int e,const char*f,...){va_list a;fflush(stdout);' \
173 ' fprintf(stderr,"%s: ",program_invocation_short_name);va_start(a,f);vfprintf(stderr,f,a);va_end(a);' \
174 ' if(e)fprintf(stderr,": %s",strerror(e));fputc(0x0a,stderr);if(s)exit(s);}' \
175 'void error_at_line(int s,int e,const char*fn,unsigned ln,const char*f,...){va_list a;fflush(stdout);' \
176 ' fprintf(stderr,"%s:%s:%u: ",program_invocation_short_name,fn,ln);' \
177 ' va_start(a,f);vfprintf(stderr,f,a);va_end(a);if(e)fprintf(stderr,": %s",strerror(e));' \
178 ' fputc(0x0a,stderr);if(s)exit(s);}' > /tmp/error-impl.c
179$CC -c -O2 /tmp/error-impl.c -o /tmp/error-impl.o
180rm -rf /tmp/fat && mkdir -p /tmp/fat && cd /tmp/fat
181for A in $OLDPWD/libdw/libdw.a $OLDPWD/libdwfl/libdwfl.a $OLDPWD/libebl/libebl.a \
182 $OLDPWD/libdwelf/libdwelf.a $OLDPWD/backends/libebl_backends.a $OLDPWD/lib/libeu.a \\
183 $OLDPWD/libdwfl_stacktrace/libdwfl_stacktrace.a; do
184 [ -f "$A" ] || continue
185 n=$(basename "$A" .a); mkdir -p $n && (cd $n && ar x "$A")
186done
187cd $OLDPWD
188ar rcs /out/usr/lib/libdw.a $(find /tmp/fat -name '*.o') /tmp/error-impl.o
189cp -a libdwfl/libdwfl.a /out/usr/lib/
190cp -a libdw/libdw.h libdw/known-dwarf.h /out/usr/include/elfutils/
191cp -a libdwfl/libdwfl.h /out/usr/include/elfutils/
192cp -a version.h /out/usr/include/elfutils/ 2>/dev/null || true
193cp -a config/libdw.pc /out/usr/lib/pkgconfig/ 2>/dev/null || true
194test -f /out/usr/lib/libdw.a && test -f /out/usr/include/dwarf.h && test -f /out/usr/include/libdw.h && test -f /out/usr/lib/libdwfl.a && test -f /out/usr/include/elfutils/libdwfl.h
195"""