Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2152850rwd; Fri, 2 Jun 2023 05:46:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5W+mDP5k51awA6vk9NLF8BWKbuRRxe/C0RjFTLZvMgQHjbRFSxOkTVlrYyJoeu2IxGA3Qu X-Received: by 2002:a05:6a20:4415:b0:10b:6b1f:c8c8 with SMTP id ce21-20020a056a20441500b0010b6b1fc8c8mr4520598pzb.31.1685709972779; Fri, 02 Jun 2023 05:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685709972; cv=none; d=google.com; s=arc-20160816; b=Y8gq0seywiyuxmZzn7YCgTT5SlQXVIZWKaUjqyETi4o1r+DHOj9mjmff1GSASRUYRZ vggrCqIsT2vIk+lyDoE/bQw3I7dTvOaxYoC33KiNkif2rHOScmpciWnBlZ7uUEWTD8oo aMFcVDgJHKxHjLL7CWbSaY2iI32nMT51ZqOGds6EdBuG3wp2VYNyGiMltWSoO170fSa8 F1ZH3jSV+jOJUfaYLWYZSKnZGSUQNAaEphNHGqQOMkONO9fa8ICU7o9ndrtHQt7vBudi vEkaLJ6PqaKoNgh6USQXfM/xhB4vCnFzJP3+S7qelYHD2VrchlHJKwWed7b/eNF0qKgP dQSA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Nh+0N7gAaajlUQA9Pn27BgVBINuOBcCyPpKtQHaHnrE=; b=CObbtWNn2rmEwGWs95zFFUgHRD9alkkGEXD0RaMsyfogZtsw7iG0GNxtPbAztWF/xD /eGGSSBpCubE1njwzBfNqQqbDZVo6/K3j9qmDG/7aEYFlXqm/9/YfUf5mLyBLEw9mitE XvssyMj66hj0f5xqjA3C2kYVWtckAG9kUtvJScpImFfVQpov6wo+SQE6a2WHgX3QvTon QboyTNs/JDBlMREVgRdeHUNzOiJPlBsCZmfWtRANebFJp3OPxaWOfNm18yUu49kFR34T saE+h07uKIj8/sUBPld6720D8g+kUaV9X7xC0sGUELgVBPqcaX2sxS/mhULAsgEDYoEd 4ZEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=iTJt9d04; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e18-20020a637452000000b0053fb7f98c63si898148pgn.778.2023.06.02.05.45.51; Fri, 02 Jun 2023 05:46:12 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b=iTJt9d04; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235564AbjFBMi6 (ORCPT + 99 others); Fri, 2 Jun 2023 08:38:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235124AbjFBMiu (ORCPT ); Fri, 2 Jun 2023 08:38:50 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A39121AE; Fri, 2 Jun 2023 05:38:40 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-97448470403so274267666b.1; Fri, 02 Jun 2023 05:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685709519; x=1688301519; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Nh+0N7gAaajlUQA9Pn27BgVBINuOBcCyPpKtQHaHnrE=; b=iTJt9d04Vot5XFIg18UMJRaIBs2Wduoabj56wOgaCPtALfWNud3uLrafoJUUEcVrlX 7Kfrmn2Qm98+LBZfNKGnAq7HcA2wQD8Vlsz4GWowDYKfeRnspE+U/2O7zYNNffa7KpBr GDZ8HVrGwYkhK6lgdAWffSz+JwVh55BbwTblwC2QeBWWGyypf+LTKXR+h1wDp7UO3HWh CqaEbX3DltujTEEIKdDfHVFny0RACA7JblEBBlqS7JmhKnECX9E1u7QNAnCekkKSmYNN I6qRwfOZRU281wMatz/vuQDTa4nI21L0M9/cR57seaBOYrD4NEu0A8nsL4/kaI5Erdi9 Gazw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685709519; x=1688301519; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Nh+0N7gAaajlUQA9Pn27BgVBINuOBcCyPpKtQHaHnrE=; b=QhbOIjKd7PC3HGoeVs4trpdwKmZpmbIRAUhanoFekSBBA6gOCzpDETgIZHyEeExtxB Vxcky04chBN4skx3bMv4i3UEC1TUNnoTin+aUgRNbNFKeq1PDm8ncPDhPMXLOCtSkjBp lUeugbAHep+dbJig0k6NZgDw7rBeDmgsTEMxf+Hdqi6QfbYwVWpuAHo+H1FCsf+QQMBQ Zbm+xvKhXtreUZcc3bagz4Kt+r63tPSSMPd6iYrENCCQp5Pvgs4q3TZKohY6dH1HB2g1 0JnQHBGH182cmnYfdT3+5K8U+g8UOcWE7dLV/0PjGzK0i2L3lu4FSBl2YDmzoLXtzQFu BJOQ== X-Gm-Message-State: AC+VfDxemhfq3o0a63Dxb98RS7FroKMw3lh9+A5wJD++P4o119I+T2yF F5f9/VEkGFJ2Vrd1h5cuQAY= X-Received: by 2002:a17:907:a426:b0:96f:c988:93b with SMTP id sg38-20020a170907a42600b0096fc988093bmr11351938ejc.35.1685709518815; Fri, 02 Jun 2023 05:38:38 -0700 (PDT) Received: from epleaning.kpn (2a02-a45b-7f00-1-8367-a07d-b687-2141.fixed6.kpn.net. [2a02:a45b:7f00:1:8367:a07d:b687:2141]) by smtp.gmail.com with ESMTPSA id ot12-20020a170906cccc00b0096f4c9ce526sm706249ejb.225.2023.06.02.05.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 05:38:38 -0700 (PDT) From: Elisabeth To: namhyung@kernel.org Cc: elisabeth , Elisabeth Panholzer , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH v2] Subject: perf jit: Fix incorrect file name in DWARF line table Date: Fri, 2 Jun 2023 14:38:15 +0200 Message-Id: <20230602123815.255001-1-paniii94@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 From: elisabeth Fixes an issue where an incorrect filename was added in the DWARF line table of an ELF object file when calling 'perf inject --jit' due to not checking the filename of a debug entry against the repeated name marker (/xff/0). The marker is mentioned in the tools/perf/util/jitdump.h header, which describes the jitdump binary format, and indicitates that the filename in a debug entry is the same as the previous enrty. In the function emit_lineno_info(), in the file tools/perf/util/genelf-debug.c, the debug entry filename gets compared to the previous entry filename. If they are not the same, a new filename is added to the DWARF line table. However, since there is no check against '\xff\0', in some cases '\xff\0' is inserted as the filename into the DWARF line table. This can be seen with `objdump --dwarf=line` on the ELF file after `perf inject --jit`. It also makes no source code information show up in 'perf annotate'. Signed-off-by: Elisabeth Panholzer Cc: linux-kernel@vger.kernel.org Cc: linux-perf-users@vger.kernel.org --- Changes in v2: - Made the commit message more descriptive - Added a comment that mentions the jitdump format - Changed memcmp() to strcmp() tools/perf/util/genelf_debug.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/genelf_debug.c b/tools/perf/util/genelf_debug.c index aa5dcc56b2ac..138fdf87eaa2 100644 --- a/tools/perf/util/genelf_debug.c +++ b/tools/perf/util/genelf_debug.c @@ -337,6 +337,9 @@ static void emit_lineno_info(struct buffer_ext *be, { size_t i; + /* as described in the jitdump format */ + const char repeated_name_marker[] = {'\xff', '\0'}; + /* * Machine state at start of a statement program * address = 0 @@ -363,7 +366,8 @@ static void emit_lineno_info(struct buffer_ext *be, /* * check if filename changed, if so add it */ - if (!cur_filename || strcmp(cur_filename, ent->name)) { + if ((!cur_filename || strcmp(cur_filename, ent->name)) && + strcmp(repeated_name_marker, ent->name)) { emit_lne_define_filename(be, ent->name); cur_filename = ent->name; emit_set_file(be, ++cur_file_idx); -- 2.34.1