From patchwork Tue Apr 4 17:27:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 9662245 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 96C42602BA for ; Tue, 4 Apr 2017 17:27:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 853EC28338 for ; Tue, 4 Apr 2017 17:27:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7978E28491; Tue, 4 Apr 2017 17:27:48 +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=unavailable 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 0C70928338 for ; Tue, 4 Apr 2017 17:27:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754447AbdDDR1f (ORCPT ); Tue, 4 Apr 2017 13:27:35 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:35304 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754925AbdDDR1d (ORCPT ); Tue, 4 Apr 2017 13:27:33 -0400 Received: by mail-pg0-f51.google.com with SMTP id 81so158884543pgh.2 for ; Tue, 04 Apr 2017 10:27:33 -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:mime-version :content-transfer-encoding; bh=gxKUIAZdp1LObu0g5wyFnZ6qXZVNPD/VPakVnCGOaOA=; b=qsMWDqeSzRxFQxYl83DwkvJeoIasTxGHMVwM4VVjdZNbf6ENWkM/FMYFe4IHniW9Ee F1++XpHPxGbqSeipQy37KEJvUK4OmECIGzXneVDRN78iZG9n1niY6Kyli4u0mnYaPZfK tuKkDnzURCO1//0CMpN3B7/UZCybiZNXZt29C67ROU0X9v/mgtisM+03bQKYwcO7LqvR V1JAxl+L0aGnx9c3igKalvgsqn+IHLtX8Q+1ZGIZFenhcklStIHcMUE4UZhFQQBDi/HY yd8Qoh1qRodnvtQX846zKRawrtwnjrtwF88oi1T1hvQSrBTrjKIPkvTzd1KpVTp+sDE3 6+UQ== X-Gm-Message-State: AFeK/H2KI/RJbG0E3IudNONq0JZ2AYqFtkxhGBPQ6uZTtdfDVYydqI3E+3ZbTCZD6TiNWHK5 X-Received: by 10.84.254.4 with SMTP id b4mr30442474plm.179.1491326852957; Tue, 04 Apr 2017 10:27:32 -0700 (PDT) Received: from mka.mtv.corp.google.com ([172.22.64.162]) by smtp.gmail.com with ESMTPSA id p9sm32912618pfe.22.2017.04.04.10.27.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Apr 2017 10:27:32 -0700 (PDT) From: Matthias Kaehlcke To: Michal Marek , Emese Revfy , Kees Cook , Behan Webster , "Luis R . Rodriguez" , =?UTF-8?q?Vin=C3=ADcius=20Tinti?= , Kyeongmin Cho Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Grant Grundler , Michael Davidson , Greg Hackmann , Peter Foley , Matthias Kaehlcke Subject: [PATCH v3] kbuild: Add support to generate LLVM bitcode files Date: Tue, 4 Apr 2017 10:27:06 -0700 Message-Id: <20170404172706.171971-1-mka@chromium.org> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog MIME-Version: 1.0 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 From: Vinícius Tinti Add rules to kbuild in order to generate LLVM bitcode files with the .ll extension when using clang. # from c code CC=clang make kernel/pid.ll # from asm code CC=clang make arch/x86/kernel/preempt.ll From: Vinícius Tinti Signed-off-by: Vinícius Tinti Signed-off-by: Behan Webster Signed-off-by: Matthias Kaehlcke --- Resending, original v3 patch: https://patchwork.kernel.org/patch/4891071/ .gitignore | 1 + Makefile | 6 ++++++ scripts/Makefile.build | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/.gitignore b/.gitignore index c2ed4ecb0acd..0c39aa20b6ba 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ *.lzo *.patch *.gcno +*.ll modules.builtin Module.symvers *.dwo diff --git a/Makefile b/Makefile index e11989d36c87..d998ce363335 100644 --- a/Makefile +++ b/Makefile @@ -1361,6 +1361,8 @@ help: @echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)' @echo ' dir/ - Build all files in dir and below' @echo ' dir/file.[ois] - Build specified target only' + @echo ' dir/file.ll - Build the LLVM bitcode file' + @echo ' (requires compiler support for LLVM bitcode generation)' @echo ' dir/file.lst - Build specified mixed source/assembly target only' @echo ' (requires a recent binutils and recent build (System.map))' @echo ' dir/file.ko - Build module including final link' @@ -1648,6 +1650,10 @@ endif $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.symtypes: %.c prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) +%.ll: %.c prepare scripts FORCE + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) +%.ll: %.S prepare scripts FORCE + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) # Modules /: prepare scripts FORCE diff --git a/scripts/Makefile.build b/scripts/Makefile.build index d883116ebaa4..e5a28da2e6fa 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -177,6 +177,20 @@ cmd_cc_symtypes_c = \ $(obj)/%.symtypes : $(src)/%.c FORCE $(call cmd,cc_symtypes_c) +# LLVM bitcode +# Generate .ll files from .s and .c +quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@ + cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $< + +$(obj)/%.ll: $(src)/%.c FORCE + $(call if_changed_dep,cc_ll_c) + +quiet_cmd_as_ll_S = CPP $(quiet_modtag) $@ + cmd_as_ll_S = $(CPP) $(a_flags) -o $@ $< + +$(obj)/%.ll: $(src)/%.S FORCE + $(call if_changed_dep,as_ll_S) + # C (.c) files # The C file is compiled and updated dependency information is generated. # (See cmd_cc_o_c + relevant part of rule_cc_o_c)