Your browser does not support JavaScript! Skip to main content
Free 30-day trial DO-178C Handbook RapiCoupling Preview DO-178C Multicore Training Multicore Resources
Rapita Systems
 

Industry leading verification tools & services

Rapita Verification Suite (RVS)

  RapiTest - Unit/system testing  RapiCover - Structural coverage analysis  RapiTime - Timing analysis (inc. WCET)  RapiTask - Scheduling visualization  RapiCoverZero - Zero footprint coverage analysis  RapiTimeZero - Zero footprint timing analysis  RapiTaskZero - Zero footprint scheduling analysis  RapiCouplingPreview - DCCC analysis

Multicore Verification

  MACH178  MACH178 Foundations  Multicore Timing Solution  RapiDaemons

Engineering Services

  V&V Services  Data Coupling & Control Coupling  Object code verification  Qualification  Training  Consultancy  Tool Integration  Support

Industries

  Civil Aviation (DO-178C)   Automotive (ISO 26262)   Military & Defense   Space

Other

RTBx Mx-Suite Software licensing Product life cycle policy RVS Assurance issue policy RVS development roadmap

Latest from Rapita HQ

Latest news

SAIF Autonomy to use RVS to verify their groundbreaking AI platform
RVS 3.22 Launched
Hybrid electric pioneers, Ascendance, join Rapita Systems Trailblazer Partnership Program
Magline joins Rapita Trailblazer Partnership Program to support DO-178 Certification
View News

Latest from the Rapita blog

How to certify multicore processors - what is everyone asking?
Data Coupling Basics in DO-178C
Control Coupling Basics in DO-178C
Components in Data Coupling and Control Coupling
View Blog

Latest discovery pages

control_tower DO-278A Guidance: Introduction to RTCA DO-278 approval
Picture of a car ISO 26262
DCCC Image Data Coupling & Control Coupling
Additional Coe verification thumb Verifying additional code for DO-178C
View Discovery pages

Upcoming events

Avionics and Testing Innovations 2025
2025-05-20
DASC 2025
2025-09-14
DO-178C Multicore In-person Training (Fort Worth, TX)
2025-10-01
DO-178C Multicore In-person Training (Toulouse)
2025-11-04
View Events

Technical resources for industry professionals

Latest White papers

Mitigation of interference in multicore processors for A(M)C 20-193
Sysgo WP
Developing DO-178C and ED-12C-certifiable multicore software
DO178C Handbook
Efficient Verification Through the DO-178C Life Cycle
View White papers

Latest Videos

Rapita Systems - Safety Through Quality
Simulation for the Motorola 68020 microprocessor with Sim68020
AI-driven Requirements Traceability for Faster Testing and Certification
Multicore software verification with RVS 3.22
View Videos

Latest Case studies

GMV case study front cover
GMV verify ISO26262 automotive software with RVS
Kappa: Verifying Airborne Video Systems for Air-to-Air Refueling using RVS
Supporting DanLaw with unit testing and code coverage analysis for automotive software
View Case studies

Other Resources

 Webinars

 Brochures

 Product briefs

 Technical notes

 Research projects

 Multicore resources

Discover Rapita

Who we are

The company menu

  • About us
  • Customers
  • Distributors
  • Locations
  • Partners
  • Research projects
  • Contact us

US office

+1 248-957-9801
info@rapitasystems.com
Rapita Systems, Inc.
41131 Vincenti Ct.
Novi
MI 48375
USA

UK office

+44 (0)1904 413945
info@rapitasystems.com
Rapita Systems Ltd.
Atlas House
Osbaldwick Link Road
York, YO10 3JB
UK

Spain office

+34 93 351 02 05
info@rapitasystems.com
Rapita Systems S.L.
Parc UPC, Edificio K2M
c/ Jordi Girona, 1-3
Barcelona 08034
Spain

Working at Rapita

Careers

Careers menu

  • Current opportunities & application process
  • Working at Rapita
Back to Top Contact Us

Function pointers and their impact on stack analysis

Breadcrumb

  1. Home
2015-03-04

Introduction

Function pointers present a real problem for static code analysis, including when calculating stack usage. Understanding software stack requirements is an activity that is required for several standards/guidelines including DO-178B and DO-178C. Nevertheless, function pointers are supported and therefore prevalent in most system-level languages (C and Ada both have them, whilst they are used all the time with C++). Any operating system, higher-level function, or middleware providing hooks will usually resort to function pointers for the user-side part of their operation.

Establishing which functions can be called indirectly can be time-consuming and error-prone, especially when done by hand. It is even sometimes impossible to establish manually which functions may be called indirectly - for example when some part of a finished executable has no source available.

In some situations failure to analyze function pointers can even lead to overly optimistic results - for example when stack analysis does not know where to look for sub-calls and therefore assumes an indirect call uses zero stack. Really, the only way to reliably trap function calls is by observation - i.e. dynamic analysis. stack usage table

Source and object instrumentation

Function pointer calls can be done through source code analysis when source is available. To be completely thorough though, object code analysis is required. This means looking at the assembly or machine-code level analysis of the compiled source, and has the added benefit of being able to catch all indirect function calls, even if they are made from part of an executable for which no source code exists. It is full of complications though - in order to be meaningful in a report a map must exist between the assembly code that has been analyzed, and the source code it originates from. Luckily debuggers have been doing a good job of providing this kind of mapping for many years and algorithms exist for providing linear-time mappings from assembly to source with relatively low memory overhead.

