Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp272649rdb; Thu, 22 Feb 2024 03:21:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXlZH/GneJEOsJJSlPLYeP0VeOPOTarGZKkEIWr7vdRWHBHTTLRWh5nzQWZTX97Ss0MlbqiyX1tvVzjx+YVlwYNZF6Qc58lzdK9AIjzwA== X-Google-Smtp-Source: AGHT+IF7LpGKkocwfn6aC/L72NC6NYOcSnPH7uFLk4OM0oeiGocSp9fGgpaUwl1H9YJFg6CHOymW X-Received: by 2002:a05:6214:4114:b0:68f:4519:78ec with SMTP id kc20-20020a056214411400b0068f451978ecmr18485509qvb.60.1708600879061; Thu, 22 Feb 2024 03:21:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708600879; cv=pass; d=google.com; s=arc-20160816; b=ezJzxl2Ppq5Qe6gx6klo/fSC378+JdG67WVdok82Ab+Dcil/vvOjC+zmrze8vFO+Qj VazicGYXm6kAJyxYi34pPJeZtW6Y9ANvs44VNqtun+PFZSvAyR5vRR39oBF0UrNvJlnd ZDHh9pK4r6pQwno60k/kB/E0lY26zQkRQ23vTgbYuAN7BEfc2Y7/FYx5Xt+LRQBmQSWj hrDaFdW+E5k5s6s3+skQM27WzjvxkEeNngMFvGDUzCkZsXgal59lYVXUgGIt3UItOL1v 5klA9N93+kWF1SpFRSQDlq8m+ZF0Q3ETNHgcs4fyZlhz5UFfRPODwKQIrmfDIBIHY0lN S1Eg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=1SjcXiN0HSEY14VbtkYXT9a2V6mhrgFrbcQEYTI562s=; fh=4rrBHvvx7FQP+Xa5keulRjxPXEetAwZOnWW0lX6P2ew=; b=hdR35Pko3yAbPiU8W093tfigJbePgCyGDTHFt4yfxotTJK+MTrIxzlaWXkOUhu4qgv JCgCAv5m2Ha+oepFD1MViqEFrEglpg2YHUPhO3GLuS1IPOgV9GiIEgo+VQ1qXJcUHQz0 3LtJ+1f8sCihluf9WIJSZPJiUM3I70DyexefOjIl16v533VVuWsiwQHMKvRnT9nLXU/G sjBW+sL0k1VaiP5J9o84N5IrXv7QI7xwHFiNjiyRPrvyDzqapGMtPgkHthdFTN4/I+Ni /CbP4zMEqZZ3+L9msAq9ATLFxphYw5axqmzcWMC738NPGq2pYq0+S39Nu2rtJySITNZQ E/kA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2FWqWvep; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-76398-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76398-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ke8-20020a056214300800b0068fbf863ab0si605686qvb.23.2024.02.22.03.21.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:21:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76398-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2FWqWvep; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-76398-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76398-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BD21F1C22B27 for ; Thu, 22 Feb 2024 11:21:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 432C240BEE; Thu, 22 Feb 2024 11:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2FWqWvep" Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BA7A3770E for ; Thu, 22 Feb 2024 11:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708600871; cv=none; b=mfD/NeivjoN6X0/5WwhTjb5V96C9ovcz4E3w6avpXf1fwiMAlwUGBwQ0u478//PnzuZgZ7gJcejJoqY3bku1drzlpUZOsay36nwXBf6eaF84Z1QJnYzVTOBcg37e2N4yRp9pvnEasZIYOA9ur/dVxHuwTtnN96d3tpUOmJ4bYmQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708600871; c=relaxed/simple; bh=9Pqfn0qC+Yj0+qJNWDK84EdmrphKvk4v2jyMlAkwfrs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=CW9V1o7xmbXvXn1g+/xcRbaPR283pr5TZY02zgUEZPuEasYi9lPIdMzMDyDdoaw8UfqYi71GSn2W9E6iqUDYlmOZrdeLtLInzuEVY0agdfZx2T7WsaCb5ByuQp/1vjzqPSpehl9m0Q8sblwTsN8BnN9KIZHaVRYFBlB9s0X619c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2FWqWvep; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-564e4477b7cso8526a12.1 for ; Thu, 22 Feb 2024 03:21:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708600868; x=1709205668; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1SjcXiN0HSEY14VbtkYXT9a2V6mhrgFrbcQEYTI562s=; b=2FWqWvepbEwV3t9/82tcf+XsbCGiEcCpFv900lXJ4xI/+rMYHiELH1cdVOoieUx5cn pH2Z2sAyPWH5+KYQRvEmdmKo3CmvqObtbWdeTpH33pnrI8whJZNmmh3yeTJqB+G9kt09 a6QuRNORuy/PPsEoUMQ9NVgHETRezA5vW13BhfMO0o4I0qRNMBD52G6NsWY1rNO+Ke3g kA/6b1KWzqajMNqYjkqcHM4cle/0cvVP8C4w0ruT5QnNOHw4t94YFpPNqGdYKF635YEK P/NhXeG8fEgFEWf/MaAf1oVajhyNwuNCXzQLQ+8FhT2T+Gse+25WjMebdjCsRK6ZsofH jAXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708600868; x=1709205668; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1SjcXiN0HSEY14VbtkYXT9a2V6mhrgFrbcQEYTI562s=; b=P+YZsWMLAticHA0NP1jOE2iBLZc0IIUyNan9p4jxamAgF6skLtzEcVKgyPiKnjFz9P WWORJ37UKy9vXXUxdVYBfeUcGW5gM8GwsPGvzUjdwFqzihaUun8pt6l6T+ZovG4pS+W3 lBGeKlSt4d60RPu1vEPJJoAMDbZTuFVtM9QjPVOC81yZd/ZvyPRDZ6DUkbMgsB8Vw06i bCu4rrpg2H8ULE6cr6dGTCpvjMACG7gPYtZomumxerj6IWDzxjhQjCsa9J9Q37KxqIlt 5nH65yyl4P0DpJrFBs0XgXbM//+q+O6VWOqtQjMclu+nbwnIZlvayiY9nAM4hYGRmqgg t+Zg== X-Forwarded-Encrypted: i=1; AJvYcCX0MhKnEj95F2EEYll/PG8oYHYsxYlADmfsvBCJdU18MvXZ9bhAp0yzJn7tVF81S6rrE0Q991e6TljzuzA3QoAPkTdkhL7npylKUVP0 X-Gm-Message-State: AOJu0YxSfTngJVglahwAXcyRFH50qWxV+KcEMzgaNk4Tv0vKjqQ+QamM /dgYYGjt4/JEFYmuExnwdH7rNp7mjinrRygl6dCCmgpcP5yTSyfXwcxhSBlcl4E+CPpYfBoxyWq v2XmfXRs+KVd6NxhkUkyPT4P+tOVcbldVIBrW X-Received: by 2002:a50:cdcc:0:b0:560:1a1:eb8d with SMTP id h12-20020a50cdcc000000b0056001a1eb8dmr322200edj.7.1708600867697; Thu, 22 Feb 2024 03:21:07 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240221202655.2423854-1-jannh@google.com> <20240221202655.2423854-2-jannh@google.com> In-Reply-To: From: Jann Horn Date: Thu, 22 Feb 2024 12:20:29 +0100 Message-ID: Subject: Re: [PATCH 2/2] kallsyms: build faster by using .incbin To: Masahiro Yamada Cc: Andrew Morton , Nick Desaulniers , Miguel Ojeda , Zhen Lei , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 22, 2024 at 5:07=E2=80=AFAM Masahiro Yamada wrote: > On Thu, Feb 22, 2024 at 5:27=E2=80=AFAM Jann Horn wrot= e: > > > > Currently, kallsyms builds a big assembly file (~19M with a normal > > kernel config), and then the assembler has to turn that big assembly > > file back into binary data, which takes around a second per kallsyms > > invocation. (Normally there are two kallsyms invocations per build.) > > > > It is much faster to instead directly output binary data, which can > > be imported in an assembly file using ".incbin". This is also the > > approach taken by arch/x86/boot/compressed/mkpiggy.c. > > > Yes, that is a sensible case because it just wraps the binary > without any modification. > > > > > > So this patch switches kallsyms to that approach. > > > > A complication with this is that the endianness of numbers between > > host and target might not match (for example, when cross-compiling); > > and there seems to be no kconfig symbol that tells us what endianness > > the target has. > > > > CONFIG_CPU_BIG_ENDIAN is it. > > > > You could do this: > > if is_enabled CONFIG_CPU_BIG_ENDIAN; then > kallsymopt=3D"${kallsymopt} --big-endian" > fi > > if is_enabled CONFIG_64BIT; then > kallsymopt=3D"${kallsymopt} --64bit" > fi Aah, nice, thanks, I searched for endianness kconfig flags but somehow missed that one. Though actually, I think further optimizations might make it necessary to directly operate on ELF files anyway, in which case it would probably be easier to keep using the ELF header... > > So pass the path to the intermediate vmlinux ELF file to the kallsyms > > tool, and let it parse the ELF header to figure out the target's > > endianness. > > > > I have verified that running kallsyms without these changes and > > kallsyms with these changes on the same input System.map results > > in identical object files. > > > > This change reduces the time for an incremental kernel rebuild > > (touch fs/ioctl.c, then re-run make) from 27.7s to 24.1s (medians > > over 16 runs each) on my machine - saving around 3.6 seconds. > > > > > This reverts bea5b74504742f1b51b815bcaf9a70bddbc49ce3 > > Somebody might struggle with debugging again, but I am not sure. > > Arnd? > > > > If the effort were "I invented a way to do kallsyms in > one pass instead of three", it would be so much more attractive. Actually, I was chatting with someone about this yesterday, and I think I have an idea on how to get rid of two link steps... I might try out some stuff and then come back with another version of this series afterwards. > I am not so sure if this grain of the optimization is exciting, > but I confirmed that a few seconds were saved for the defconfig. > > I am neutral about this. > > > > For the debugging purpose, perhaps we can add --debug option > in order to leave the possibility for > outputting the full assembly as comments. Hm, maybe... though that also involves a lot of duplicate code...