From patchwork Mon Apr 3 21:25:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 9660633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 44EBF60353 for ; Mon, 3 Apr 2017 21:26:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 365952846A for ; Mon, 3 Apr 2017 21:26:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29359284C2; Mon, 3 Apr 2017 21:26:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44E372846A for ; Mon, 3 Apr 2017 21:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752447AbdDCV0M (ORCPT ); Mon, 3 Apr 2017 17:26:12 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:36760 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752438AbdDCV0L (ORCPT ); Mon, 3 Apr 2017 17:26:11 -0400 Received: by mail-pg0-f42.google.com with SMTP id g2so130528680pge.3 for ; Mon, 03 Apr 2017 14:26:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+D8JtWMa/nent1Xj+RZmJSg2SmvYKZGtttuMjBDpLPE=; b=V+ODb90Q89q5tK3JfKzYGVXIDalUXGNeEeXk8QapXun1JV4jSNvYQPOle3x63LQAAj 04TDjm1SzmLChtBSg21gaU2pKyeJi6t7hj2m+7/bI/CGWUcA4Q7mWlVMKO5bmVIz9Esr 4170pUA9Ah6JquCW/uEwZ6j3qWyQIPiUqBdjJrujHQ0llFDjZ3ymilbzybQfN+eVhB/T W9ukNp0ALXApAowo7OOReG6o9+SIJeP2ePH4u3CSHOV+q3v3UTrcV1Aqv+iXIEMY/zAW +b/w6SkYug7w7JOWPf0UHnkvMAbHVW4ooi1bOCbFl4kDnEEdnONUWbtlDSXIWgjL4Ann Cr/A== X-Gm-Message-State: AFeK/H21m/k8McK6aGQgArdRDq7TCliQ547tBoTlD95XmeOxOPS9Ln8vtVNNL9dYk4xSZ2rt X-Received: by 10.99.109.67 with SMTP id i64mr19728629pgc.56.1491254770968; Mon, 03 Apr 2017 14:26:10 -0700 (PDT) Received: from mka.mtv.corp.google.com ([172.22.64.162]) by smtp.gmail.com with ESMTPSA id e70sm27567093pfh.84.2017.04.03.14.26.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Apr 2017 14:26:10 -0700 (PDT) From: Matthias Kaehlcke To: Michal Marek Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Grant Grundler , Michael Davidson , Greg Hackmann , Behan Webster , Peter Foley , Matthias Kaehlcke Subject: [RFC PATCH] kbuild: Fix asm-offset generation to work with clang Date: Mon, 3 Apr 2017 14:25:37 -0700 Message-Id: <20170403212537.124217-1-mka@chromium.org> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When using clang with -no-integerated-as clang will use the gnu assembler instead of the integrated assembler. However clang will still perform asm error checking before sending the inline assembly language to gas. The generation of asm-offsets from within C code is dependent on gcc's blind passing of whatever is in asm() through to gas. Arbirary text is passed through which is then modified by a sed script into the appropriate .h and .S code. Since the arbitrary text is not valid assembly language, clang fails. This can be fixed by making the arbitrary text into an ASM comment and then updating the sed scripts accordingly to work as expected. This solution works for both gcc and clang. Based-on-patch-from: Behan Webster Signed-off-by: Matthias Kaehlcke --- Dependencies all architectures kbuild: Consolidate header generation from ASM offset information https://patchwork.kernel.org/patch/9660459/ um um: Include kbuild.h instead of duplicating its macros https://patchwork.kernel.org/patch/9660503/ frv frv: Use OFFSET macro in DEF_*REG() https://patchwork.kernel.org/patch/9660473/ The change has been build tested on a wide range of architectures. The if cascade in kbuild.h and the comment symbol list in Makefile.asm-offsets won't win a beauty price. Alternatively the comment symbol could be specified in arch/Kconfig. Personally I don't have a strong preference on this point. include/linux/kbuild.h | 34 ++++++++++++++++++++++++++++--- scripts/Makefile.asm-offsets | 48 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/include/linux/kbuild.h b/include/linux/kbuild.h index 22a72198c14b..632e33d3b70c 100644 --- a/include/linux/kbuild.h +++ b/include/linux/kbuild.h @@ -1,15 +1,43 @@ #ifndef __LINUX_KBUILD_H #define __LINUX_KBUILD_H +#if defined(CONFIG_ALPHA) || defined(CONFIG_AVR32) || \ + defined(CONFIG_MICROBLAZE) || defined(CONFIG_MIPS) || \ + defined(CONFIG_MN10300) || defined(CONFIG_PPC) || \ + defined(CONFIG_S390) || defined(CONFIG_SCORE) || \ + defined(CONFIG_UML_X86) || defined(CONFIG_X86) || \ + defined(CONFIG_XTENSA) +#define ASM_COMMENT_SYM "#" +#elif defined(CONFIG_ARM) || defined(CONFIG_ARM64) +#define ASM_COMMENT_SYM "@" +#elif defined(CONFIG_ARC) || defined(CONFIG_C6X) || \ + defined(CONFIG_CRIS) || defined(CONFIG_FRV) || \ + defined(CONFIG_H8300) || defined(CONFIG_M32R) || \ + defined(CONFIG_PARISC) +#define ASM_COMMENT_SYM ";" +#elif defined(CONFIG_BLACKFIN) || defined(CONFIG_HEXAGON) || \ + defined(CONFIG_IA64) || defined(CONFIG_NIOS2) || \ + defined(CONFIG_OPENRISC) +#define ASM_COMMENT_SYM "//" +#elif defined(CONFIG_METAG) || defined(CONFIG_SUPERH) || \ + defined(CONFIG_SPARC) || defined(CONFIG_TILE) || \ + defined(CONFIG_UNICORE32) +#define ASM_COMMENT_SYM "!" +#elif defined(CONFIG_M68K) +#define ASM_COMMENT_SYM "|" +#else +#error Symbol for ASM inline comments is not defined for ARCH +#endif + #define DEFINE(sym, val) \ - asm volatile("\n->" #sym " %0 " #val : : "i" (val)) + asm volatile("\n" ASM_COMMENT_SYM "->" #sym " %0 " #val : : "i" (val)) -#define BLANK() asm volatile("\n->" : : ) +#define BLANK() asm volatile("\n" ASM_COMMENT_SYM "->" : : ) #define OFFSET(sym, str, mem) \ DEFINE(sym, offsetof(struct str, mem)) #define COMMENT(x) \ - asm volatile("\n->#" x) + asm volatile("\n" ASM_COMMENT_SYM "->#" x) #endif diff --git a/scripts/Makefile.asm-offsets b/scripts/Makefile.asm-offsets index 4ba80ba29b82..7f8d3cbc5901 100644 --- a/scripts/Makefile.asm-offsets +++ b/scripts/Makefile.asm-offsets @@ -1,9 +1,49 @@ +# Symbols for ASM inline comments for all architectures +asm_comment_sym_arch_alpha = \# +asm_comment_sym_arch_arc = \; +asm_comment_sym_arch_arm = @ +asm_comment_sym_arch_arm64 = @ +asm_comment_sym_arch_avr32 = \# +asm_comment_sym_arch_blackfin = // +asm_comment_sym_arch_c6x = \; +asm_comment_sym_arch_cris = \; +asm_comment_sym_arch_frv = \; +asm_comment_sym_arch_h8300 = \; +asm_comment_sym_arch_hexagon = // +asm_comment_sym_arch_ia64 = // +asm_comment_sym_arch_m32r = \; +asm_comment_sym_arch_m68k = | +asm_comment_sym_arch_metag = ! +asm_comment_sym_arch_microblaze = \# +asm_comment_sym_arch_mips = \# +asm_comment_sym_arch_mn10300 = \# +asm_comment_sym_arch_nios2 = // +asm_comment_sym_arch_openrisc = // +asm_comment_sym_arch_parisc = \; +asm_comment_sym_arch_powerpc = \# +asm_comment_sym_arch_s390 = \# +asm_comment_sym_arch_score = \# +asm_comment_sym_arch_sh = ! +asm_comment_sym_arch_sparc = ! +asm_comment_sym_arch_tile = ! +# Note: assumes uml_x86 +asm_comment_sym_arch_um = \# +asm_comment_sym_arch_unicore32 = ! +asm_comment_sym_arch_x86 = \# +asm_comment_sym_arch_xtensa = \# + +ASM_COMMENT_SYM = $(asm_comment_sym_arch_$(SRCARCH)) + +ifeq ($(ASM_COMMENT_SYM),) +$(error Symbol for ASM inline comments is not defined for ARCH=$(SRCARCH)) +endif + # Default sed regexp - multiline due to syntax constraints define sed-asm-offsets-to-c - "/^->/{s:->#\(.*\):/* \1 */:; \ - s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \ - s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ - s:->::; p;}" + "\:^$(ASM_COMMENT_SYM)->:{s:$(ASM_COMMENT_SYM)->#\(.*\):/* \1 */:; \ + s:^$(ASM_COMMENT_SYM)->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \ + s:^$(ASM_COMMENT_SYM)->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ + s:$(ASM_COMMENT_SYM)->::; p;}" endef define gen_header_from_asm_offsets