ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.84k stars 2.55k forks source link

Missing symbols in the musl libc or at least for 64bit? #21465

Closed jittygitty closed 1 month ago

jittygitty commented 1 month ago

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

Could do better to skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556

``` ~/ZIG/zig-linux-aarch64-0.13.0/bash-4.2.53# make LDFLAGS=-lrt CC="/root/ZIG/zig-linux-aarch64-0.13.0/zig cc -I./lib/termcap -L. -ltermcap -static -std=gnu89 -target powerpc-linux-musl" CXX="/root/ZIG/zig-linux-aarch64-0.13.0/zig c++ -std=gnu89 -target powerpc-linux-musl" *********************************************************** * * /bin/sh: 1: /root/ZIG/zig-linux-aarch64-0.13.0/bash-4.2.53/bashversion: Exec format error * * * *********************************************************** rm -f bash /root/ZIG/zig-linux-aarch64-0.13.0/zig cc -I./lib/termcap -L. -ltermcap -static -std=gnu89 -target powerpc-linux-musl -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/malloc -L./lib/sh -lrt -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcmd.o hashlib.o mailcheck.o trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o bashline.o list.o stringlib.o locale.o findcmd.o redir.o pcomplete.o pcomplib.o syntax.o xmalloc.o -lbuiltins -lglob -lsh -lreadline -lhistory -ltermcap -ltilde -lmalloc -ldl ld.lld: error: undefined symbol: __stat_time64 >>> referenced by bashhist.c:382 >>> bashhist.o:(maybe_append_history) >>> referenced by bind.c:779 >>> bind.o:(_rl_read_init_file) in archive ./lib/readline/libreadline.a >>> referenced by pathcanon.c:83 >>> pathcanon.o:(sh_canonpath) in archive ./lib/sh/libsh.a >>> referenced 34 more times ld.lld: error: undefined symbol: __lstat_time64 >>> referenced by bashline.c:2803 >>> bashline.o:(bash_directory_completion_hook) >>> referenced by complete.c:563 >>> complete.o:(print_filename) in archive ./lib/readline/libreadline.a >>> referenced by complete.c:563 >>> complete.o:(print_filename) in archive ./lib/readline/libreadline.a >>> referenced 4 more times ld.lld: error: undefined symbol: __time64 >>> referenced by printf.def:465 (./printf.def:465) >>> printf.o:(printf_builtin) in archive ./builtins/libbuiltins.a >>> referenced by history.c:249 >>> history.o:(add_history) in archive ./lib/readline/libreadline.a >>> referenced by tmpfile.c:136 >>> tmpfile.o:(sh_mktmpname) in archive ./lib/sh/libsh.a >>> referenced 8 more times ld.lld: error: undefined symbol: __localtime64 >>> referenced by printf.def:473 (./printf.def:473) >>> printf.o:(printf_builtin) in archive ./builtins/libbuiltins.a >>> referenced by history.def:256 (./history.def:256) >>> history.o:(display_history) in archive ./builtins/libbuiltins.a >>> referenced by parse.y:5209 (./parse.y:5209) >>> y.tab.o:(decode_prompt_string) >>> referenced 1 more times ld.lld: error: undefined symbol: __fstat_time64 >>> referenced by histfile.c:188 >>> histfile.o:(read_history_range) in archive ./lib/readline/libreadline.a >>> referenced by histfile.c:325 >>> histfile.o:(history_truncate_file) in archive ./lib/readline/libreadline.a >>> referenced by read.def:377 (./read.def:377) >>> read.o:(read_builtin) in archive ./builtins/libbuiltins.a >>> referenced 4 more times ld.lld: error: undefined symbol: __select_time64 >>> referenced by input.c:303 >>> input.o:(_rl_input_available) in archive ./lib/readline/libreadline.a >>> referenced by input.c:303 >>> input.o:(_rl_input_queued) in archive ./lib/readline/libreadline.a >>> referenced by input.c:187 >>> input.o:(rl_read_key) in archive ./lib/readline/libreadline.a >>> referenced 3 more times ld.lld: error: undefined symbol: __setitimer_time64 >>> referenced by ufuncs.c:55 >>> ufuncs.o:(falarm) in archive ./lib/sh/libsh.a ld.lld: error: undefined symbol: __getrusage_time64 >>> referenced by times.def:73 (./times.def:73) >>> times.o:(times_builtin) in archive ./builtins/libbuiltins.a >>> referenced by times.def:74 (./times.def:74) >>> times.o:(times_builtin) in archive ./builtins/libbuiltins.a >>> referenced by execute_cmd.c:1217 >>> execute_cmd.o:(time_command) >>> referenced 3 more times ld.lld: error: undefined symbol: __dlsym_time64 >>> referenced by enable.def:332 (./enable.def:332) >>> enable.o:(enable_builtin) in archive ./builtins/libbuiltins.a ld.lld: error: undefined symbol: __gettimeofday_time64 >>> referenced by variables.c:1283 >>> variables.o:(initialize_shell_variables) >>> referenced by execute_cmd.c:1213 >>> execute_cmd.o:(time_command) >>> referenced by execute_cmd.c:1251 >>> execute_cmd.o:(time_command) >>> referenced 2 more times make: *** [Makefile:541: bash] Error 1 root@rpi4-20220808:~/ZIG/zig-linux-aarch64-0.13.0/bash-4.2.53# ```

