This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 2645e06c862ca3726f12b6abf629b358151c1dbd Author: liwenxiang1 <[email protected]> AuthorDate: Tue Jan 7 15:59:56 2025 +0800 arch/x86_64: Add gprof add gprof tool Signed-off-by: liwenxiang1 <[email protected]> --- arch/x86_64/src/common/Toolchain.defs | 4 +++ libs/libc/machine/x86_64/CMakeLists.txt | 4 +++ libs/libc/machine/x86_64/Make.defs | 9 +++++ libs/libc/machine/x86_64/mcount.S | 63 +++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/arch/x86_64/src/common/Toolchain.defs b/arch/x86_64/src/common/Toolchain.defs index ff2309e3c16..2cff921aab5 100644 --- a/arch/x86_64/src/common/Toolchain.defs +++ b/arch/x86_64/src/common/Toolchain.defs @@ -77,6 +77,10 @@ ifeq ($(CONFIG_ARCH_INSTRUMENT_ALL),y) ARCHOPTIMIZATION += -finstrument-functions endif +ifeq ($(CONFIG_PROFILE_ALL),y) + ARCHOPTIMIZATION += -pg +endif + ARCHCFLAGS += -fno-common -Wno-attributes ARCHCXXFLAGS += -fno-common -Wno-attributes -nostdinc++ diff --git a/libs/libc/machine/x86_64/CMakeLists.txt b/libs/libc/machine/x86_64/CMakeLists.txt index 918b95d6032..e904299ff01 100644 --- a/libs/libc/machine/x86_64/CMakeLists.txt +++ b/libs/libc/machine/x86_64/CMakeLists.txt @@ -78,4 +78,8 @@ if(CONFIG_X86_64_STRNCMP) list(APPEND SRCS arch_strncmp.S) endif() +if(CONFIG_PROFILE_MINI) + list(APPEND SRCS gnu/mcount.S) +endif() + target_sources(c PRIVATE ${SRCS}) diff --git a/libs/libc/machine/x86_64/Make.defs b/libs/libc/machine/x86_64/Make.defs index 339f041aab9..4184b7a74fc 100644 --- a/libs/libc/machine/x86_64/Make.defs +++ b/libs/libc/machine/x86_64/Make.defs @@ -76,5 +76,14 @@ ifeq ($(CONFIG_X86_64_STRNCMP),y) ASRCS += arch_strncmp.S endif +ifeq ($(CONFIG_PROFILE_MINI),y) +ASRCS += mcount.S +endif + +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +DEPPATH += --dep-path machine/x86_64/gnu +VPATH += :machine/x86_64/gnu +endif + DEPPATH += --dep-path machine/x86_64 VPATH += :machine/x86_64 diff --git a/libs/libc/machine/x86_64/mcount.S b/libs/libc/machine/x86_64/mcount.S new file mode 100644 index 00000000000..ca9c1a84b50 --- /dev/null +++ b/libs/libc/machine/x86_64/mcount.S @@ -0,0 +1,63 @@ +/**************************************************************************** + * libs/libc/machine/x86_64/gnu/mcount.S + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + + .globl mcount + .type mcount, @function + +mcount: + + /* Allocate space for 7 registers */ + + subq $56, %rsp + movq %rax, (%rsp) + movq %rcx, 8(%rsp) + movq %rdx, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdi, 32(%rsp) + movq %r8, 40(%rsp) + movq %r9, 48(%rsp) + + movq 56(%rsp),%rsi + + /* Get frompc via the fp */ + + movq 8(%rbp), %rdi + + /* Jump to mcount_internal */ + + call mcount_internal + + /* Pop the saved registers. Please note that `mcount' has no + return value. + */ + + movq 48(%rsp),%r9 + movq 40(%rsp),%r8 + movq 32(%rsp),%rdi + movq 24(%rsp),%rsi + movq 16(%rsp),%rdx + movq 8(%rsp), %rcx + movq (%rsp), %rax + addq $56, %rsp + ret
