Received: by 2002:a19:651b:0:0:0:0:0 with SMTP id z27csp3659598lfb; Mon, 9 May 2022 01:03:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxRbd+Zp403rVMV+ssLtOI1MZ3hY/NZcv8mD7avX6isvxZsOwl+k6K/+vSoEZ0wY3IO6a8 X-Received: by 2002:a6b:3ec1:0:b0:65a:499f:23a4 with SMTP id l184-20020a6b3ec1000000b0065a499f23a4mr5816936ioa.189.1652083380391; Mon, 09 May 2022 01:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652083380; cv=none; d=google.com; s=arc-20160816; b=gkx+qyvCmQmP3tcd5AQaR/Ib3/QE00yr7VMJspHVSWVy6W7sZ4Aql6x/ws9vkwNlxw 7DQWNU9P3m0MDhyMj/SMWvcCczDEJ/G/49Iu2mUJaQC0FTEG8bo4bUma7kVOz/icwwma SYgmHAbaOZeafymYeM5BcBwZmqP3gGRKRuRMCBrwL69w7qByUHSCKBivhqNnNwTGmvRO ma00YCCKq1ISyoYLuCGbT7UdHmAS9Jv9VbdL+HN3AIhvDGpUUyicaOvRHu8eQ4h/gTFl tl5vNFuofqEf4M2nlUFQ0nZfHz9ZllBT44lbfM7jb7ABpZFJvORCTEYFzNZOk0dyBQbI T3UA== 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=vJj7hyb6KvONupXhNbRH0Ymg8muWpbWaMoM7jlyWrK4=; b=KuBNcoBGJq+ZlJhXhhcYKRobssglocTiGA3tbFgvRgeL7CVG6og/ofFVgPMIpAN9xH +TNEI216VgebL+H96lST+nOupzQubh6ckci6PMR5QiRPsCEBMyK+Fb7HRhEJFV9svcBE VjZ9XjJxVQulyH5hHZcqxCKUti8lPpuJ2dvPdZOw/ZFlQvLnWZ/vJ6rFGZgp8zS/h40u jyqL+zTfbwQF+d6OVaBtvlRU0LA/aRcLj2m5NkAbxL750nVn+oKwmyOGPyUVP6qERUsV uP31bp9tl9QFXzjPoU1QhkXZ8+CxXMXHeIqTswRLE7dCvKm8yjSwj+V/YQPvBMbZBsl5 arrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=phYQZs1S; 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 b5-20020a021905000000b003264e336330si6792201jab.41.2022.05.09.01.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 01:02:59 -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=phYQZs1S; 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 BC6281D7347; Mon, 9 May 2022 00:53:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384962AbiEETV4 (ORCPT + 99 others); Thu, 5 May 2022 15:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343951AbiEETVy (ORCPT ); Thu, 5 May 2022 15:21:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0676E50449; Thu, 5 May 2022 12:18:14 -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 ams.source.kernel.org (Postfix) with ESMTPS id 89D16B82F20; Thu, 5 May 2022 19:18:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 369B4C385B9; Thu, 5 May 2022 19:18:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651778291; bh=XLwv05HK4cqKvTg/DHDbRijSSxci4Q5RSO07SJNVPxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=phYQZs1SssV/Z9+rPpcDM6mV2VGi0lgzVa17AlbhV/uhf5N6ioV9N0RmwflxhPAM1 ZUI0G8mEKuANJb09zMh030bcJJ4Ns2ARneVFptBKBX58hOdNLnhWBurFCPD/ZBKtOZ PcXAhQBN8bzGTVpWZCPNPvo04+XNWk8f1hdCReWPqv3mSbwLbQfnct0Toj1QK5Mec7 2v5SazcHgjChdPRFYpsWFMkY0fqs3w81PqNBpXSD0w8JhVguxQHL4UMZGceyCzQ5L3 RwPWESFyL5EkD8vPnp7helkNvkfLvmKH1Qasto4IFZsfMix0drJ/nhNl80lpjgFXgN bqcx0f1AZyjkQ== From: Miguel Ojeda To: Randy Dunlap , Song Liu , Kees Cook , Bixuan Cui , Alexei Starovoitov , Nick Desaulniers , David Vernet , Stephen Boyd , Jiri Olsa , Masahiro Yamada , Changbin Du , Nathan Chancellor , linux-kernel@vger.kernel.org Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , Boqun Feng , Matthew Wilcox Subject: [PATCH v1 2/3] kallsyms: support "big" kernel symbols Date: Thu, 5 May 2022 21:16:44 +0200 Message-Id: <20220505191704.22812-3-ojeda@kernel.org> In-Reply-To: <20220505191704.22812-1-ojeda@kernel.org> References: <20220505191704.22812-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 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 79f2eb617a62..e8d2262ef2d2 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 880c4404731b..c4e85eec2b4b 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -480,12 +480,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.3