Recording the results

Each time an instrumented function pointer is seen, a map must be recorded between the origin of the call and the destination function. Some chips and hardware have capabilities for on-chip tracing which helps us to be able to produce a trace of, say, all branch statements made by the processor. Sadly this is not commonplace, and other strategies must be employed in order to extract the required information.

Naively this can be done via a trace - every time a function pointer call is seen the original location of the call and the function being called can be output to a trace. We do this via instrumentation of the code to call tracing functions which store the relevant data. The problem with this, is that the trace is unbounded - observe the same indirect call 2000 times and you will have 2000 records of this in your trace. However, there are only a finite number of combinations of functions and pointers that can be made, bounded by (number of functions * indirect call locations). Therefore, it is straightforward enough to provide a map of caller to callee which updates in linear-time. In fact, if speed and memory are not an issue during your analysis run then a map can be used as good alternative to tracing.

It is also possible to provide constant-time instrumentation as a bitmap (one bit per caller-callee pair) via object-code level instrumentation, where access to the assembly allows more controlled injection of data and instrumentation code.

Identifying indirect calls

One of the major issues with object code analysis is the number of creative (and, thanks to optimization, often employed) ways that a function can be called indirectly. Partly this is down to the processor, and partly down to the compiler.

On the ARM processor, for example, the program counter is just a register that can be written to like any other - any instruction that can alter a register (which is pretty much all of them) can alter the program counter and therefore has the potential to be used for indirect calls. These instructions can be used interchangeably with the return from a subroutine. Ironically the instructions used for direct function calls on the ARM are among the few which are not capable of invoking indirect calls. In addition the instruction to preserve and update the return-from-subroutine register may appear in a variety of forms and is not bound to the updating of the program counter.

An example of a hand-coded indirect function call on the ARM processor:

.indirect_function
STMIA R13!, {R1-R3, R14}  -- Preserve calls
ADR   R14, subcall_return -- Move the address of the return into the link R14
MOV   R0, #15             -- Move the constant 15 into R0
MOV   PC, R1              -- Move the contents of R1 into the program counter
.subcall_return
LDMIA R13!, {R1-R3, PC}   -- Return from this routine, restoring R0-R3 at the same time

Luckily there are some processors, such as the PowerPC, where identification of indirect calls falls to a single dedicated instruction, which is therefore easily identified. Identifying the patterns which a specific compiler uses for indirect function calls (as opposed to other jumps in general - indirect or otherwise) is a task that needs to be performed on a per-compiler basis. Where various binaries from different compilers are packaged together (or even, as is likely with operating systems, hand-coded assembly is provided) this task becomes even more complex, though not impossible.

Conclusion

In conclusion, function pointer analysis is an area fraught with complexity - the more it is looked at, the more corner-cases we find. In order to perform to the most optimal level with the greatest completeness object-code analysis is required; however this comes with its own issues, some of which are considerably harder to deal with than others. You can find out more about tools for worst case stack analysis in the technical note below.

DO-178C webinars

DO178C webinars

White papers

Mitigation of interference in multicore processors for A(M)C 20-193
Sysgo WP Developing DO-178C and ED-12C-certifiable multicore software
DO178C Handbook Efficient Verification Through the DO-178C Life Cycle
A Commercial Solution for Safety-Critical Multicore Timing Analysis

Related blog posts

DO-178C - Stage of Involvement 4

.
2022-04-06

DO-178C - Stage of Involvement 3

.
2022-03-23

DO-178C - Stage of Involvement 2

.
2022-03-09

DO-178C - Stage of Involvement 1

.
2022-03-01

Pagination

  • Current page 1
  • Page 2
  • Page 3
  • Page 4
  • Page 5
  • Next page Next ›
  • Last page Last »
  • Solutions
    • Rapita Verification Suite
    • RapiTest
    • RapiCover
    • RapiTime
    • RapiTask
    • MACH178

    • Verification and Validation Services
    • Qualification
    • Training
    • Integration
  • Latest
  • Latest menu

    • News
    • Blog
    • Events
    • Videos
  • Downloads
  • Downloads menu

    • Brochures
    • Webinars
    • White Papers
    • Case Studies
    • Product briefs
    • Technical notes
    • Software licensing
  • Company
  • Company menu

    • About Rapita
    • Careers
    • Customers
    • Distributors
    • Industries
    • Locations
    • Partners
    • Research projects
    • Contact
  • Discover
    • Multicore Timing Analysis
    • Embedded Software Testing Tools
    • Worst Case Execution Time
    • WCET Tools
    • Code coverage for Ada, C & C++
    • MC/DC Coverage
    • Verifying additional code for DO-178C
    • Timing analysis (WCET) & Code coverage for MATLAB® Simulink®
    • Data Coupling & Control Coupling
    • Aerospace Software Testing
    • Automotive Software Testing
    • Certifying eVTOL
    • DO-178C
    • AC 20-193 and AMC 20-193
    • ISO 26262
    • What is CAST-32A?

All materials © Rapita Systems Ltd. 2025 - All rights reserved | Privacy information | Trademark notice Subscribe to our newsletter