Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp357150pxb; Wed, 14 Apr 2021 17:43:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNUmb5xaQSL3JJh7Up5NVzKaXhEuNcxDAaAN4Ez3+ZMTX/11lpXAzjnFEC4/5590Sxe5kq X-Received: by 2002:a17:907:210a:: with SMTP id qn10mr759232ejb.414.1618447387333; Wed, 14 Apr 2021 17:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618447387; cv=none; d=google.com; s=arc-20160816; b=tIfPmaf3Ex1PVVcoIxUq5GR3rKP3NvEDXMl8HgZXTfyWK8+P2WMQS8ViKgzrejSOs4 JXpvZpzfybzlIGRHv3ZztTp2PKGxYmEi29KCsva6VFNsA/YmnWIlHQVorBJxWaJc0fEM dGXHqpCGgBtDPlj575pkUQ+Z4P6DSWuNLiBT0zlAkXWzHiqLw5XG/dz8Q7oqu3lDmCDZ qR4jqLbbyPcXhNqb8ahiPge92qO+uTrNFbqIVeI6lCAUn8AM6mFG7ciwic1fkD2SbKSk mN51BzAvmqY7ks+gmBbOIrRXR4h98vz4KLzsp1DnUmORMIvU344lV5jQlAlp0LrwVrh6 ffMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uBBS4DV7GZGFB/M7MS3zt7xVoBEzQKue+fr2ih/0IXc=; b=Oy+UNeRJnSd9bwFFUD8zoi+AMtTgKAVOnnA0XTD6UZXTe7/kCv+gdU8ChCp7URvCEU KSE8GA9Lxe9oRV/vRS/C1LKgoJxu/ezjecIOURTwtjQMWdeWFz/gYKGS9KZ3QaUFsSsd UaxPR9T5SkBWDzrzu/2NE0gnDuq0cHkICAiHvyENf5VpmtayOtRbRxFnxDAbvuEwlVxx FrrzeTxr1YOSjeSp2OZ3ufi5+rHLpN00HzfqIPbWIExmiW2XzNbsHaKrT9Yst51RcLck V+ALvne72hxEYm5/JjYbsEmboJNKwsvdngkWpm4I2sTypMBtCZtfbdN2hzhYz74FfNzu VmHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PoNrqlzw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si982828edo.410.2021.04.14.17.42.44; Wed, 14 Apr 2021 17:43:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PoNrqlzw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353047AbhDNSq6 (ORCPT + 99 others); Wed, 14 Apr 2021 14:46:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:49072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353021AbhDNSqt (ORCPT ); Wed, 14 Apr 2021 14:46:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0846F61153; Wed, 14 Apr 2021 18:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618425987; bh=tIW9/GtTYEr3rMqQ5PvPIFl8/iExEIaumsIoas5zmX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PoNrqlzwz9Ra54wscIVxKxX0ProvI6EOrNWeIHFtqBB7kSGF6XofnEdnVMH3NalVp qsfxzvXGCJxTrSGUv09oa3LSgMYdyLPirYHv0QvNUTUVEyqHOFR08hJFysyJsfzHLe 26wKZXYKxSCYpgb8XWpEXvkLsDN0yjzXDDtWAKawMFWJXgPfP98s6q8AzzgzKBIsJ1 yTaGR05/kNtLBlYhGPCjqNmEZLlQS/CtXZtC637dBSQBrDiS8WkGA3kb1EDNwLHXCL StXFViddTaTOuO+a7Uw4zJkcycMiGSj3LuEpA/fj8TPj0YgVqBtUrjuM2siBrG36pP xpiZTp8U9LH5w== From: ojeda@kernel.org To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho Subject: [PATCH 01/13] kallsyms: Support "big" kernel symbols (2-byte lengths) Date: Wed, 14 Apr 2021 20:45:52 +0200 Message-Id: <20210414184604.23473-2-ojeda@kernel.org> In-Reply-To: <20210414184604.23473-1-ojeda@kernel.org> References: <20210414184604.23473-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miguel Ojeda Rust symbols can become quite long due to namespacing introduced by modules, types, traits, generics, etc. Increasing to 255 is not enough in some cases, and therefore we need to introduce 2-byte lengths to the symbol table. We call these "big" symbols. In order to avoid increasing all lengths to 2 bytes (since most of them only require 1 byte, including many Rust ones), we use length zero to mark "big" symbols in the table. Co-developed-by: Alex Gaynor Signed-off-by: Alex Gaynor Co-developed-by: Geoffrey Thomas Signed-off-by: Geoffrey Thomas Co-developed-by: Finn Behrens Signed-off-by: Finn Behrens Co-developed-by: Adam Bratschi-Kaye Signed-off-by: Adam Bratschi-Kaye Co-developed-by: Wedson Almeida Filho Signed-off-by: Wedson Almeida Filho Signed-off-by: Miguel Ojeda --- kernel/kallsyms.c | 7 +++++++ scripts/kallsyms.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 8043a90aa50e..faba546e9a58 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -73,6 +73,13 @@ static unsigned int kallsyms_expand_symbol(unsigned int off, */ off += len + 1; + /* If zero, it is a "big" symbol, so a two byte length follows. */ + if (len == 0) { + len = (data[0] << 8) | data[1]; + data += 2; + off += len + 2; + } + /* * For every byte on the compressed symbol data, copy the table * entry for that byte. diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 54ad86d13784..bcdabee13aab 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -470,12 +470,37 @@ static void write_src(void) if ((i & 0xFF) == 0) markers[i >> 8] = off; - printf("\t.byte 0x%02x", table[i]->len); + /* + * There cannot be any symbol of length zero -- we use that + * to mark a "big" symbol (and it doesn't make sense anyway). + */ + if (table[i]->len == 0) { + fprintf(stderr, "kallsyms failure: " + "unexpected zero symbol length\n"); + exit(EXIT_FAILURE); + } + + /* Only lengths that fit in up to two bytes are supported. */ + if (table[i]->len > 0xFFFF) { + fprintf(stderr, "kallsyms failure: " + "unexpected huge symbol length\n"); + exit(EXIT_FAILURE); + } + + if (table[i]->len <= 0xFF) { + /* Most symbols use a single byte for the length. */ + printf("\t.byte 0x%02x", table[i]->len); + off += table[i]->len + 1; + } else { + /* "Big" symbols use a zero and then two bytes. */ + printf("\t.byte 0x00, 0x%02x, 0x%02x", + (table[i]->len >> 8) & 0xFF, + table[i]->len & 0xFF); + off += table[i]->len + 3; + } for (k = 0; k < table[i]->len; k++) printf(", 0x%02x", table[i]->sym[k]); printf("\n"); - - off += table[i]->len + 1; } printf("\n"); -- 2.17.1