Re: [Toybox] llvm regression test.
On 5/4/20 5:03 PM, Rob Landley wrote: > $ root/x86_64/fs/bin/toybox echo hello > hello > $ sudo chroot root/x86_64/fs /init > Segmentation fault > > Looks like I've still got some work to do before the release... No, I don't. I can't fix this. A) Statically linked bionic is almost as big as glibc? $ ~/android/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-cc hello.c --static $ ls -l a.out -rwxr-xr-x 1 landley landley 392 May 4 23:52 a.out $ file a.out a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped $ strip a.out $ ls -l a.out -rwxr-xr-x 1 landley landley 676904 May 4 23:52 a.out $ ./a.out hello (glibc static hello world strips to 738384 bytes, With musl, 5240 bytes.) B) the problem is if /dev/null isn't there, bionic's startup code segfaults before reaching main(). $ mkdir empty $ mv a.out empty $ sudo chroot empty ./a.out Segmentation fault $ sudo strace chroot empty ./a.out ... mprotect(0x4a7000, 4096, PROT_READ) = 0 mprotect(0x4a7000, 4096, PROT_READ|PROT_WRITE) = 0 mprotect(0x4a7000, 4096, PROT_READ) = 0 openat(AT_FDCWD, "/dev/null", O_RDWR) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/sys/fs/selinux/null", O_RDWR) = -1 ENOENT (No such file or directory) --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x80} --- +++ killed by SIGSEGV +++ Segmentation fault $ mknod empty/dev $ sudo mknod empty/dev/null c 1 3 $ sudo chroot empty ./a.out hello Needless to say, this makes performing initramfs setup with a bionic binary kinda awkward, since /dev isn't populated yet when PID 1 runs. (I sent a patch! Three times! The kernel guys ignored it. https://lkml.org/lkml/2017/9/13/651 .) Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] llvm regression test.
On Mon, May 4, 2020 at 2:57 PM Rob Landley wrote: > What portion of this script does what when? Right, assuming all the bisect > stuff > is ignorable and the command line editing isn't relevant, where's the real > binary it passes through to? > > $ find clang-r377782d -name clang | xargs file > clang-r377782d/include/clang: directory > clang-r377782d/bin/clang: Python script, ASCII text executable > clang-r377782d/lib64/clang: directory > clang-r377782d/lib64/cmake/clang: directory > clang-r377782d/share/clang: directory > You're looking for "clang.real". ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
[Toybox] llvm regression test.
So I'm trying to build under llvm again, and rather than download a new NDK I thought I'd just repo sync and try using the AOSP compiler. Unfortunately, there still isn't a consistent URL _to_ said compiler? $ ls ~/android/aosp/prebuilts/clang/host/linux-x86/clang-stable/bin/ clang-format git-clang-format Ok, grab the highest version clang-*/bin instead and: $ ln -s clang ~/android/aosp/prebuilts/clang/host/linux-x86/clang-r377782d/bin/llvm-cc $ make root CROSS_COMPILE=~/android/aosp/prebuilts/clang/host/linux-x86/clang-r377782d/bin/llvm- Make generated/config.h from .config. generated/flags.h /usr/bin/env: 'python': No such file or directory /usr/bin/env: 'python': No such file or directory Um... what? $ head -n 5 ~/android/aosp/prebuilts/clang/host/linux-x86/clang-r377782d/bin/llvm-cc #!/usr/bin/env python # # Copyright (C) 2017 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); Really, AOSP? Python as a dependency to run the compiler? What is this script doing... def main(argv): cw = CompilerWrapper(argv) if BISECT_STAGE and BISECT_STAGE in bisect_driver.VALID_MODES\ and '-o' in argv: cw.bisect() else: cw.invoke_compiler() Bisect? What... self.execargs += ['-fno-color-diagnostics'] + disabled_warnings def process_gomacc_command(self): """Return the gomacc command if '--gomacc-path' is set.""" gomacc = self.custom_flags['--gomacc-path'] I am very confused. BISECT_STAGE = os.environ.get('BISECT_STAGE') # We do not need bisect functionality with Goma and clang. # Goma server does not have bisect_driver, so we only import # bisect_driver when needed. See http://b/34862041 # We should be careful when doing imports because of Goma. if BISECT_STAGE: import bisect_driver What portion of this script does what when? Right, assuming all the bisect stuff is ignorable and the command line editing isn't relevant, where's the real binary it passes through to? $ find clang-r377782d -name clang | xargs file clang-r377782d/include/clang: directory clang-r377782d/bin/clang: Python script, ASCII text executable clang-r377782d/lib64/clang: directory clang-r377782d/lib64/cmake/clang: directory clang-r377782d/share/clang: directory Right, back to the NDK... $ find android-ndk-r21 -name clang android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/clang Oh darn, I remember this was nonobvious too. (And changed from how it _used_ to work...) Sigh. I googled "android ndk" and got a page of icons trying to look like a phone (https://developer.android.com/ndk) from which the getting started guide is entirely about the IDE GUI (https://developer.android.com/ndk/guides) with no mention of the command line. I googled "how do I compile hello world with the android ndk" and got a page about java (https://www3.ntu.edu.sg/home/ehchua/programming/android/Android_NDK.html). So I dug up my notes and the page I'd bookmarked says "obsolete": https://developer.android.com/ndk/guides/standalone_toolchain But it links to: https://developer.android.com/ndk/guides/other_build_systems Which... is wrong? It says: $ $NDK/toolchains/llvm/prebuilt/$HOST_TAG/clang++ \ -target aarch64-linux-android21 foo.cpp $ ls toolchains/llvm/prebuilt/linux-x86_64/ aarch64-linux-android lib NOTICE AndroidVersion.txt lib64prebuilt_include arm-linux-androideabi libexec share binmanifest_6317467.xml sysroot i686-linux-android MODULE_LICENSE_BSD_LIKE test includeMODULE_LICENSE_MIT x86_64-linux-android I guess $HOST_TAG should be set to "linux-x86_64/bin" perhaps? Because there's no clang++ in the linux-x86_64/ directory, and using binaries out of the wrong directory is the rathole I went down before... Alright, let's go back to guessing whack-a-mole. (I REALLY hope I don't _have_ to specify --target on the command line like the web page says, and can just use the prefixed compiler names instead...) $ ln -s x86_64-linux-android29-clang ~/android/android-ndk-21b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-cc $ make root LINUX=~/linux/linux CROSS_COMPILE=~/android/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android- Yay, toybox built! The linux kernel did not: scripts/Kconfig.include:45: compiler '/home/landley/android/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-gcc' not found scripts/kconfig/Makefile:71: recipe for target 'allnoconfig' failed Dear Linux: llvm is not gcc. It's a cc. What is... Oh good grief what's happened to the kernel Makefile: ifneq ($(LLVM),) CC = clang ... else CC = $(CROSS_COMPILE)gcc ... PERL= perl PYTHON
Re: [Toybox] Would someone please explain what bash is doing here?
On 5/4/20 12:20 PM, Rob Landley wrote: > On 5/4/20 8:39 AM, Chet Ramey wrote: >> On 5/2/20 4:01 PM, Rob Landley wrote: >> >>> Why does the export flag on $_ toggle? >> >> It does three different things. It's initially exported if bash inherits it >> from the environment at startup; after that it does its thing. >> >> "_ At shell startup, set to the absolute pathname used to invoke >> the shell or shell script being executed as passed in the envi- >> ronment or argument list. Subsequently, expands to the last ar- >> gument to the previous simple command executed in the fore- >> ground, after expansion. Also set to the full pathname used to >> invoke each command executed and placed in the environment ex- >> ported to that command. When checking mail, this parameter >> holds the name of the mail file currently being checked." >> >> We picked that up from ksh. > > My question was why "declare -p _" was showing -x sometimes and not other > times, > but I guess that's just an implementation detail showing through? Yeah, pretty much. It should show as exported all the time, since it was imported from the initial environment, but the code that sets it to the last argument of the previous simple command makes sure it doesn't have the export attribute. >(Unlike other > magic variables, if you unset _ it doesn't stop being magic, it still gets > reset > every command. It predates dynamic variables by several years. > And if you "readonly _" bash gets REALLY chatty. :) That falls into the category of giving you enough rope to shoot yourself. > Still trying to work out what the "bash spec" would be, vs implementation > details... I'll be interested when you get that spec done. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/ ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
[Toybox] Shell error messages.
In toysh I'm using normal perror_msg() which does strerr(errno), ala: # walrus sh: walrus: No such file or directory # /usr sh: /usr: Permission denied # exit But bash is doing: $ walrus bash: walrus: command not found $ /usr bash: /usr: Is a directory On the one hand, this is libc's problem: "not found" is a MUCH better error message than "no such file or directory or symlink or dev node or fifo or named pipe or unix domain socket" and there IS an EISDIR that the kernel apparently isn't returning for exec of a directory...? Um, hello kernel? man 2 execve says it CAN return EISDIR... if ld.so is a directory: EISDIR An ELF interpreter was a directory. But if the file you RAN was a directory, it gives EPERM. Great. The problem with me trying to micromanage this and produce my own error messages is 2/3 of the world speaks something other than english. The libc messages are (potentially) translated where toybox is not. So I want to return the libc error messages where I can, and restrict the english error message vocabulary to about a dozen words when I can't. (Hence "bad" everything. Yes I'm aware the help text kinda undermines that. Part of my todo item to wire up gzip to display compressed help includes adding a way to substitute in different translated help text through that input path, although I'm not sure I want to merge it into toybox because that hole has no bottom. Still, if somebody ELSE wants to maintain that...) Anyway, thingy. Todo item. Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] Would someone please explain what bash is doing here?
On 5/4/20 8:39 AM, Chet Ramey wrote: > On 5/2/20 4:01 PM, Rob Landley wrote: > >> Why does the export flag on $_ toggle? > > It does three different things. It's initially exported if bash inherits it > from the environment at startup; after that it does its thing. > > "_ At shell startup, set to the absolute pathname used to invoke > the shell or shell script being executed as passed in the envi- > ronment or argument list. Subsequently, expands to the last ar- > gument to the previous simple command executed in the fore- > ground, after expansion. Also set to the full pathname used to > invoke each command executed and placed in the environment ex- > ported to that command. When checking mail, this parameter > holds the name of the mail file currently being checked." > > We picked that up from ksh. My question was why "declare -p _" was showing -x sometimes and not other times, but I guess that's just an implementation detail showing through? (Unlike other magic variables, if you unset _ it doesn't stop being magic, it still gets reset every command. And if you "readonly _" bash gets REALLY chatty. :) Still trying to work out what the "bash spec" would be, vs implementation details... Rob ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] Would someone please explain what bash is doing here?
On 5/2/20 4:01 PM, Rob Landley wrote: > Why does the export flag on $_ toggle? It does three different things. It's initially exported if bash inherits it from the environment at startup; after that it does its thing. "_ At shell startup, set to the absolute pathname used to invoke the shell or shell script being executed as passed in the envi- ronment or argument list. Subsequently, expands to the last ar- gument to the previous simple command executed in the fore- ground, after expansion. Also set to the full pathname used to invoke each command executed and placed in the environment ex- ported to that command. When checking mail, this parameter holds the name of the mail file currently being checked." We picked that up from ksh. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/ ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net