Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp215619imm; Tue, 22 May 2018 17:20:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZojhvQW6+YaZA8aV/E35YBtKyHUcXd5GEyOnt7j3BqQjTwPNKv+IGl4aSGz6H64Nu+2+IPY X-Received: by 2002:a62:1152:: with SMTP id z79-v6mr575849pfi.135.1527034813700; Tue, 22 May 2018 17:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527034813; cv=none; d=google.com; s=arc-20160816; b=oKnhBrAcZX+Qfciu6AeW4YzwtjrzlQ2u7wHbzgeanZe1REZkSoI4TQ6wyr3Wvir9cF /SidP19qlj4PLkTSMkvUtjfIvfx4BLnnoEYZBi4XUIoBGAMqOvYZQ0/c34qg9kt7+LUN bnT2Fk66V1ubivW3V4RuoZ4hO1nw42/M57Mrh7ZTVAUzobwfZIgZsTpFAYn54MCFhUN9 nyMCYeU3pEhN/uhyD6ezeDQ5+/hzUmJCTepsMGDOhe8lt4hRbg0SxEbtZY0gt/Yn/33y JOcoYSauWZjiioIim4vl3p60y/n0lM5tjnbOzbTI5XbciAQxNQbvgXGfH5Y3fmoXQLia xA6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=43bEIrr3LkVBCP3gecETmDysn4uZEmPZf86ewWH6S0g=; b=l52/60AWP/XEg0/pLUiPzM9W9PGUC42YZ52T+fxHHCPl/bJi1HhI3epJ/R2PhlL69L aHnEvDWjsuWxeA6dCz48dWh1qBy739Uf8doQIGmqp8VUUJq4XRrgkEH42+ZK0V9qg690 yWFeqbphRKYxXmZO+9NqxeHnJtUmY1H2cxYzHN9ePOeByVCTkfq3FEmfQyXrd6KK68rp FLjAtLGYqJdO1lrohnxg1FbefoCLFfV5WAmb2AbPQ64lgXLOJlWdoLx5/M/XTaON5/kK oczLAoWy5Zt1XrPlb8JKz86Bpgg0nWyA7dmtvZmebLGBuwbCs0Y00kGg4cvyeh/59VkJ MMmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11-v6si17774530plo.352.2018.05.22.17.19.59; Tue, 22 May 2018 17:20:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753620AbeEWATw (ORCPT + 99 others); Tue, 22 May 2018 20:19:52 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:38923 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753618AbeEWATs (ORCPT ); Tue, 22 May 2018 20:19:48 -0400 Received: by mail-pl0-f67.google.com with SMTP id c19-v6so11870830pls.6 for ; Tue, 22 May 2018 17:19:48 -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:in-reply-to :references; bh=43bEIrr3LkVBCP3gecETmDysn4uZEmPZf86ewWH6S0g=; b=hhTbRv6YCepoy1vjW4qayeF0UVUNlqjJ7SxA5Rjc5NqbErmJF/pA69aJvH2XIPYlkn Z0CSJPr/9bKnPQBYL9dkuNsiKDsFBPGpCg1HUJPPGn/wH/qYiuxmST0Glw3j2Pp0tS89 dH5HGMMqAQWs7f6OySKYq8cFUIr1MpG5i/DN0RcOxvXjNGs9slsqMe9dNdAXl9qpPLxR Ak+3UFQIAhBUVa/PT9yjzZ9w+ZoO57NLdzXjbNJN4uLYIVJBHKsLU2bv/6sCRsueHhrV zmCpakEl7EmKY12QauKLdCEqcIEGWTlH7QQNzXLJQkv5tzlgq/EXZ+j2Hj1fbjsoNQYv yajA== X-Gm-Message-State: ALKqPwcwry2GZzzn2yO/efUgLnFIZVWZkJ/JHySGwEFzHmDtkBtqNVy7 5D3eLjmxaLpLydl32hk8EbWNng== X-Received: by 2002:a17:902:aa98:: with SMTP id d24-v6mr601375plr.185.1527034788062; Tue, 22 May 2018 17:19:48 -0700 (PDT) Received: from localhost.net ([2601:602:9802:a8dc::4dc5]) by smtp.gmail.com with ESMTPSA id 206-v6sm29303145pfy.51.2018.05.22.17.19.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 17:19:47 -0700 (PDT) From: Laura Abbott To: Andy Lutomirski , mjw@fedoraproject.org, "H . J . Lu" , Masahiro Yamada Cc: Laura Abbott , Linus Torvalds , X86 ML , linux-kernel@vger.kernel.org, Nick Clifton , Cary Coutant , linux-kbuild@vger.kernel.org Subject: [PATCHv3 1/2] kbuild: Introduce build-salt linker script Date: Tue, 22 May 2018 17:19:38 -0700 Message-Id: <20180523001939.9431-2-labbott@redhat.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523001939.9431-1-labbott@redhat.com> References: <20180523001939.9431-1-labbott@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The build id generated from --build-id can be generated in several different ways, with the default being the sha1 on the output of the linked file. For distributions, it can be useful to make sure this ID is unique, even if the actual file contents don't change. The easiest way to do this is to insert a comment section with some data. Introduce a generated linker script to link against the kernel/modules. This puts the kernel version in a .comment section which will generate a unique build id if the kernel version changes. Signed-off-by: Laura Abbott --- v3: Generate the linker script directly instead of just a header. --- Makefile | 4 +++- scripts/.gitignore | 1 + scripts/Makefile | 9 ++++++++- scripts/gensalt | 22 ++++++++++++++++++++++ scripts/link-vmlinux.sh | 3 ++- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100755 scripts/gensalt diff --git a/Makefile b/Makefile index ec6f45928fd4..87fe8992afd8 100644 --- a/Makefile +++ b/Makefile @@ -428,7 +428,8 @@ KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE -KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds +KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds \ + -T $(obj)/scripts/build-salt.lds LDFLAGS := GCC_PLUGINS_CFLAGS := @@ -997,6 +998,7 @@ export KBUILD_VMLINUX_INIT := $(head-y) $(init-y) export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y2) $(drivers-y) $(net-y) $(virt-y) export KBUILD_VMLINUX_LIBS := $(libs-y1) export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds +export EXTRA_LDS := scripts/build-salt.lds export LDFLAGS_vmlinux # used by scripts/package/Makefile export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Documentation include samples scripts tools) diff --git a/scripts/.gitignore b/scripts/.gitignore index 0442c06eefcb..1c840ef4f0c8 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -13,3 +13,4 @@ asn1_compiler extract-cert sign-file insert-sys-cert +build-salt.lds diff --git a/scripts/Makefile b/scripts/Makefile index 25ab143cbe14..019b0749ff46 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -25,7 +25,14 @@ HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include HOSTLOADLIBES_sign-file = -lcrypto HOSTLOADLIBES_extract-cert = -lcrypto -always := $(hostprogs-y) $(hostprogs-m) +always := $(hostprogs-y) $(hostprogs-m) build-salt.lds + +define filechk_build-salt.lds + ($(CONFIG_SHELL) $(srctree)/scripts/gensalt $(KERNELRELEASE)) +endef + +$(obj)/build-salt.lds: $(src)/gensalt FORCE + $(call filechk,build-salt.lds) # The following hostprogs-y programs are only build on demand hostprogs-y += unifdef diff --git a/scripts/gensalt b/scripts/gensalt new file mode 100755 index 000000000000..846c0407cc43 --- /dev/null +++ b/scripts/gensalt @@ -0,0 +1,22 @@ +#!/bin/sh + +if [[ $1 = "" ]]; then + echo "#define BUILD_ID_SALT" + exit 0 +fi + +BUILD_ID_SALT=$1 + +echo "SECTIONS {" +echo ".comment (INFO) :" +echo " {" + +_TAG=`echo $BUILD_ID_SALT | sed -e 's/\(.\)/\1 /g'` +for c in $_TAG; do + _HEX=`echo -n $c | od -A n -t x1 | tr -d ' ' ` + echo "BYTE(0x$_HEX);" +done +echo "BYTE(0x00);" + +echo " } " +echo " } " diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 9045823c7be7..588946dde658 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -84,6 +84,7 @@ modpost_link() vmlinux_link() { local lds="${objtree}/${KBUILD_LDS}" + local extra_lds="${objtree}/${EXTRA_LDS}" local objects if [ "${SRCARCH}" != "um" ]; then @@ -96,7 +97,7 @@ vmlinux_link() ${1}" ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ - -T ${lds} ${objects} + -T ${lds} -T ${extra_lds} ${objects} else objects="-Wl,--whole-archive \ built-in.a \ -- 2.17.0