# US 2014/0208301 A1 · Function calling computer programs

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2014/0208301 A1
- Document ID: US20140208301A1
- Status: Published application
- Kind: A1
- Application number: 14/086,433
- Filed: 2013-11-21
- Published: 2014-07-24
- Earliest claimed: 2012-11-29
- Assignees: International Business Machines Corporation
- Applicants: International Business Machines Corporation
- Inventors: Xiao Feng Guan; Jiu Fu Guo; Jian Jiang; Hong Wei Zhu
- Web page: https://patentgrep.com/patent/US20140208301A1

## CPC

- G06F 9/4484: {Executing subprograms}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

The present invention discloses a method and apparatus for function calling that eliminates or reduces errors caused by calling convention mismatch by preparing a number of candidate code modules during program compiling and inserting them in a compiled program. A library of compiled candidate code modules is thus included in the complied program, which allows the user to call a function by specifying a function to be called and a library where it belongs in the source program, without need to know the calling convention thereof or to focus on the call execution process. This ensures the matching of calling convention between the caller and callee of the function while being transparent to users, so as to avoid problems caused by calling convention inconsistency.

## Claims

### Claim 1

A method for function calling, comprising:
in response to detection of a function call in a program, obtaining a plurality of candidate code modules for executing the function call, the plurality of candidate code modules complying with a plurality of calling conventions respectively;
obtaining a specific calling convention used by a called function;
according to the specific calling convention obtained, selecting from the plurality of candidate code modules a code module which complies with the specific calling convention to execute the function call.

### Claim 2 (depends on 1)

The method according to claim 1, wherein obtaining a plurality of candidate code modules comprises, in response to the called function being a function from an external function library, obtaining the plurality of candidate code modules.

### Claim 3 (depends on 1)

The method according to claim 1, wherein at least one of the plurality of candidate code modules comprises: a prologue for performing the preparatory work before the function call; a main body for executing the function call; and an epilogue for performing clean up after the function call.

### Claim 4 (depends on 1)

The method according to claim 1, wherein obtaining the specific calling convention used by a called function comprises, querying load information of the called function in the program runtime to determine the specific calling convention.

### Claim 5 (depends on 4)

The method according to claim 4, wherein querying load information of the called function in the program runtime to determine the specific calling convention comprises:
issuing a query request to the program runtime, which includes identification information of the called function;
in response to the query request, obtaining a decorated name of the called function; and
determining the specific calling convention corresponding to the called function based on the decorated name.

### Claim 6 (depends on 5)

The method according to claim 5, wherein obtaining a decorated name of the called function comprises:
performing name demangling based on the identification information of the called function to obtain an original function name; and
obtaining the decorated name of the called function in the function library based on the original function name.

### Claim 7 (depends on 4)

The method according to claim 4, wherein obtaining the specific calling convention further comprises recording the determined specific calling convention, in order to directly obtain the specific calling convention when the called function is called again.

### Claim 8 (depends on 7)

The method according to claim 7, wherein recording the determined specific calling convention comprises: recording an index corresponding to the specific calling convention, and modifying a first address, which points to a code segment for querying the load information, to a second address, which points to a code module corresponding to the index of the specific calling convention among the plurality of code modules.

### Claim 9

An apparatus for function calling, comprising:
a code module obtaining unit configured to, in response to detection of a function call in a program, obtain a plurality of candidate code modules for executing the function call, the plurality of candidate code modules complying with a plurality of calling conventions respectively;
a calling convention obtaining unit configured to obtain a specific calling convention used by a called function; and
a code module selection unit configured to, according to the specific calling convention obtained, select from the plurality of candidate code modules a code module which complies with the specific calling convention to execute the function call.

### Claim 10 (depends on 9)

The apparatus according to claim 9, wherein the code module obtaining unit is configured to, in response to the called function being a function from an external function library, obtain the plurality of candidate code modules.

### Claim 11 (depends on 9)

The apparatus according to claim 9, wherein at least one of the plurality of candidate code modules comprises: a prologue for performing the preparatory work before the function call; a main body for executing the function call; and an epilogue for performing clean up after the function call.

### Claim 12 (depends on 9)

The apparatus according to claim 9, wherein the calling convention obtaining unit comprises a calling convention determination sub-unit configured to determine the specific calling convention by querying load information of the called function in the program runtime.

### Claim 13 (depends on 12)

The apparatus according to claim 12, wherein the calling convention determination sub-unit is configured to:
issue a query request to the program runtime, which includes identification information of the called function;
in response to the query request, obtain a decorated name of the called function; and
determine the specific calling convention corresponding to the called function based on the decorated name.

### Claim 14 (depends on 13)

The apparatus according to claim 13, wherein the calling convention determination sub-unit is configured to:
perform name demangling based on the identification information of the called function to obtain an original function name; and
obtain the decorated name of the called function in the function library based on the original function name.

### Claim 15 (depends on 12)

The apparatus according to claim 12, wherein the calling convention obtaining unit further comprises a recording sub-unit configured to record the determined specific calling convention, in order to directly obtain the specific calling convention when the called function is called again.

### Claim 16 (depends on 15)

The apparatus according to claim 15, wherein the recording sub-unit is configured to record an index corresponding to the specific calling convention, and modify a first address, which points to a code segment for querying the load information, to a second address, which points to code module corresponding to the index of the specific calling convention among the plurality of code modules.

### Claim 17

A computer program product for calling functions, the computer program product comprising a computer readable storage medium having program code embodied therewith, the program code executable by a computer to perform a method comprising:
in response to detection of a function call in a program, obtaining a plurality of candidate code modules for executing the function call, the plurality of candidate code modules complying with a plurality of calling conventions respectively;
obtaining a specific calling convention used by a called function;
according to the specific calling convention obtained, selecting from the plurality of candidate code modules a code module which complies with the specific calling convention to execute the function call.

### Claim 18 (depends on 17)

The computer program product according to claim 17, wherein obtaining a plurality of candidate code modules comprises, in response to the called function being a function from an external function library, obtaining the plurality of candidate code modules.

### Claim 19 (depends on 17)

The computer program product according to claim 17, wherein at least one of the plurality of candidate code modules comprises: a prologue for performing the preparatory work before the function call; a main body for executing the function call; and an epilogue for performing clean up after the function call.

### Claim 20 (depends on 17)

The computer program product according to claim 17, wherein obtaining the specific calling convention used by a called function comprises, querying load information of the called function in the program runtime to determine the specific calling convention.
