Re: [Toybox] toys/android/log.c with android NDK?
On 03/16/2018 01:34 PM, enh wrote: >> Ah, here's the problem: >> >> $ /opt/android/x86-64/bin/llvm-cc -llog hello.c >> $ ./a.out >> bash: ./a.out: No such file or directory >> $ /opt/android/x86-64/bin/llvm-cc -llog hello.c --static >> /opt/android/x86-64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: >> cannot find -llog >> clang60: error: linker command failed with exit code 1 (use -v to see >> invocation) >> >> The library only exists for dynamic, not static. And I can't run a dynamic >> bionic binary on an ubuntu host. > > not _strictly_ true: you can install /system/bin/linker64 and all the > libraries you need in /system/lib64. Hmmm... Different search path, avoids collision with the host libraries. Feasible. >> Of course... >> >> $ /opt/android/x86-64/bin/llvm-cc --static hello.c >> $ ./a.out >> Illegal instruction (core dumped) >> >> Still an issue with api 28. > > works for me. > > are you running on hardware so old that it doesn't meet the minimum > ABI requirements for Android x86-64? from > https://developer.android.com/ndk/guides/abis.html that's MMX, SSE2, > SSE3, and SSSE3, SSE4.1, SSE4.2, and POPCNT. $ grep 'model name' /proc/cpuinfo model name : AMD C-60 APU with Radeon(tm) HD Graphics model name : AMD C-60 APU with Radeon(tm) HD Graphics So yes, probably. (My netbook is the programming equivalent of a ratty old t-shirt. More than one co-worker has threatened to ritually burn it.) I'll see if I can throw qemu at the problem. > if you're seeing SIGILL on an instruction not covered by those, that > would be a bug. but Android never shipped on CPUs lower than the above > bar. Mostly it ships on arm anyway. :) AOSP and the ADK use a qemu fork and I test with vanilla qemu, but many moons ago (2010?) I did a contract porting the android base OS layers to the TI netra for a videoconferencing thing, which meant I built an android kernel from source and got it to boot to a shell prompt. What I'm trying to do at the moment is figure out how to shoehorn the android kernel source tree into https://github.com/landley/mkroot with a config for qemu and use the NDK toolchain as the compiler, and get it to boot to a shell prompt. (I have aarch64, armv7l, x86-64, and several others doing that with musl-cross-make and the vanilla kernel already.) Would have been nice if it worked on the host, but at least now I know why it doesn't... $ CROSS_COMPILE=... make more warnings, more warnings... scripts/make.sh: line 28: /opt/android/x86-64/bin/llvm-strip: No such file or directory strip failed, using unstripped >> >> You know that one's trivial enough I might just add a "strip" to toybox. >> (It's >> basically objcopy with some excludes.) >> >> (The hiccup is that the japanese developers implementing the sh4 toolchain >> had a >> translated copy of the ELF spec and the codepage switch turned "_" into "." >> so >> they dutifully used . as the symbol prefix, and if you use the wrong strip >> there >> it mangles your executables. So one strip working on all targets requires >> checking to see what if any prefix is currently in use, and that's why I use >> the >> prefixed strip.) And nm doesn't look too hard either. This is a rathole I probably shouldn't go down _right_ now. Lemme close a few more tabs first... Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] toys/android/log.c with android NDK?
On Mon, Mar 12, 2018 at 11:06 AM, Rob Landleywrote: > On 03/10/2018 11:06 PM, enh wrote: >>> $ sudo build/tools/make_standalone_toolchain.py --arch x86_64 --api 26 \ >>> --stl=libc++ --install-dir=/opt/android/x86-64 >>> $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make defconfig >>> It has no llvm-cc... ok then: >>> $ sudo ln -s clang /opt/android/x86-64/bin/llvm-cc >>> $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make defconfig >>> $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make >>> many warnings ignored... >>> generated/obj/log.o:log.c:function log_main: error: undefined reference to >>> '__android_log_write' >>> $ CROSS_COMPILE=... make menuconfig # switch off log in android menu. >> >> (or add -llog.) > > Hmmm, should already be there in scripts/make.sh... > > # We trust --as-needed to remove each library if we don't use any symbols > # out of it, this loop is because the compiler has no way to ignore a > library > # that doesn't exist, so we have to detect and skip nonexistent libraries > # for it. > > > generated/optlibs.dat > for i in util crypt m resolv selinux smack attr rt crypto z log > do > > Ah, here's the problem: > > $ /opt/android/x86-64/bin/llvm-cc -llog hello.c > $ ./a.out > bash: ./a.out: No such file or directory > $ /opt/android/x86-64/bin/llvm-cc -llog hello.c --static > /opt/android/x86-64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: > cannot find -llog > clang60: error: linker command failed with exit code 1 (use -v to see > invocation) > > The library only exists for dynamic, not static. And I can't run a dynamic > bionic binary on an ubuntu host. not _strictly_ true: you can install /system/bin/linker64 and all the libraries you need in /system/lib64. > Of course... > > $ /opt/android/x86-64/bin/llvm-cc --static hello.c > $ ./a.out > Illegal instruction (core dumped) > > Still an issue with api 28. works for me. are you running on hardware so old that it doesn't meet the minimum ABI requirements for Android x86-64? from https://developer.android.com/ndk/guides/abis.html that's MMX, SSE2, SSE3, and SSSE3, SSE4.1, SSE4.2, and POPCNT. if you're seeing SIGILL on an instruction not covered by those, that would be a bug. but Android never shipped on CPUs lower than the above bar. >>> $ CROSS_COMPILE=... make >>> more warnings, more warnings... >>> scripts/make.sh: line 28: /opt/android/x86-64/bin/llvm-strip: No such file >>> or >>> directory >>> strip failed, using unstripped > > You know that one's trivial enough I might just add a "strip" to toybox. (It's > basically objcopy with some excludes.) > > (The hiccup is that the japanese developers implementing the sh4 toolchain > had a > translated copy of the ELF spec and the codepage switch turned "_" into "." so > they dutifully used . as the symbol prefix, and if you use the wrong strip > there > it mangles your executables. So one strip working on all targets requires > checking to see what if any prefix is currently in use, and that's why I use > the > prefixed strip.) > >>> And that file is doing #include so I don't see _why_ it's not >>> getting >>> them? >> >> because isn't there until API 28, but a side-effect of the >> single sysroot for all API levels is that the *file* is there, but the >> contents are #ifdef'ed out since you asked for API level 26. > > Cut and paste from the example in the web page. :) > > I redid it with api 28, and switching off android/log I got the rest of it to > build. But the result still immediately segfaults, as does hello world. > > (I tried building with the included gcc toolchain too: same thing.) > >> we'll be able to provide better errors (along the lines of "iconv_open >> is only available in API level 28 and later") when we remove GCC later >> this year and only have to support clang, but r17 still includes GCC >> so it's just #ifdef'ed out. > > The ability to build an x86-64 hello world binary statically linked against > bionic which runs on an ubuntu host would be nice. Is there a design reason > that's not supported? > > Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] toys/android/log.c with android NDK?
On 03/10/2018 11:06 PM, enh wrote: >> $ sudo build/tools/make_standalone_toolchain.py --arch x86_64 --api 26 \ >> --stl=libc++ --install-dir=/opt/android/x86-64 >> $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make defconfig >> It has no llvm-cc... ok then: >> $ sudo ln -s clang /opt/android/x86-64/bin/llvm-cc >> $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make defconfig >> $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make >> many warnings ignored... >> generated/obj/log.o:log.c:function log_main: error: undefined reference to >> '__android_log_write' >> $ CROSS_COMPILE=... make menuconfig # switch off log in android menu. > > (or add -llog.) Hmmm, should already be there in scripts/make.sh... # We trust --as-needed to remove each library if we don't use any symbols # out of it, this loop is because the compiler has no way to ignore a library # that doesn't exist, so we have to detect and skip nonexistent libraries # for it. > generated/optlibs.dat for i in util crypt m resolv selinux smack attr rt crypto z log do Ah, here's the problem: $ /opt/android/x86-64/bin/llvm-cc -llog hello.c $ ./a.out bash: ./a.out: No such file or directory $ /opt/android/x86-64/bin/llvm-cc -llog hello.c --static /opt/android/x86-64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -llog clang60: error: linker command failed with exit code 1 (use -v to see invocation) The library only exists for dynamic, not static. And I can't run a dynamic bionic binary on an ubuntu host. Of course... $ /opt/android/x86-64/bin/llvm-cc --static hello.c $ ./a.out Illegal instruction (core dumped) Still an issue with api 28. >> $ CROSS_COMPILE=... make >> more warnings, more warnings... >> scripts/make.sh: line 28: /opt/android/x86-64/bin/llvm-strip: No such file or >> directory >> strip failed, using unstripped You know that one's trivial enough I might just add a "strip" to toybox. (It's basically objcopy with some excludes.) (The hiccup is that the japanese developers implementing the sh4 toolchain had a translated copy of the ELF spec and the codepage switch turned "_" into "." so they dutifully used . as the symbol prefix, and if you use the wrong strip there it mangles your executables. So one strip working on all targets requires checking to see what if any prefix is currently in use, and that's why I use the prefixed strip.) >> And that file is doing #include so I don't see _why_ it's not >> getting >> them? > > because isn't there until API 28, but a side-effect of the > single sysroot for all API levels is that the *file* is there, but the > contents are #ifdef'ed out since you asked for API level 26. Cut and paste from the example in the web page. :) I redid it with api 28, and switching off android/log I got the rest of it to build. But the result still immediately segfaults, as does hello world. (I tried building with the included gcc toolchain too: same thing.) > we'll be able to provide better errors (along the lines of "iconv_open > is only available in API level 28 and later") when we remove GCC later > this year and only have to support clang, but r17 still includes GCC > so it's just #ifdef'ed out. The ability to build an x86-64 hello world binary statically linked against bionic which runs on an ubuntu host would be nice. Is there a design reason that's not supported? Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] toys/android/log.c with android NDK?
On Sat, Mar 10, 2018 at 8:26 PM, Rob Landleywrote: > On 03/09/2018 03:54 PM, enh wrote: >> well, that took a lot longer than expected... but r17beta1 is out now >> with an up-to-date libc.a. >> >> download: https://github.com/android-ndk/ndk/wiki#current-beta-release >> release notes: https://github.com/android-ndk/ndk/wiki/Changelog-r17-beta1 >> >> standalone toolchain example: >> https://developer.android.com/ndk/guides/standalone_toolchain.html#building_open_source_projects_using_standalone_toolchains >> >> (https://developer.android.com/ndk/downloads/index.html should update >> later this afternoon.) > > Let's see... > > $ sudo build/tools/make_standalone_toolchain.py --arch x86_64 --api 26 \ > --stl=libc++ --install-dir=/opt/android/x86-64 > $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make defconfig > It has no llvm-cc... ok then: > $ sudo ln -s clang /opt/android/x86-64/bin/llvm-cc > $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make defconfig > $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make > many warnings ignored... > generated/obj/log.o:log.c:function log_main: error: undefined reference to > '__android_log_write' > $ CROSS_COMPILE=... make menuconfig # switch off log in android menu. (or add -llog.) > $ CROSS_COMPILE=... make > more warnings, more warnings... > scripts/make.sh: line 28: /opt/android/x86-64/bin/llvm-strip: No such file or > directory > strip failed, using unstripped > $ ./toybox > Illegal instruction (core dumped) > landley@driftwood:~/toybox/clean$ file toybox > toybox: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically > linked, > not stripped > > Well... it's certainly progress. :) > > I'll see if I can work out why it doesn't run... > > $ /opt/android/x86-64/bin/llvm-cc --static hello.c > $ ./a.out > Illegal instruction (core dumped) > > Because a statically linked hello world segfaults on ubuntu 14.04, would be > why. > > The warnings, by the way, are primarily: > > toys/posix/iconv.c:53:5: warning: implicit declaration of function 'iconv' is > invalid in C99 [-Wimplicit-function-declaration] > iconv(TT.ic, , , , ); > ^ > toys/posix/iconv.c:70:31: warning: implicit declaration of function > 'iconv_open' > is invalid in C99 [-Wimplicit-function-declaration] > if ((iconv_t)-1 == (TT.ic = iconv_open(TT.to, TT.from))) > ^ > toys/posix/iconv.c:73:24: warning: implicit declaration of function > 'iconv_close' is invalid in C99 [-Wimplicit-function-declaration] > if (CFG_TOYBOX_FREE) iconv_close(TT.ic); > > And that file is doing #include so I don't see _why_ it's not > getting > them? because isn't there until API 28, but a side-effect of the single sysroot for all API levels is that the *file* is there, but the contents are #ifdef'ed out since you asked for API level 26. we'll be able to provide better errors (along the lines of "iconv_open is only available in API level 28 and later") when we remove GCC later this year and only have to support clang, but r17 still includes GCC so it's just #ifdef'ed out. > Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] toys/android/log.c with android NDK?
On 03/09/2018 03:54 PM, enh wrote: > well, that took a lot longer than expected... but r17beta1 is out now > with an up-to-date libc.a. > > download: https://github.com/android-ndk/ndk/wiki#current-beta-release > release notes: https://github.com/android-ndk/ndk/wiki/Changelog-r17-beta1 > > standalone toolchain example: > https://developer.android.com/ndk/guides/standalone_toolchain.html#building_open_source_projects_using_standalone_toolchains > > (https://developer.android.com/ndk/downloads/index.html should update > later this afternoon.) Let's see... $ sudo build/tools/make_standalone_toolchain.py --arch x86_64 --api 26 \ --stl=libc++ --install-dir=/opt/android/x86-64 $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make defconfig It has no llvm-cc... ok then: $ sudo ln -s clang /opt/android/x86-64/bin/llvm-cc $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make defconfig $ CROSS_COMPILE=/opt/android/x86-64/bin/llvm- CFLAGS=--static make many warnings ignored... generated/obj/log.o:log.c:function log_main: error: undefined reference to '__android_log_write' $ CROSS_COMPILE=... make menuconfig # switch off log in android menu. $ CROSS_COMPILE=... make more warnings, more warnings... scripts/make.sh: line 28: /opt/android/x86-64/bin/llvm-strip: No such file or directory strip failed, using unstripped $ ./toybox Illegal instruction (core dumped) landley@driftwood:~/toybox/clean$ file toybox toybox: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped Well... it's certainly progress. :) I'll see if I can work out why it doesn't run... $ /opt/android/x86-64/bin/llvm-cc --static hello.c $ ./a.out Illegal instruction (core dumped) Because a statically linked hello world segfaults on ubuntu 14.04, would be why. The warnings, by the way, are primarily: toys/posix/iconv.c:53:5: warning: implicit declaration of function 'iconv' is invalid in C99 [-Wimplicit-function-declaration] iconv(TT.ic, , , , ); ^ toys/posix/iconv.c:70:31: warning: implicit declaration of function 'iconv_open' is invalid in C99 [-Wimplicit-function-declaration] if ((iconv_t)-1 == (TT.ic = iconv_open(TT.to, TT.from))) ^ toys/posix/iconv.c:73:24: warning: implicit declaration of function 'iconv_close' is invalid in C99 [-Wimplicit-function-declaration] if (CFG_TOYBOX_FREE) iconv_close(TT.ic); And that file is doing #include so I don't see _why_ it's not getting them? Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] toys/android/log.c with android NDK?
well, that took a lot longer than expected... but r17beta1 is out now with an up-to-date libc.a. download: https://github.com/android-ndk/ndk/wiki#current-beta-release release notes: https://github.com/android-ndk/ndk/wiki/Changelog-r17-beta1 standalone toolchain example: https://developer.android.com/ndk/guides/standalone_toolchain.html#building_open_source_projects_using_standalone_toolchains (https://developer.android.com/ndk/downloads/index.html should update later this afternoon.) On Fri, Feb 16, 2018 at 7:51 AM, Rob Landleywrote: > > n 02/14/2018 06:30 PM, enh wrote: >> On Wed, Feb 14, 2018 at 3:36 PM, Rob Landley wrote: >>> More to the point all of this _compiled_, meaning it's in the headers. And >>> then >>> it couldn't find it in the libraries. So there's a consistency issue >>> somewhere. >> >> i suspect you said "--api 26" but then also tried to build a static >> binary? in which case you linked against an api 21 libc.a. as i said > > Yup, has to be statically compiled to run on an ubuntu host. > >> (somewhere) earlier today, NDK r17 (and later) will have a modern >> libc.a, but for NDK r16 you'll want to either (a) set --api 21 for >> static binaries or (b) build a dynamic binary for --api 26. > > Ok, I'll try again when the new one comes out. > >> longer term >> (https://android.googlesource.com/platform/ndk/+/master/docs/Roadmap.md) >> we want to make standalone toolchains obsolete by just teaching the >> clang driver everything it needs to know about Android, so hopefully >> before the end of the year it's just a matter of `CC=ndk-clang make >> defconfig`. > > I don't have context to know what's involved there. > >>> I can try to fix it up in lib/portability.c...? >> >> the __android_log_write thing might need a fix on your side: i suspect >> you're missing a -l for the NDK liblog? > > I'll try to fix it up when I get the new ndk. > > Thanks, > > Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] toys/android/log.c with android NDK?
n 02/14/2018 06:30 PM, enh wrote: > On Wed, Feb 14, 2018 at 3:36 PM, Rob Landleywrote: >> More to the point all of this _compiled_, meaning it's in the headers. And >> then >> it couldn't find it in the libraries. So there's a consistency issue >> somewhere. > > i suspect you said "--api 26" but then also tried to build a static > binary? in which case you linked against an api 21 libc.a. as i said Yup, has to be statically compiled to run on an ubuntu host. > (somewhere) earlier today, NDK r17 (and later) will have a modern > libc.a, but for NDK r16 you'll want to either (a) set --api 21 for > static binaries or (b) build a dynamic binary for --api 26. Ok, I'll try again when the new one comes out. > longer term > (https://android.googlesource.com/platform/ndk/+/master/docs/Roadmap.md) > we want to make standalone toolchains obsolete by just teaching the > clang driver everything it needs to know about Android, so hopefully > before the end of the year it's just a matter of `CC=ndk-clang make > defconfig`. I don't have context to know what's involved there. >> I can try to fix it up in lib/portability.c...? > > the __android_log_write thing might need a fix on your side: i suspect > you're missing a -l for the NDK liblog? I'll try to fix it up when I get the new ndk. Thanks, Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] toys/android/log.c with android NDK?
On Wed, Feb 14, 2018 at 3:36 PM, Rob Landleywrote: > I grabbed the current ndk (-r16b), make_standalone_toolchain.py'd an --arch > x86_64 --api 26 toolchain, and then built defconfig toybox with it, and at > link > time it failed to find: > > '__android_log_write' > 'facilitynames' > 'getgrgid_r' > 'iconv' > 'iconv_open' > 'prioritynames' > 'sethostname' > 'stderr' > 'stdin' > 'stdout' > > I've mentioned stdin/stdout/stderr here before. sethostname() is a trivial > syscall wrapper, iconv() and iconv_open() I _know_ bionic has because I > complained about them being implemented in c++, android_log_write() is your > own > function (and the double underscore is confusing)... > > More to the point all of this _compiled_, meaning it's in the headers. And > then > it couldn't find it in the libraries. So there's a consistency issue > somewhere. i suspect you said "--api 26" but then also tried to build a static binary? in which case you linked against an api 21 libc.a. as i said (somewhere) earlier today, NDK r17 (and later) will have a modern libc.a, but for NDK r16 you'll want to either (a) set --api 21 for static binaries or (b) build a dynamic binary for --api 26. longer term (https://android.googlesource.com/platform/ndk/+/master/docs/Roadmap.md) we want to make standalone toolchains obsolete by just teaching the clang driver everything it needs to know about Android, so hopefully before the end of the year it's just a matter of `CC=ndk-clang make defconfig`. > I can try to fix it up in lib/portability.c...? the __android_log_write thing might need a fix on your side: i suspect you're missing a -l for the NDK liblog? > Rob > ___ > Toybox mailing list > Toybox@lists.landley.net > http://lists.landley.net/listinfo.cgi/toybox-landley.net ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
[Toybox] toys/android/log.c with android NDK?
I grabbed the current ndk (-r16b), make_standalone_toolchain.py'd an --arch x86_64 --api 26 toolchain, and then built defconfig toybox with it, and at link time it failed to find: '__android_log_write' 'facilitynames' 'getgrgid_r' 'iconv' 'iconv_open' 'prioritynames' 'sethostname' 'stderr' 'stdin' 'stdout' I've mentioned stdin/stdout/stderr here before. sethostname() is a trivial syscall wrapper, iconv() and iconv_open() I _know_ bionic has because I complained about them being implemented in c++, android_log_write() is your own function (and the double underscore is confusing)... More to the point all of this _compiled_, meaning it's in the headers. And then it couldn't find it in the libraries. So there's a consistency issue somewhere. I can try to fix it up in lib/portability.c...? Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net