Expected Behavior

Expected behavior: build bash for 32bit powerpc without complaining : )

jittygitty commented 1 month ago

Hi @Kevin-Otalvares Are you a nice virus bot or a bad one?

Rexicon226 commented 1 month ago

A bad bot, please do not click on the link.

jittygitty commented 1 month ago

@Rexicon226 Yea it's amazing how fast the bot posted, like immediately after my post. Anyway, i been playing with zig mainly to try use it for cross-compiling. For simple stuff worked but it's been quite an adventure trying to cross-compile bash : )

alexrp commented 1 month ago

Please format the output in a code block using triple backticks. 🙂

alexrp commented 1 month ago

Can you please try with a master build from here? Note that you will need to use powerpc-linux-musleabihf instead of powerpc-linux-musl as we've split that triple out depending on float ABI.

jittygitty commented 1 month ago

Cleanup, best skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556

@alexrp Thanks, I tried with latest but seems got same thing (note I did "not" do a make clean, but simply switched over to using master: zig-master -> zig-linux-aarch64-0.14.0-dev.1632+d83a3f174 ) ``` ~/ZIG/zig-master/bash-4.2.53# make LDFLAGS=-lrt CC="/root/ZIG/zig-master/zig cc -I./lib/termcap -L. -ltermcap -static -std=gnu89 -target powerpc-linux-musleabihf" CXX="/root/ZIG/zig-master/zig c++ -std=gnu89 -target powerpc-linux-musleabihf" *********************************************************** * * /bin/sh: 1: /root/ZIG/zig-linux-aarch64-0.13.0/bash-4.2.53/bashversion: Exec format error * * * *********************************************************** rm -f bash /root/ZIG/zig-master/zig cc -I./lib/termcap -L. -ltermcap -static -std=gnu89 -target powerpc-linux-musleabihf -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/malloc -L./lib/sh -lrt -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcmd.o hashlib.o mailcheck.o trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o bashline.o list.o stringlib.o locale.o findcmd.o redir.o pcomplete.o pcomplib.o syntax.o xmalloc.o -lbuiltins -lglob -lsh -lreadline -lhistory -ltermcap -ltilde -lmalloc -ldl ld.lld: error: undefined symbol: __stat_time64 >>> referenced by bashhist.c:382 >>> bashhist.o:(maybe_append_history) >>> referenced by mailstat.c:70 >>> mailstat.o:(mailstat) in archive ./lib/sh/libsh.a >>> referenced by mailstat.c:96 >>> mailstat.o:(mailstat) in archive ./lib/sh/libsh.a >>> referenced 34 more times ld.lld: error: undefined symbol: __lstat_time64 >>> referenced by bashline.c:2803 >>> bashline.o:(bash_directory_completion_hook) >>> referenced by complete.c:563 >>> complete.o:(print_filename) in archive ./lib/readline/libreadline.a >>> referenced by complete.c:563 >>> complete.o:(print_filename) in archive ./lib/readline/libreadline.a >>> referenced 4 more times ld.lld: error: undefined symbol: __time64 >>> referenced by printf.def:465 (./printf.def:465) >>> printf.o:(printf_builtin) in archive ./builtins/libbuiltins.a >>> referenced by history.c:249 >>> history.o:(add_history) in archive ./lib/readline/libreadline.a >>> referenced by tmpfile.c:136 >>> tmpfile.o:(sh_mktmpname) in archive ./lib/sh/libsh.a >>> referenced 8 more times ld.lld: error: undefined symbol: __localtime64 >>> referenced by printf.def:473 (./printf.def:473) >>> printf.o:(printf_builtin) in archive ./builtins/libbuiltins.a >>> referenced by history.def:256 (./history.def:256) >>> history.o:(display_history) in archive ./builtins/libbuiltins.a >>> referenced by parse.y:5209 (./parse.y:5209) >>> y.tab.o:(decode_prompt_string) >>> referenced 1 more times ld.lld: error: undefined symbol: __select_time64 >>> referenced by input_avail.c:83 >>> input_avail.o:(input_avail) in archive ./lib/sh/libsh.a >>> referenced by input.c:303 >>> input.o:(_rl_input_available) in archive ./lib/readline/libreadline.a >>> referenced by input.c:303 >>> input.o:(_rl_input_queued) in archive ./lib/readline/libreadline.a >>> referenced 3 more times ld.lld: error: undefined symbol: __fstat_time64 >>> referenced by histfile.c:188 >>> histfile.o:(read_history_range) in archive ./lib/readline/libreadline.a >>> referenced by histfile.c:325 >>> histfile.o:(history_truncate_file) in archive ./lib/readline/libreadline.a >>> referenced by read.def:377 (./read.def:377) >>> read.o:(read_builtin) in archive ./builtins/libbuiltins.a >>> referenced 4 more times ld.lld: error: undefined symbol: __setitimer_time64 >>> referenced by ufuncs.c:55 >>> ufuncs.o:(falarm) in archive ./lib/sh/libsh.a ld.lld: error: undefined symbol: __getrusage_time64 >>> referenced by times.def:73 (./times.def:73) >>> times.o:(times_builtin) in archive ./builtins/libbuiltins.a >>> referenced by times.def:74 (./times.def:74) >>> times.o:(times_builtin) in archive ./builtins/libbuiltins.a >>> referenced by execute_cmd.c:1217 >>> execute_cmd.o:(time_command) >>> referenced 3 more times ld.lld: error: undefined symbol: __dlsym_time64 >>> referenced by enable.def:332 (./enable.def:332) >>> enable.o:(enable_builtin) in archive ./builtins/libbuiltins.a ld.lld: error: undefined symbol: __gettimeofday_time64 >>> referenced by variables.c:1283 >>> variables.o:(initialize_shell_variables) >>> referenced by execute_cmd.c:1213 >>> execute_cmd.o:(time_command) >>> referenced by variables.c:1283 >>> variables.o:(get_random_number) >>> referenced 2 more times make: *** [Makefile:541: bash] Error 1 ```
jittygitty commented 1 month ago

