Skip to content

Commit

Permalink
gprof: define original mcount APIs inserted by compiler
Browse files Browse the repository at this point in the history
Simplify gprof implementation via defining original mcount APIs: _mcount
(for aarch64) and __gnu_mcount_nc (for arm) inserted by compiler instead
of providing them via __utee_mcount API.

Also remove weak definitions of mcount API that were earlier mandated by
linker script via PROVIDE().

Signed-off-by: Sumit Garg <[email protected]>
Acked-by: Jerome Forissier <[email protected]>
  • Loading branch information
b49020 authored and jbech-linaro committed Apr 29, 2019
1 parent 5df2a98 commit e34f6cd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 52 deletions.
21 changes: 2 additions & 19 deletions lib/libutee/arch/arm/gprof/gprof_a32.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,15 @@
* stored on the top of the stack. The callee, i.e. the instrumented function
* itself, is determined from the current value of lr. Then we call:
* void __mcount_internal(void *frompc, void *selfpc);
*
* __gnu_mcount_nc is defined and set to the value of this function by the
* TA linker script, only if__gnu_mcount_nc is referenced
*/
FUNC __utee_mcount, :
FUNC __gnu_mcount_nc, :
stmdb sp!, {r0-r3, lr}
ldr r0, [sp, #20] /* lr of instrumented func */
mcount_adj_pc r0, r0
mcount_adj_pc r1, lr /* instrumented func */
bl __mcount_internal
ldmia sp!, {r0-r3, ip, lr}
bx ip
END_FUNC __utee_mcount

#else /* !CFG_TA_GPROF_SUPPORT */

/*
* The TA linker script always references __utee_mcount so provide a version
* that just pops one register (lr) off the stack, since that's the ABI we must
* follow.
*/
.weak __utee_mcount
FUNC __utee_mcount, :
push {lr}
pop {ip, lr}
bx ip
END_FUNC __utee_mcount
END_FUNC __gnu_mcount_nc

#endif /* CFG_TA_GPROF_SUPPORT */
20 changes: 3 additions & 17 deletions lib/libutee/arch/arm/gprof/gprof_a64.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.endm

/*
* void __utee_mcount(void *return_address)
* void _mcount(void *return_address)
* @return_address: return address to instrumented function
*
* With the -pg option, the compiler inserts a call to _mcount into
Expand All @@ -27,29 +27,15 @@
* instrumented function itself, is determined from the current value of x30.
* Then we call:
* void __mcount_internal(void *frompc, void *selfpc);
*
* _mcount is defined and set to the value of this function by the linker
* script if the TA is instrumented, i.e., if _mcount is referenced
*/
FUNC __utee_mcount, :
FUNC _mcount, :
stp x29, x30, [sp, #-16]!
mov x29, sp
adjust_pc x0, x0
adjust_pc x1, x30
bl __mcount_internal
ldp x29, x30, [sp], #16
ret
END_FUNC __utee_mcount

#else /* !CFG_TA_GPROF_SUPPORT */

/*
* The TA linker script always references __utee_mcount so provide a version
* that does nothing
*/
.weak __utee_mcount
FUNC __utee_mcount, :
ret
END_FUNC __utee_mcount
END_FUNC _mcount

#endif /* CFG_TA_GPROF_SUPPORT */
13 changes: 0 additions & 13 deletions lib/libutee/arch/arm/user_ta_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@
#include <malloc.h>
#include "tee_api_private.h"

/*
* Pull in symbol __utee_mcount.
* This symbol is implemented in assembly in its own compilation unit, and is
* never referenced except by the linker script (in a PROVIDE() command).
* Because the compilation units are packed into an archive (libutee.a), the
* linker will discard the compilation units that are not explicitly
* referenced. AFAICT this occurs *before* the linker processes the PROVIDE()
* command, resulting in an "undefined symbol" error. We avoid this by
* adding an explicit reference here.
*/
extern uint8_t __utee_mcount[];
void *_ref__utee_mcount __unused = &__utee_mcount;

struct ta_session {
uint32_t session_id;
void *session_ctx;
Expand Down
3 changes: 0 additions & 3 deletions ta/arch/arm/ta.ld.S
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ SECTIONS {
*(.gnu.linkonce.t.*)
/* Workaround for an erratum in ARM's VFP11 coprocessor */
*(.vfp11_veneer)
PROVIDE(MCOUNT_SYM = __utee_mcount);
__text_end = .;
}
.plt : { *(.plt) }
Expand Down Expand Up @@ -91,8 +90,6 @@ SECTIONS {
* TA profiling with gprof
* Reserve some space for the profiling buffer, only if the
* TA is instrumented (i.e., some files were built with -pg).
* Note that PROVIDE() above defines a symbol only if it is
* referenced in the object files.
* This also provides a way to detect at runtime if the TA is
* instrumented or not.
*/
Expand Down

0 comments on commit e34f6cd

Please sign in to comment.