Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4900019pxb; Sun, 13 Feb 2022 00:37:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgb0F3TYfcXxw347L4YbhE5U05uINzdjyURB35ZFaOcBzHT2ewYKCh2ljPdgYNK12Pq/zc X-Received: by 2002:aa7:d059:: with SMTP id n25mr10102945edo.106.1644741431112; Sun, 13 Feb 2022 00:37:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644741431; cv=none; d=google.com; s=arc-20160816; b=F4klPdR2Yzv5S4/cyAh0GSFTfnEQyHluqFCryEWeu1FtEzSjP5ZzgLNYYcR5M5Zp6z Axek+g2qPglxNGWqNs7aEuXoPZsW9MX0Ix38gASfulh/Mgu67m6Z0nJaLjXJfbiDbAIl 9Vw9YVu1rBdqJyqKlIvW+IMMB5arok9gSW3VQAsl2YvJYUTXjNwybEmFQGCDMNr3T+Gi Iri87SylI7PFCgRIxLZQnk3Xsl9mY0cENEJnbOpqTOYBykNAIOGjk7+YdDB2pHPOaxZk VIXqMA+X2ASlxZnr6HOrLOrQaVWqhqlXJLC5fGMy5qvfR8fgG4UnYFNCjVVIJbADcStg P8EA== 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=s3jlJraeyBb9/493NaLoTuN9dxYNUhvlX26flq1ssjw=; b=ii9H2J9nVmWl6ctTVwZpg+nWHjyycZ5ojnv8oQfAwD0nEr7tGG3IUj9UWB+0Q4P1Oc esWqJMzL/ckem57HC8MaLCNn35xpDwMGhrxr5sO6/4TaRPMoRIQL3cw8Lyzx1AW1zWdw YJuMe5lOu2JoujHYTtADsKnPDbM7R55qx631qKmt/3k7qyTOYdNvc8oBi82QbdiHEjHA 7oT191+9gSRYaN5/MvpjJ9yQP0kTvNXxNG3gN8hUgpEmj9oYLWnNKO09i/ovTOlYMxKD IDsU8sYv4qTwfYXRC0ao6hdC1O+G/usDSndZSufGB0CKD3DThZkKHLkqot69HtEGe1rX t6rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HLXQ8rH6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb11si21500371edb.149.2022.02.13.00.36.48; Sun, 13 Feb 2022 00:37:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HLXQ8rH6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235259AbiBLNFR (ORCPT + 99 others); Sat, 12 Feb 2022 08:05:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235246AbiBLNFP (ORCPT ); Sat, 12 Feb 2022 08:05:15 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7149826AF9; Sat, 12 Feb 2022 05:05:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 179DCB8068E; Sat, 12 Feb 2022 13:05:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C06FC340E7; Sat, 12 Feb 2022 13:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644671105; bh=I9zqqNz6a40jJe8Y6XJkwn3RA7u4Nik/c6hmRpvHBK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HLXQ8rH60xZuvy6UTsfGsN5jE11beT/h7rKCUfCRPcc+KbcgkvKfwogoIIB92MrtR 6edDfmM2CU3mqai9oepD2z9WxBlAfVl9+J22japM0izJA3TQjRloe64d5pGLUPdPhh IGjZWIW8vZc3N0kOUX0E9ZmSIzDs40uWHCATfoq3r+tNeYVcaKHnXONjtsnFDyNxSk E9j+hkd+jIu7btG/MO32BZ6SjLP9eUwNIq+25RF/Om0Kf7TQ6Ak19S5mx55pcebwUZ bC99FC6CfHwXn+rlMDX2RJB8HqbAHcaG0GNkPc64M/dAko6d5nvvLVCAWWWryx2xoC Ru/4xL6wtJ3HA== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , Boqun Feng , Matthew Wilcox Subject: [PATCH v4 01/20] kallsyms: support "big" kernel symbols Date: Sat, 12 Feb 2022 14:03:27 +0100 Message-Id: <20220212130410.6901-2-ojeda@kernel.org> In-Reply-To: <20220212130410.6901-1-ojeda@kernel.org> References: <20220212130410.6901-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 longer lengths to the symbol table. In order to avoid increasing all lengths to 2 bytes (since most of them are small, including many Rust ones), we use ULEB128 to keep smaller symbols in 1 byte, with the rest in 2 bytes. Co-developed-by: Alex Gaynor Signed-off-by: Alex Gaynor Co-developed-by: Wedson Almeida Filho Signed-off-by: Wedson Almeida Filho Co-developed-by: Gary Guo Signed-off-by: Gary Guo Co-developed-by: Boqun Feng Signed-off-by: Boqun Feng Co-developed-by: Matthew Wilcox Signed-off-by: Matthew Wilcox Signed-off-by: Miguel Ojeda --- kernel/kallsyms.c | 26 ++++++++++++++++++++++---- scripts/kallsyms.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 951c93216fc4..57213e1d2349 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -69,12 +69,20 @@ static unsigned int kallsyms_expand_symbol(unsigned int off, data = &kallsyms_names[off]; len = *data; data++; + off++; + + /* If MSB is 1, it is a "big" symbol, so needs an additional byte. */ + if ((len & 0x80) != 0) { + len = (len & 0x7F) | (*data << 7); + data++; + off++; + } /* * Update the offset to return the offset for the next symbol on * the compressed stream. */ - off += len + 1; + off += len; /* * For every byte on the compressed symbol data, copy the table @@ -127,7 +135,7 @@ static char kallsyms_get_symbol_type(unsigned int off) static unsigned int get_symbol_offset(unsigned long pos) { const u8 *name; - int i; + int i, len; /* * Use the closest marker we have. We have markers every 256 positions, @@ -141,8 +149,18 @@ static unsigned int get_symbol_offset(unsigned long pos) * so we just need to add the len to the current pointer for every * symbol we wish to skip. */ - for (i = 0; i < (pos & 0xFF); i++) - name = name + (*name) + 1; + for (i = 0; i < (pos & 0xFF); i++) { + len = *name; + + /* + * If MSB is 1, it is a "big" symbol, so we need to look into + * the next byte (and skip it, too). + */ + if ((len & 0x80) != 0) + len = ((len & 0x7F) | (name[1] << 7)) + 1; + + name = name + len + 1; + } return name - kallsyms_names; } diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 54ad86d13784..79b11bb7f07d 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -470,12 +470,35 @@ 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. */ + 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-byte ULEB128 are supported. */ + if (table[i]->len > 0x3FFF) { + fprintf(stderr, "kallsyms failure: " + "unexpected huge symbol length\n"); + exit(EXIT_FAILURE); + } + + /* Encode length with ULEB128. */ + if (table[i]->len <= 0x7F) { + /* 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 two bytes. */ + printf("\t.byte 0x%02x, 0x%02x", + (table[i]->len & 0x7F) | 0x80, + (table[i]->len >> 7) & 0x7F); + off += table[i]->len + 2; + } 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.35.1