Better to skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556

I went ahead and did a "make clean" and rebuilt all again with the zig master zig-linux-aarch64-0.14.0-dev.1632+d83a3f174 ``` ~/ZIG/zig-master/bash-4.2.53# make LDFLAGS=-lrt CC="/root/ZIG/zig-master/zig cc -I./lib/termcap -L. -ltermcap -static -std=gnu89 -target powerpc-linux-musleabihf" CXX="/root/ZIG/zig-master/zig c++ -std=gnu89 -target powerpc-linux-musleabihf" *********************************************************** * * /bin/sh: 1: /root/ZIG/zig-linux-aarch64-0.13.0/bash-4.2.53/bashversion: Exec format error * * * *********************************************************** rm -f bash /root/ZIG/zig-master/zig cc -I./lib/termcap -L. -ltermcap -static -std=gnu89 -target powerpc-linux-musleabihf -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/malloc -L./lib/sh -lrt -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcmd.o hashlib.o mailcheck.o trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o bashline.o list.o stringlib.o locale.o findcmd.o redir.o pcomplete.o pcomplib.o syntax.o xmalloc.o -lbuiltins -lglob -lsh -lreadline -lhistory -ltermcap -ltilde -lmalloc -ldl ld.lld: error: undefined symbol: __stat_time64 >>> referenced by findcmd.c:91 >>> findcmd.o:(file_status) >>> referenced by findcmd.c:91 >>> findcmd.o:(executable_file) >>> referenced by findcmd.c:91 >>> findcmd.o:(is_directory) >>> referenced 34 more times ld.lld: error: undefined symbol: __fstat_time64 >>> referenced by redir.c:602 >>> redir.o:(do_redirection_internal) >>> referenced by read.def:377 (./read.def:377) >>> read.o:(read_builtin) in archive ./builtins/libbuiltins.a >>> referenced by histfile.c:188 >>> histfile.o:(read_history_range) in archive ./lib/readline/libreadline.a >>> referenced 4 more times ld.lld: error: undefined symbol: __localtime64 >>> referenced by history.def:256 (./history.def:256) >>> history.o:(display_history) in archive ./builtins/libbuiltins.a >>> referenced by printf.def:473 (./printf.def:473) >>> printf.o:(printf_builtin) in archive ./builtins/libbuiltins.a >>> referenced by parse.y:5209 (./parse.y:5209) >>> y.tab.o:(decode_prompt_string) >>> referenced 1 more times ld.lld: error: undefined symbol: __time64 >>> referenced by history.c:249 >>> history.o:(add_history) in archive ./lib/readline/libreadline.a >>> referenced by tmpfile.c:136 >>> tmpfile.o:(sh_mktmpname) in archive ./lib/sh/libsh.a >>> referenced by tmpfile.c:185 >>> tmpfile.o:(sh_mktmpfd) in archive ./lib/sh/libsh.a >>> referenced 8 more times ld.lld: error: undefined symbol: __select_time64 >>> referenced by input.c:303 >>> input.o:(_rl_input_available) in archive ./lib/readline/libreadline.a >>> referenced by input.c:303 >>> input.o:(_rl_input_queued) in archive ./lib/readline/libreadline.a >>> referenced by input.c:187 >>> input.o:(rl_read_key) in archive ./lib/readline/libreadline.a >>> referenced 3 more times ld.lld: error: undefined symbol: __lstat_time64 >>> referenced by complete.c:563 >>> complete.o:(print_filename) in archive ./lib/readline/libreadline.a >>> referenced by complete.c:563 >>> complete.o:(print_filename) in archive ./lib/readline/libreadline.a >>> referenced by complete.c:1695 >>> complete.o:(append_to_match) in archive ./lib/readline/libreadline.a >>> referenced 4 more times ld.lld: error: undefined symbol: __setitimer_time64 >>> referenced by ufuncs.c:55 >>> ufuncs.o:(falarm) in archive ./lib/sh/libsh.a ld.lld: error: undefined symbol: __getrusage_time64 >>> referenced by times.def:73 (./times.def:73) >>> times.o:(times_builtin) in archive ./builtins/libbuiltins.a >>> referenced by times.def:74 (./times.def:74) >>> times.o:(times_builtin) in archive ./builtins/libbuiltins.a >>> referenced by execute_cmd.c:1217 >>> execute_cmd.o:(time_command) >>> referenced 3 more times ld.lld: error: undefined symbol: __dlsym_time64 >>> referenced by enable.def:332 (./enable.def:332) >>> enable.o:(enable_builtin) in archive ./builtins/libbuiltins.a ld.lld: error: undefined symbol: __gettimeofday_time64 >>> referenced by variables.c:1283 >>> variables.o:(initialize_shell_variables) >>> referenced by execute_cmd.c:1213 >>> execute_cmd.o:(time_command) >>> referenced by execute_cmd.c:1251 >>> execute_cmd.o:(time_command) >>> referenced 2 more times make: *** [Makefile:541: bash] Error 1 ```
jittygitty commented 1 month ago

