libs: add gprof arm64 support

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai
2024-08-14 17:40:28 +08:00
committed by Xiang Xiao
parent 1b42a7bf84
commit d375a09c0a
4 changed files with 81 additions and 0 deletions

View File

@@ -88,6 +88,10 @@ ifeq ($(CONFIG_ARCH_INSTRUMENT_ALL),y)
ARCHOPTIMIZATION += -finstrument-functions
endif
ifeq ($(CONFIG_SCHED_GPROF_ALL),y)
ARCHOPTIMIZATION += -pg
endif
ifeq ($(CONFIG_ARCH_FPU),y)
ARCHCXXFLAGS += -D_LDBL_EQ_DBL
ARCHCFLAGS += -D_LDBL_EQ_DBL

View File

@@ -135,6 +135,10 @@ if(CONFIG_ARCH_INSTRUMENT_ALL)
add_compile_options(-finstrument-functions)
endif()
if(CONFIG_SCHED_GPROF_ALL)
add_compile_options(-pg)
endif()
if(CONFIG_ARCH_FPU)
add_compile_options(-D_LDBL_EQ_DBL)
endif()

View File

@@ -21,6 +21,13 @@
#ifndef __INCLUDE_SYS_GMON_H
#define __INCLUDE_SYS_GMON_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
#include <stdint.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@@ -46,6 +53,9 @@ void monstartup(unsigned long lowpc, unsigned long highpc);
void _mcleanup(void);
noinstrument_function
void mcount_internal(uintptr_t frompc, uintptr_t selfpc);
#undef EXTERN
#if defined(__cplusplus)
}

View File

@@ -0,0 +1,63 @@
/****************************************************************************
* libs/libc/machine/arm64/gnu/mcount.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/gmon.h>
/****************************************************************************
* Private Functions
****************************************************************************/
static inline noinstrument_function void *strip_pac(void *p)
{
register void *ra asm ("x30") = (p);
asm ("hint 7 // xpaclri" : "+r"(ra));
return ra;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: _mcount
*
* Description:
* This is the ARM64 mcount function. It is called by the profiling
* logic to record the call.
*
* Input Parameters:
* frompc - The address of the calling instruction
*
* Returned Value:
* None
*
****************************************************************************/
noinstrument_function
void _mcount(void *frompc)
{
mcount_internal((uintptr_t)strip_pac(frompc),
(uintptr_t)return_address(0));
}