Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1614665pxp; Thu, 17 Mar 2022 12:46:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw16U1VdW6ntWyhwhK2z5fZOoxi+1gL4KD/UfW0vP2Hi3j+d5RPqRXI1zGIyfO4tA6SCoIZ X-Received: by 2002:a63:2a0e:0:b0:380:aeb3:d46c with SMTP id q14-20020a632a0e000000b00380aeb3d46cmr4987567pgq.404.1647546369402; Thu, 17 Mar 2022 12:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647546369; cv=none; d=google.com; s=arc-20160816; b=S6d1aG4x/zvaGgz1OmwO1/hfpFfHErMXZhBrmi39dDD3U2Mu0bCQ2Kbu2/TS35rFdk PHWIU+9Gn9HZ2XEj3LMIFJNJSLoHlkASIg18ZP/+1Z1BbHC5aYHChEwzdkxa0wxbxMk/ GZg6f7DcS4/eXkZkn3S9dzi5KSYkN3RMARHih4zo+NfTYz1CDpjn5Ho6fDMRNJic3TaV lLZfmfdHM0FkM/FLtfhIWbp4zqYubgoHJF3NCQ60VEiREDVQkqei4VxspQILb+hYXnvP sP2lcc2cL2gqtWG1YfzDyE97EbgbBY+talbORghIBFH5cck7I/iVO2/EjwJWhOr031oc nqEg== 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=REaG7cy+zKEzk2Qb+eow3UyvsUwaVzq37uD/KPXL6MJhOissx4LtrXeZUzVuFHpaDH TpDa9yRbTwJT6aP8xVsH51cm3iYJnLIkuReMdfXIG0qapvS1/GZ2djnmSLeckKTJTmsj A9v1SOJydph2QaBzM76U8PE3A5hwcc2Ydz3VJ1PwBbH4avdBMrpkJyUsKRR9tUfMJ2Uo OgM9tJjN0m6MTC5fW5emnH1Gd9g9LpZlKW26iwvrWb3EfDwOvmawv5CTWogvFOs17g4P qgi01hK9bw8jxPKswbzd812qsGhrTnHceaA3UKNkiHqx3svj+UM2Q8RVVAiZ9B92zsGQ UJqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bogQc+NF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 9-20020a630609000000b003821cf2feafsi1420182pgg.421.2022.03.17.12.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 12:46:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bogQc+NF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8E4BE33A4; Thu, 17 Mar 2022 12:43:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237252AbiCQSMf (ORCPT + 99 others); Thu, 17 Mar 2022 14:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237241AbiCQSMd (ORCPT ); Thu, 17 Mar 2022 14:12:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70A5221DF25; Thu, 17 Mar 2022 11:11:15 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 0F4C86164B; Thu, 17 Mar 2022 18:11:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFF99C340EE; Thu, 17 Mar 2022 18:11:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647540674; bh=I9zqqNz6a40jJe8Y6XJkwn3RA7u4Nik/c6hmRpvHBK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bogQc+NFanP5tNkbrnuPwQ49rpvd5QfUw2PuHKQid8LfvrQxAHuqkHIMU8yKtjyyy 319oywCTaVC8MvzY1buQnF0KlTDPmtitJyriIeiHt13clic0OspfBp5w8t8YhEr6TS haJqEdI88QmoVy/Da/20Oa/ymovAhn86FYu31a2HpeAu5wYAJOHwwAhmsm/hIA4vs+ t00BRllJvIURuHyCck3IKV1UabXWhnYMhWGeiFbYt5c75xSzVrp7WpfXZAXGcNyQYS cBon5UbewvnDZzNSfhkEUXRB2EM9FZv4r8G+d0IctfDju6/Nu6DOUFd9P9qY75WOQ+ alvaqx9p2k0HQ== 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 v5 01/20] kallsyms: support "big" kernel symbols Date: Thu, 17 Mar 2022 19:09:49 +0100 Message-Id: <20220317181032.15436-2-ojeda@kernel.org> In-Reply-To: <20220317181032.15436-1-ojeda@kernel.org> References: <20220317181032.15436-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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