@alexrp I ended up just creating the following files to define those symbols etc: gettimeofday_time64.c, dlsym_time64.c, etc etc

That worked and in the end I got a bash and bashversion binary but file said it needed /lib/ld-musl...powerpc.so... which I don't have on my intended target system. So back go trying target powerpc-linux-gnueabihf i guess...

alexrp commented 1 month ago

@alexrp I ended up just creating the following files to define those symbols etc: gettimeofday_time64.c, dlsym_time64.c, etc etc

Ok, I'll see if I can figure out why it doesn't work the normal way.

That worked and in the end I got a bash and bashversion binary but file said it needed /lib/ld-musl...powerpc.so...

That means your executable wasn't statically linked for some reason. Can you try running file bash and musl-ldd bash?

jittygitty commented 1 month ago

Yea it's dynamically built, i figured that was likely something in all the makefiles that perhaps made it that way. But now I just noticed that I didn't have /lib/ld-musl-aarch64.so.1 so I just quickly did an apt-get install musl and rebuilt and same thing, but maybe I need to do a make clean and perhaps ./configure again? Although remember I'm "cross-compiling" so I thought it was actually "zig" build environment providing all that, but I'm just few days old in zig. I also installed musl-tools now for musl-ldd but doesn't really work, i guess since the bash binaries are powerpc and not Arm (i'm on a pi4).

root:~/ZIG/zig-master/bash-4.2.53# make CC="/root/ZIG/zig-master/zig cc -I./lib/termcap -L. -ltermcap -std=gnu89 -static -target powerpc-linux-musleabihf" CXX="/root/ZIG/zig-master/zig c++ -std=gnu89 -static -target powerpc-linux-musleabihf" EXTRA_LDFLAGS=-static

root:~/ZIG/zig-master/bash-4.2.53# file bash
bash: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-powerpc.so.1, with debug_info, not stripped
root:~/ZIG/zig-master/bash-4.2.53# file bashversion
bashversion: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-powerpc.so.1, with debug_info, not stripped
root:~/ZIG/zig-master/bash-4.2.53# musl-ldd bash
musl-ldd: bash: Not a valid dynamic program
jittygitty commented 1 month ago

Best skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556

