镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Make clang integrated-as optional in Linux kernel #577

Closed

Description

@tpimh

Right now -no-integrated-as is passed to clang unconditionally during kernel compilation. I would like to make it optional and add a Kconfig switch to toggle it. I will try to work on it in my spare time.

Activity

  1. added
    enhancementNew feature or request
    [BUG] linuxA bug that should be fixed in the mainline kernel.
    [TOOL] integrated-asThe issue is relevant to LLVM integrated assembler
    on Jun 26, 2019
  2. self-assigned this
    on Jun 26, 2019
  3. changed the title [-]Make clang integrated as optional in Linux kernel[/-] [+]Make clang integrated-as optional in Linux kernel[/+] on Jun 26, 2019
  4. tpimh commented on Jun 26, 2019

    @tpimh
    Author

    Initial version of what it should look like

    diff --git a/Makefile b/Makefile
    index 7a7c17eb0..a487f1f5b 100644
    --- a/Makefile
    +++ b/Makefile
    @@ -527,7 +527,11 @@ endif
     ifneq ($(GCC_TOOLCHAIN),)
     CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
     endif
    +ifdef CONFIG_CLANG_USE_INTEGRATED_AS
    +CLANG_FLAGS    += -integrated-as
    +else
     CLANG_FLAGS    += -no-integrated-as
    +endif
     KBUILD_CFLAGS  += $(CLANG_FLAGS)
     KBUILD_AFLAGS  += $(CLANG_FLAGS)
     export CLANG_FLAGS
    diff --git a/init/Kconfig b/init/Kconfig
    index 0e2344389..fcab57c66 100644
    --- a/init/Kconfig
    +++ b/init/Kconfig
    @@ -24,6 +24,11 @@ config CLANG_VERSION
            int
            default $(shell,$(srctree)/scripts/clang-version.sh $(CC))
    
    +config CLANG_USE_INTEGRATED_AS
    +       bool "Use Clang integrated assembler"
    +       depends on CC_IS_CLANG
    +       default CC_IS_CLANG && CLANG_VERSION > 90000
    +
     config CC_HAS_ASM_GOTO
            def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
    
    
  5. dileks commented on Jun 26, 2019

    @dileks
    Collaborator

    [1] says:

    Assembler

    Clang can either use LLVM’s integrated assembler or an external system-specific tool (for instance, > the GNU Assembler on GNU OSes) to produce machine code from assembly. By default, Clang uses > LLVM’s integrated assembler on all targets where it is supported. If you wish to use the system
    assembler instead, use the -fno-integrated-as option."

    [2] says:

    -fintegrated-as, -fno-integrated-as, -integrated-as
    Enable the integrated assembler

    bool "Use LLVM’s integrated assembler with Clang" ?

    [1] https://clang.llvm.org/docs/Toolchain.html#assembler
    [2] https://clang.llvm.org/docs/ClangCommandLineReference.html#target-dependent-compilation-options

  6. nickdesaulniers commented on Jun 26, 2019

    @nickdesaulniers
    Member

    A config option would make allyesconfig builds start failing. Maybe a custom command like variable to Make like AS and CC and friends currently are?

    Maybe -no-integrated-as should not be added IF AS was set at the command line? I think that should be the way to go.

  7. nathanchance commented on Jun 26, 2019

    @nathanchance
    Member
    diff --git a/Makefile b/Makefile
    index aa233492e04a..929b2cca671f 100644
    --- a/Makefile
    +++ b/Makefile
    @@ -527,7 +527,9 @@ endif
     ifneq ($(GCC_TOOLCHAIN),)
     CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
     endif
    +ifeq ($(findstring clang,$(AS)),)
     CLANG_FLAGS    += -no-integrated-as
    +endif
     CLANG_FLAGS    += -Werror=unknown-warning-option
     KBUILD_CFLAGS  += $(CLANG_FLAGS)
     KBUILD_AFLAGS  += $(CLANG_FLAGS)

    or

    diff --git a/Makefile b/Makefile
    index aa233492e04a..4954f1e911be 100644
    --- a/Makefile
    +++ b/Makefile
    @@ -527,7 +527,9 @@ endif
     ifneq ($(GCC_TOOLCHAIN),)
     CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
     endif
    +ifeq ($(shell $(AS) --version 2>&1 | head -n 1 | grep clang),)
     CLANG_FLAGS    += -no-integrated-as
    +endif
     CLANG_FLAGS    += -Werror=unknown-warning-option
     KBUILD_CFLAGS  += $(CLANG_FLAGS)
     KBUILD_AFLAGS  += $(CLANG_FLAGS)

    works for all four of these combos:

    $ make AS=as CC=clang
    $ make AS=clang CC=clang
    $ make AS=/usr/bin/clang CC=clang
    $ make AS=/usr/bin/as CC=clang
    

    I would think the latter is preferred but I have no strong opinion. This type of change is easily upstreamable I think, I can send it along.

  8. nickdesaulniers commented on Jun 26, 2019

    @nickdesaulniers
    Member

    I would think the latter is preferred but I have no strong opinion.

    The first doesn't invoke a subshell. ;)

    What about if I use AS=clang-8 or AS=clang-9?

  9. nathanchance commented on Jun 26, 2019

    @nathanchance
    Member

    The first doesn't invoke a subshell. ;)

    Fair point :)

    What about if I use AS=clang-8 or AS=clang-9?

    Also works because findstring just checks if clang is somewhere in $(AS) not that $(AS) is clang.

  10. tpimh commented on Jun 27, 2019

    @tpimh
    Author

    Second option looks better to me because it will also work with a clang-based comiler with a different executable name (e.g. ELLCC).

  11. dileks commented on Jun 27, 2019

    @dileks
    Collaborator

    Hmmm, interesting for me the possibility to set AS=clang.

    When do people use llvm-as?
    Can we use it for CBL?

    2nd options looks more familiar to me (similiar setting like for LD etc.)

  12. tpimh commented on Jun 27, 2019

    @tpimh
    Author

    llvm-as is used for building LLVM assembly. Platform specific assembly can be built with clang (it would either use LLVM's integrated assembler or call external as depending on whether or not -no-integrated-as was set).

  13. nathanchance commented on Jun 27, 2019

    @nathanchance
    Member

    @tpimh I agree, I realized that last night and never commented lol.

    Tentative patch, let me know if you all want the patch improved in any way.

    From 50e90e9d6b9f2ae26656e7eb532ae545567c386a Mon Sep 17 00:00:00 2001
    From: Nathan Chancellor <natechancellor@gmail.com>
    Date: Thu, 27 Jun 2019 08:58:50 -0700
    Subject: [PATCH] kbuild: Add ability to test Clang's integrated assembler
    
    There are some people interested in experimenting with Clang's
    integrated assembler. To make it easy to do so without source
    modification, allow the user to specify AS=clang as part of the
    make command to avoid adding '-no-integrated-as' to the {A,C}FLAGS.
    
    Link: https://github.com/ClangBuiltLinux/linux/issues/577
    Suggested-by: Dmitry Golovin <dima@golovin.in>
    Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
    ---
     Makefile | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/Makefile b/Makefile
    index aa233492e04a..4954f1e911be 100644
    --- a/Makefile
    +++ b/Makefile
    @@ -527,7 +527,9 @@ endif
     ifneq ($(GCC_TOOLCHAIN),)
     CLANG_FLAGS	+= --gcc-toolchain=$(GCC_TOOLCHAIN)
     endif
    +ifeq ($(shell $(AS) --version 2>&1 | head -n 1 | grep clang),)
     CLANG_FLAGS	+= -no-integrated-as
    +endif
     CLANG_FLAGS	+= -Werror=unknown-warning-option
     KBUILD_CFLAGS	+= $(CLANG_FLAGS)
     KBUILD_AFLAGS	+= $(CLANG_FLAGS)
    -- 
    2.22.0
  14. 221 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[BUG] linuxA bug that should be fixed in the mainline kernel.[FIXED][LINUX] 5.3This bug was fixed in Linux 5.3[TOOL] integrated-asThe issue is relevant to LLVM integrated assemblerenhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions