03 Sep, 2021

1 commit

  • It has been brought up a few times in various code reviews that clang
    3.5 introduced -f{,no-}integrated-as as the preferred way to enable and
    disable the integrated assembler, mentioning that -{no-,}integrated-as
    are now considered legacy flags.

    Switch the kernel over to using those variants in case there is ever a
    time where clang decides to remove the non-'f' variants of the flag.

    Also, fix a typo in a comment ("intergrated" -> "integrated").

    Link: https://releases.llvm.org/3.5.0/tools/clang/docs/ReleaseNotes.html#new-compiler-flags
    Reviewed-by: Nick Desaulniers
    Signed-off-by: Nathan Chancellor
    Signed-off-by: Masahiro Yamada

    Nathan Chancellor
     

25 Apr, 2021

1 commit

  • Documentation/process/changes.rst defines the minimum assembler version
    (binutils version), but we have never checked it in the build time.

    Kbuild never invokes 'as' directly because all assembly files in the
    kernel tree are *.S, hence must be preprocessed. I do not expect
    raw assembly source files (*.s) would be added to the kernel tree.

    Therefore, we always use $(CC) as the assembler driver, and commit
    aa824e0c962b ("kbuild: remove AS variable") removed 'AS'. However,
    we are still interested in the version of the assembler acting behind.

    As usual, the --version option prints the version string.

    $ as --version | head -n 1
    GNU assembler (GNU Binutils for Ubuntu) 2.35.1

    But, we do not have $(AS). So, we can add the -Wa prefix so that
    $(CC) passes --version down to the backing assembler.

    $ gcc -Wa,--version | head -n 1
    gcc: fatal error: no input files
    compilation terminated.

    OK, we need to input something to satisfy gcc.

    $ gcc -Wa,--version -c -x assembler /dev/null -o /dev/null | head -n 1
    GNU assembler (GNU Binutils for Ubuntu) 2.35.1

    The combination of Clang and GNU assembler works in the same way:

    $ clang -no-integrated-as -Wa,--version -c -x assembler /dev/null -o /dev/null | head -n 1
    GNU assembler (GNU Binutils for Ubuntu) 2.35.1

    Clang with the integrated assembler fails like this:

    $ clang -integrated-as -Wa,--version -c -x assembler /dev/null -o /dev/null | head -n 1
    clang: error: unsupported argument '--version' to option 'Wa,'

    For the last case, checking the error message is fragile. If the
    proposal for -Wa,--version support [1] is accepted, this may not be
    even an error in the future.

    One easy way is to check if -integrated-as is present in the passed
    arguments. We did not pass -integrated-as to CLANG_FLAGS before, but
    we can make it explicit.

    Nathan pointed out -integrated-as is the default for all of the
    architectures/targets that the kernel cares about, but it goes
    along with "explicit is better than implicit" policy. [2]

    With all this in my mind, I implemented scripts/as-version.sh to
    check the assembler version in Kconfig time.

    $ scripts/as-version.sh gcc
    GNU 23501
    $ scripts/as-version.sh clang -no-integrated-as
    GNU 23501
    $ scripts/as-version.sh clang -integrated-as
    LLVM 0

    [1]: https://github.com/ClangBuiltLinux/linux/issues/1320
    [2]: https://lore.kernel.org/linux-kbuild/20210307044253.v3h47ucq6ng25iay@archlinux-ax161/

    Signed-off-by: Masahiro Yamada
    Reviewed-by: Nathan Chancellor

    Masahiro Yamada