fyi I also built it via: ``` make LDFLAGS=-lrt CC="/root/ZIG/zig-master/zig cc -v -I./lib/termcap -L. -L/usr/include -std=gnu89 -target powerpc-linux-gnueabihf" CXX="/root/ZIG/zig-master/zig c++ -std=gnu89 -target powerpc-linux-gnueabihf" root:~/ZIG/zig-master/bash-4.2.53# file bash bash: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 2.0.0, with debug_info, not stripped root:~/ZIG/zig-master/bash-4.2.53# file bashversion bashversion: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 2.0.0, with debug_info, not stripped ``` But the resulting bashversion and bash gave Segmentation fault on the target powerpc elf 32bit msb system. (/lib/ld.so.1 does exist on the target powerpc system, ie: /lib/ld.so.1 -> ld-2.11.1.so ) I also had to create a sigsetjmp.c file i made due to error of undefined sigsetjmp symbol, so there's ``` cat sigsetjmp.c #include #include extern int sigsetjmp(sigjmp_buf env, int savesigs) { return sigsetjmp(env, savesigs); } root:~/ZIG/zig-master/bash-4.2.53# ../zig cc -c -o sigsetjmp.o -std=gnu89 -I. -I./include --sysroot=/root/ZIG/glibc-2.28 sigsetjmp.c -lc -target powerpc-linux-gnueabihf ``` NOTE: During the compilation process of bash, it required to build and then "run" some binaries used to further process some code before continuing compilation, so while cross-compiling and encountering those errors, I had to stop and manually build "mksyntax.c" and builtins/mkbuiltins.c and support/mksignames.c such as: ``` ../zig build-exe -I. -I./include support/mksignames.c support/signames.c -lc ``` Which built those as ARM so it could run the binaries on that pi4 ARM system and that got me past the error (I think bash tried to interpret the 'powerpc binary' and gives some error about expected ")" or something), not sure if that could have created any other issues down the line though even though I got bash binary produced.
jittygitty commented 1 month ago

Better to skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556

I decided to make a clean bash folder again from scratch. ``` time make CC="/root/ZIG/zig-master/zig cc -v -std=gnu89 -target powerpc-linux-gnueabihf -mcpu=e500" CXX="/root/ZIG/zig-master/zig c++ -std=gnu89 -target powerpc-linux-gnueabihf -mcpu=e500" End of search list. In file included from display.c:49: ./tcap.h:33:12: fatal error: 'termcap.h' file not found 33 | # include | ^~~~~~~~~~~ 1 error generated. ``` I ended up editing that tcap.h file in the bash project and changing #include to #include "../termcap/termcap.h" and that got past it and then it complained about libtermcap.so or libtermcap.a not finding it, so i copied it from my powerpc target system and put it where it was looking in builtins subfolder in bash project and it built my bash binary. (Yea i had tried -I./lib/termcap -ltermcap both to zig cc or to LDFLAGS=-L/libtermcap -ltermcap etc but still gave termcap.h file not found, that's why i ended up just giving in and editing tcap.h) But again Segmentation Fault (UPDATE: I also tried to go into the ./lib/termcap folder and use zig to cross-compile that and created the libtermcap.a and then instead of using libtermcap.so borrowed from target powerpc, i copied this libtermcap.a to the ./builtins subfolder which was a path it was looking for libterm in and it built bash binary but again it Segfaulted on powerpc system), so maybe i'll try not be as lazy and see about letting it use system termcap.h etc and see about letting it build it's own matching libtermcap.so... but if you use -I/usr/include to use the system installed termcap you get: ``` End of search list. In file included from display.c:37: In file included from /usr/include/stdlib.h:1045: /root/ZIG/zig-linux-aarch64-0.14.0-dev.1632+d83a3f174/lib/libc/include/generic-glibc/bits/stdlib-ldbl.h:41:21: error: use of undeclared identifier 'strfroml' 41 | __LDBL_REDIR1_DECL (strfroml, strfromd) | ^ In file included from display.c:42: /usr/include/stdio.h:205:27: error: use of undeclared identifier 'L_tmpnam' 205 | extern char *tmpnam (char[L_tmpnam]) __THROW __wur; | ^ /usr/include/stdio.h:210:33: error: use of undeclared identifier 'L_tmpnam' 210 | extern char *tmpnam_r (char __s[L_tmpnam]) __THROW __wur; | ^ display.c:251:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype] 251 | expand_prompt (pmt, lp, lip, niflp, vlp) ``` Anyway the main point here is that this time (since using powerpc-linux-gnueabihf instead of "musl..." or i ran ./configure differently?) I had no need of creating those compatibility time64.c files and no need of creating sigsetjmp.c (didn't get undefined sigsetjmp symbol). Unfortunately so far the binaries I've built all Segfault on powerpc. A simple ./configure and "make" does create a perfectly fine bash and bashversion that runs on the pi4 no problem. Oh and i tried to cross-compile via g++-12-powerpc...but well seems debian 12 onlhy provides powerpc64le, no 32bit.
jittygitty commented 1 month ago

Ok i confirmed that when I use musl, I can't specify ./configure --host=powerpc-linux-musleabihf since it doesn't recognize it so I just configured and built via:

root:~/ZIG/zig-master/bash-4.2.53# ./configure --build=aarch64-unknown-linux-gnu --verbose
root:~/ZIG/zig-master/bash-4.2.53# make CC="/root/ZIG/zig-master/zig cc -v -target powerpc-linux-musleabihf -mcpu=e500" CXX="/root/ZIG/zig-master/zig c++ -target powerpc-linux-musleabihf -mcpu=e500"

rm -f syntax.c
./mksyntax -o syntax.c
./mksyntax: 1: Syntax error: "(" unexpected
make: *** [Makefile:669: syntax.c] Error 2

