From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7814) id 577FD3847809; Fri, 3 Sep 2021 17:03:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 577FD3847809 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Fangrui Song To: glibc-cvs@sourceware.org Subject: [glibc/maskray/unnest] Use __executable_start as the lowest address for profiling [BZ #28153] X-Act-Checkin: glibc X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/maskray/unnest X-Git-Oldrev: 5eb3e2c794c3fdd553833af5342740051221479c X-Git-Newrev: 84a7eb1f87c1d01b58ad887a0ab5d87abbc1c772 Message-Id: <20210903170355.577FD3847809@sourceware.org> Date: Fri, 3 Sep 2021 17:03:55 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Sep 2021 17:03:55 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=84a7eb1f87c1d01b58ad887a0ab5d87abbc1c772 commit 84a7eb1f87c1d01b58ad887a0ab5d87abbc1c772 Author: H.J. Lu Date: Fri Jul 30 19:07:30 2021 -0700 Use __executable_start as the lowest address for profiling [BZ #28153] 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. Diff: --- 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" <