[Toybox] llvm regression test.

Rob Landley rob at landley.net
Mon May 4 15:03:29 PDT 2020


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     lib64                    prebuilt_include
arm-linux-androideabi  libexec                  share
bin                    manifest_6317467.xml     sysroot
i686-linux-android     MODULE_LICENSE_BSD_LIKE  test
include                MODULE_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          = python
PYTHON3         = python3
...
ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
ifneq ($(CROSS_COMPILE),)
CLANG_FLAGS     += --target=$(notdir $(CROSS_COMPILE:%-=%))
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
CLANG_FLAGS     += --prefix=$(GCC_TOOLCHAIN_DIR)
GCC_TOOLCHAIN   := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_FLAGS     += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
ifneq ($(LLVM_IAS),1)
CLANG_FLAGS     += -no-integrated-as
endif
CLANG_FLAGS     += -Werror=unknown-warning-option
KBUILD_CFLAGS   += $(CLANG_FLAGS)
KBUILD_AFLAGS   += $(CLANG_FLAGS)
export CLANG_FLAGS
endif

The vanilla kernel makes no attempt whatsoever to work with generic tools
anymore, does it? Even ones copying gcc's API. I need a flamethrower... But
that's a SEPARATE problem, so let's see...

$ 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...

Rob


More information about the Toybox mailing list