Know why do I get these issues with mksyntax.c binary and mkbuiltins and mksignames... with musl but not with gnueabihf? (EDIT: To answer my own question had nothing to do with musleabihf versus gnueabihf, but that --host=powerpc-linux-gnueabihf was accepted while --host=powerpc-linux-musleabihf wasn't, that's the reason, more details in https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556 )

jittygitty commented 1 month ago

@alexrp @andrewrk Hi! Did you guys purposefully fix the time64 stuff in musl in the latest master from 9/30/2024?

root@rpi4-20220808:~/ZIG# ls -l zig-master2
lrwxrwxrwx 1 root root 44 Sep 30 06:14 zig-master2 -> zig-linux-aarch64-0.14.0-dev.1694+3b465ebec/

Because seems I was able to build it properly this time, it built an actual static binary and it did "not" complain about all that time64 stuff as undefined symbols etc! Anyway, unless I somehow messed up before, seems you fixed it, so many thanks!

I should add that if I built it normally, though bashversion ran fine on the powerpc target, "bash" would give: bash: xmalloc: locale.c:73: cannot allocate 18 bytes (0 bytes allocated)

I fixed that with:

./configure --build=aarch64-unknown-linux-gnu --without-bash-malloc --disable-mem-scramble --verbose

(Yea guess there's no need for disable mem scramble, i think i had forgotten do a make distclean and added it then..)

Anyway, the great thing is I can confirm that I have working bash and bashversion binaries cross-compiled (on a raspberry pi4) with zig for a target of powerpc elf 32bit via:

root@rpi4:~/ZIG/zig-master2/bash-4.2.53# time make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" CXX="/root/ZIG/zig-master2/zig c++ -target powerpc-linux-musleabihf -mcpu=e500"

In case it HELPS others, there are a few other "annoyances" you have to fix manually along the way, like:

``` root@rpi4:~/ZIG/zig-master2/bash-4.2.53# time make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" CXX="/root/ZIG/zig-master2/zig c++ -target powerpc-linux-musleabihf -mcpu=e500" ./mksyntax -o syntax.c ./mksyntax: 1: Syntax error: "(" unexpected make: *** [Makefile:669: syntax.c] Error 2 root@rpi4:~/ZIG/zig-master2/bash-4.2.53# ../zig build-exe -I. support/mksignames.c support/signames.c -lc root@rpi4:~/ZIG/zig-master2/bash-4.2.53# time make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" CXX="/root/ZIG/zig-master2/zig c++ -target powerpc-linux-musleabihf -mcpu=e500" ./mksyntax -o syntax.c ./mksyntax: 1: Syntax error: "(" unexpected make: *** [Makefile:669: syntax.c] Error 2 root@rpi4:~/ZIG/zig-master2/bash-4.2.53# ../zig build-exe -I./include mksyntax.c -lc root@rpi4:~/ZIG/zig-master2/bash-4.2.53# time make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" CXX="/root/ZIG/zig-master2/zig c++ -target powerpc-linux-musleabihf -mcpu=e500" ./mkbuiltins: 1: Syntax error: "(" unexpected make[1]: *** [Makefile:168: builtext.h] Error 2 make[1]: Leaving directory '/root/ZIG/zig-linux-aarch64-0.14.0-dev.1694+3b465ebec/bash-4.2.53/builtins' make: *** [Makefile:682: builtins/builtext.h] Error 1 root@rpi4:~/ZIG/zig-master2/bash-4.2.53# ../zig build-exe -I. -I./include builtins/mkbuiltins.c -lc root@rpi4:~/ZIG/zig-master2/bash-4.2.53# file mkbuiltins mkbuiltins: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, with debug_info, not stripped root@rpi4:~/ZIG/zig-master2/bash-4.2.53# file builtins/mkbuiltins builtins/mkbuiltins: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, with debug_info, not stripped root@rpi4:~/ZIG/zig-master2/bash-4.2.53# cp mkbuiltins builtins/mkbuiltins root@rpi4:~/ZIG/zig-master2/bash-4.2.53# time make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" CXX="/root/ZIG/zig-master2/zig c++ -target powerpc-linux-musleabihf -mcpu=e500" ./mksignames lsignames.h ./mksignames: 1: Syntax error: "(" unexpected make: *** [Makefile:661: lsignames.h] Error 2 root@rpi4:~/ZIG/zig-master2/bash-4.2.53# ../zig build-exe -I. support/mksignames.c support/signames.c -lc root@rpi4:~/ZIG/zig-master2/bash-4.2.53# time make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" CXX="/root/ZIG/zig-master2/zig c++ -target powerpc-linux-musleabihf -mcpu=e500" ls -l bash -rwxr-xr-x 1 root root 4677916 Oct 1 04:03 bash size bash text data bss dec hex filename 1437016 38948 32264 1508228 170384 bash /bin/sh: 1: /root/ZIG/zig-master2/bash-4.2.53/bashversion: Exec format error real 1m11.107s user 0m49.550s sys 0m18.531s root@rpi4:~/ZIG/zig-master2/bash-4.2.53# file bashversion bashversion: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, with debug_info, not stripped root@rpi4:~/ZIG/zig-master2/bash-4.2.53# file bash bash: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, with debug_info, not stripped root@rpi4:~/ZIG/zig-master2/bash-4.2.53# du bash bashversion 4572 bash 1064 bashversion ```
alexrp commented 1 month ago

Hi! Did you guys purposefully fix the time64 stuff in musl in the latest master from 9/30/2024?

No, I actually hadn't found time to properly look at this yet. But if it works after all, that's great!

I fixed that with:

I'm not familiar with Bash's build system, but I will note that, for most C/C++ projects, running configure with a different compiler (in this case, presumably, your system cc) than the one you use when invoking make is usually a bad idea because the configuration checks can reach completely wrong conclusions for the actual target you're compiling for in the end. You would usually want to set CC when invoking configure. This could potentially explain the xmalloc failure, but that's just a guess.

jittygitty commented 1 month ago

Yea, my apologies, I think main problem is I was working yet again too late without sleep and brain dead. I think previously my issue was likely forgetting make distclean and then getting "compounded errors" : D instead of earning compounded intere$t.

Seems I was switching between linux-gnueabihf and musl in the same tree/folder and not cleaning and then forgot -ltermcap or ./lib/termcap while building for musl when should of been only when targetting the gnueabihf not musl.

I might still mess with trying to get powerpc-linux-gnueabihf to work since I'm a little bit worried if the static bash with musl will really run all our scripts the same way as the one built via powerpc gnueabihf, or am I paranoid for no good reason? thx!

@alexrp Oh, and any comment on me having to disable bash's malloc? ie to avoid: bash: xmalloc: locale.c:73: cannot allocate 18 bytes (0 bytes allocated) Can that cause me any issues, or should it be fine compatibility wise? thx!

And as far as enabling malloc again, could you please explain what you mean, by setting CC when invoking configure? I ran configure normally as "./configure etc" and after ran make with Zig cc, so I wonder what alternate way would be? thx!

alexrp commented 1 month ago

I might still mess with trying to get powerpc-linux-gnueabihf to work since I'm a little bit worried if the static bash with musl will really run all our scripts the same way as the one built via gnueabihf, or am I paranoid for no good reason? thx!

In principle I wouldn't expect this to make a difference. But I'm not familiar with the Bash codebase.

Can that cause me any issues, or should it be fine compatibility wise? thx!

Probably not? But I'm just making a semi-educated guess.

jittygitty commented 1 month ago

Anyway, I'm happy I at least built working musl static binary with ZIG. I can cross compile for powerpc-linux-gnueabihf in about same way, but the resulting binaries give Segmentation fault and the gdb on the target powerpc can't do dwarf 4, only dwarf 2. Wonder how hard/easy it would be to cross-compile a newer version of gdb with zig? maybe, I'll try it next.

(EDIT: I have confirmed, if you do NOT specify a proper --host= directive that ./configure recognizes and understand, you WILL have to do those manual overrides and build mksyntax.c/mkbuiltins/mksignames/etc for the build platform (pi4 in my case, even though target is powerpc. On pi4 i found --host=powerpc-unknown-linux-gnu or --host=powerpc-linux-gnueabihf worked fine, for musl on pi4 , the --host=powerpc-linux-musleabihf didn't work that's why i had to do the mksyntax.c etc workarounds, but you can likely cheat and use --host=powerpc-unknown-linux-gnu and still make/build with target powerpc-linux-musleabihf. So always try to include proper configure --host directive if cross-compiling etc.)

Though ZIG built the powerpc-linux-gnueabihf binary easily via:

./configure --build=aarch64-unknown-linux-gnu --host=powerpc-linux-gnueabihf --verbose
make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-gnueabihf -mcpu=e500"

(The resulting binary still gave Segmentation fault and gdb on that powerpc target needs dwarf2, so will see...)

Anyway, unfortunately I have not been able to build a STATIC binary of bash-4.2.53 with ZIG, targeting powerpc-linux-gnueabihf, it keeps building a dynamically linked binary.

But here's easiest way I found to build a working STATIC bash binary with ZIG targeting powerpc-linux-musleabihf :

You can avoid editing tcap.h etc if you either don't have any termcap.h anywhere systemwide, outside your bash sources folder, or if you rename any termcap.h you have system-wide so it can't be found, or ideally if you're smarter or more awake than me and properly told config or make to just use the bash-4.2.53/lib/termcap/termcap.h , then you won't have to do any of the tcap.h editing or manually building in the termcap subfolder and copying over libtermcap.a etc, and you'd be done with just those "two" simple ./configure and make commands below and nothing else to do. ``` root@rpi4:~/ZIG/zig-master/bash-4.2.53# ./configure --host=powerpc-unknown-linux-gnu --build=aarch64-unknown-linux-gnu --without-bash-malloc --verbose LDFLAGS=-static root@rpi4:~/ZIG/zig-master/bash-4.2.53# make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" ..... clang -cc1 version 19.1.0 based upon LLVM 19.1.0 default target aarch64-linux-musl ignoring duplicate directory "../.." #include "..." search starts here: #include <...> search starts here: . /root/ZIG/zig-master/bash-4.2.53 ../../lib /root/ZIG/zig-linux-aarch64-0.14.0-dev.1694+3b465ebec/lib/include /root/ZIG/zig-linux-aarch64-0.14.0-dev.1694+3b465ebec/lib/libc/include/powerpc-linux-musl /root/ZIG/zig-linux-aarch64-0.14.0-dev.1694+3b465ebec/lib/libc/include/generic-musl /root/ZIG/zig-linux-aarch64-0.14.0-dev.1694+3b465ebec/lib/libc/include/powerpc-linux-any /root/ZIG/zig-linux-aarch64-0.14.0-dev.1694+3b465ebec/lib/libc/include/any-linux-any End of search list. In file included from display.c:49: ./tcap.h:33:12: fatal error: 'termcap.h' file not found 33 | # include | ^~~~~~~~~~~ 1 error generated. make[1]: *** [Makefile:69: display.o] Error 1 make[1]: Leaving directory '/root/ZIG/zig-linux-aarch64-0.14.0-dev.1632+d83a3f174/bash-4.2.53/lib/readline' make: *** [Makefile:602: lib/readline/libreadline.a] Error 1 root@rpi4:~/ZIG/zig-master/bash-4.2.53# perl -pi -e 's/# include /# include "\.\.\/termcap\/termcap\.h"/g;' lib/readline/tcap.h root@rpi4:~/ZIG/zig-master/bash-4.2.53# pushd lib/termcap root@rpi4:~/ZIG/zig-master/bash-4.2.53/lib/termcap# make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" ... root@rpi4:~/ZIG/zig-master/bash-4.2.53/lib/termcap# cp libtermcap.a ../../builtins/ root@rpi4:~/ZIG/zig-master/bash-4.2.53/lib/termcap# popd root@rpi4:~/ZIG/zig-master/bash-4.2.53# make CC="/root/ZIG/zig-master2/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" ls -l bash -rwxr-xr-x 1 root root 4603536 Oct 2 22:26 bash root@rpi4:~/ZIG/zig-master/bash-4.2.53# file bash bash: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, with debug_info, not stripped ```

(Use gnu89 with ZIG as above, or you'll end up with big headache trying to fix errors via code changes/fixes/updates etc.)

(Trying to pass ZIG as the CC while configuring, ie: CC="/root/ZIG/zig-master/zig cc -v -std=gnu89 -target powerpc-linux-musleabihf -mcpu=e500" ./configure --host=powerpc-unknown-linux-gnu --build=x86_64-unknown-linux-gnu --verbose LDFLAGS=-static , unfortunately did not allow me to use internal malloc, I still had to use the --without-bash-malloc )

WITHOUT ZIG:

But I found that even though AARCH64 Debian 12/bookworm didn't have gcc compiler for PowerPC elf 32-BIT, that the 32-Bit PowerPC compiler is available on Debian 12/bookworm X86_64! And that was able to build a STATIC binary with GLIBC that ran just fine on my target powerpc, without segmentation fault. (Dynamic one needed too new glibc on target) ``` bash-4.2.53# ./configure --host=powerpc-linux-gnueabihf --build=x86_64-unknown-linux-gnu --verbose LDFLAGS=-static bash-4.2.53# make CC="powerpc-linux-gnu-gcc -static -mtune=e500mc -m32" LDFLAGS=-static ``` That's it, just those "two" commands above will build a working static bash binary for powerpc without any other intervention, no editing tcap.h for termcap or anything else. Not sure how to get zig to build a static bash with glibc.

@alexrp I will leave it at that for now, unless you think I "should" be able to build a STATIC bash binary using GLIBC with ZIG cc and target powerpc-linux-gnueabihf? thx

alexrp commented 1 month ago

I will leave it at that for now, unless you think I "should" be able to build a STATIC bash binary using GLIBC with ZIG cc and target powerpc-linux-gnueabihf? thx

In general, it is a bad idea to statically link glibc. It can work in some limited cases, but will break easily. I'm fairly certain this is a use case we just don't support in Zig.

jittygitty commented 1 month ago

Ok thanks for the info, I'll stick with musl for zig static binaries going forward. I may try debug and build dynamic gnueabihf binary once I get around to build a dwarf4 gdb for my powerpc target. And thanks to you and Andrew and all ZIG contributors!

alexrp commented 1 month ago

Will close this since it seems like the original issue is no longer present.