From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_MED,RDNS_DYNAMIC,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 946941F8C6 for ; Thu, 5 Aug 2021 12:09:40 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FA16399E011 for ; Thu, 5 Aug 2021 12:09:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FA16399E011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628165379; bh=FW0rN8SwRr1TuTP4PbwDLF6holDtfuOuGpAlWrGm/T0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=as8r+ynRb0pYqJseNDjC09W5nSGNFfqodzWllHxyXsyZzW+dPTBIHq+3zuQnQ7HWX lwPrt2SrasDxojR4Gp7vxBGphGeZARKnodZhgy2QktjwxPh6yZs8kOqoXlv5jl4S4h F7amAMDKJ6Q4MJTtEtgNj8T8Jzl7pp3NU0Yxv+q0= Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id F0BF73857C74 for ; Thu, 5 Aug 2021 12:09:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F0BF73857C74 Received: by mail-pj1-x102e.google.com with SMTP id pj14-20020a17090b4f4eb029017786cf98f9so8837633pjb.2 for ; Thu, 05 Aug 2021 05:09:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=FW0rN8SwRr1TuTP4PbwDLF6holDtfuOuGpAlWrGm/T0=; b=dIsLT+V4T+ChKiIA548TwJ+IDXjVr8085r525+Ji33Tx1lQUH3a7ZV4mR7mHr1gPFv uAtUIB2yOde3yw8N3iSXefJDSiSoEdSOZs2y+Cmn/d/jUL8LAk4SSQ2dR9FndyfSZkkM h+6DTr/xn7yv7JEAZRTFoouhRYnOo4tEZJKCSfH8iY52VvIKBw7dX4sZLTkYifZULY82 0J0Wh6OiVfSUAdY4rM0IgS9Az2zMzd5V7Q48zck7NOzBDxnzRTh6u6hZE2+fvrDlXRGx WG7gA7XddcSjy66NFe7RBqEs/R5DLiDyMgFhkfQWdm4Q4YVUc7C+BAyWB0RTqr5q31I/ EHkg== X-Gm-Message-State: AOAM531xzNBE9vmTNql0mbiZ+CgQrMk+oc/CxHvgip/nG7LLI8kyPgm4 L1NbdaMg0UGs3barrxdYsQtOBQNEGX0= X-Google-Smtp-Source: ABdhPJzz9qwlqJvwGNz0Fvt68TXXDEJl4TqkuMnElZaJtuLrg7rhetXOoLS1Dw59sWdUhKsoDl5H1w== X-Received: by 2002:a17:902:8c83:b029:129:17e5:a1cc with SMTP id t3-20020a1709028c83b029012917e5a1ccmr3691344plo.49.1628165356847; Thu, 05 Aug 2021 05:09:16 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id j3sm6823060pfe.98.2021.08.05.05.09.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 05:09:16 -0700 (PDT) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.34]) by gnu-cfl-2.localdomain (Postfix) with ESMTPS id 25896C02BD for ; Thu, 5 Aug 2021 05:09:15 -0700 (PDT) Received: from gnu-tgl-2.lan (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id DBCD83002C2 for ; Thu, 5 Aug 2021 05:09:04 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3] Use __executable_start as the lowest address for profiling [BZ #28153] Date: Thu, 5 Aug 2021 05:09:04 -0700 Message-Id: <20210805120904.3528530-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: "H.J. Lu via Libc-alpha" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Glibc assumes that ENTRY_POINT is the lowest address for which we need to keep profiling records and BFD linker uses a linker script to place the input sections. Starting from GCC 4.6, the main function is placed in .text.startup section and starting from binutils 2.22, BFD linker with commit add44f8d5c5c05e08b11e033127a744d61c26aee Author: Alan Modra Date: Thu Nov 25 03:03:02 2010 +0000 * scripttempl/elf.sc: Group .text.exit, text.startup and .text.hot sections. places .text.startup section before .text section, which leave the main function out of profiling records. Starting from binutils 2.15, linker provides __executable_start to mark the lowest address of the executable. Use __executable_start as the lowest address to keep the main function in profiling records. This fixes [BZ #28153]. Tested on Linux/x86-64, Linux/x32 and Linux/i686 as well as with build-many-glibcs.py. --- csu/gmon-start.c | 10 +++++++++- gmon/tst-gmon-gprof.sh | 2 ++ gmon/tst-gmon-static-gprof.sh | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/csu/gmon-start.c b/csu/gmon-start.c index b3432885b3..344606a676 100644 --- a/csu/gmon-start.c +++ b/csu/gmon-start.c @@ -52,6 +52,11 @@ extern char ENTRY_POINT[]; #endif extern char etext[]; +/* Use __executable_start as the lowest address to keep profiling records + if it provided by the linker. */ +extern const char executable_start[] asm ("__executable_start") + __attribute__ ((weak, visibility ("hidden"))); + #ifndef TEXT_START # ifdef ENTRY_POINT_DECL # define TEXT_START ENTRY_POINT @@ -92,7 +97,10 @@ __gmon_start__ (void) called = 1; /* Start keeping profiling records. */ - __monstartup ((u_long) TEXT_START, (u_long) &etext); + if (&executable_start != NULL) + __monstartup ((u_long) &executable_start, (u_long) &etext); + else + __monstartup ((u_long) TEXT_START, (u_long) &etext); /* Call _mcleanup before exiting; it will write out gmon.out from the collected data. */ diff --git a/gmon/tst-gmon-gprof.sh b/gmon/tst-gmon-gprof.sh index 9d371582b9..dc0be02110 100644 --- a/gmon/tst-gmon-gprof.sh +++ b/gmon/tst-gmon-gprof.sh @@ -39,12 +39,14 @@ trap cleanup 0 cat > "$expected" < "$expected_dot" < "$expected" < "$expected_dot" <