Closed jittygitty closed 1 month ago
Hi @Kevin-Otalvares Are you a nice virus bot or a bad one?
A bad bot, please do not click on the link.
@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 : )
Please format the output in a code block using triple backticks. 🙂
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.
Cleanup, best skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556
Better to skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556
@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 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
?
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
Best skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556
Better to skip to https://github.com/ziglang/zig/issues/21465#issuecomment-2384921556
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 )
@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:
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.
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!
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.
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 :
(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:
@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
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.
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!
Will close this since it seems like the original issue is no longer present.
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
Expected Behavior
Expected behavior: build bash for 32bit powerpc without complaining : )