Marking variables as local or imported

The compiler assumes that all variables in applications are imported, but the use of -qdatalocal and -qdataimported can mark variables local or imported. The compiler optimizes applications that are based on the specification of static or dynamic binding for program variables.

-qdatalocal

Local variables are stored in a special segment of memory that is uniquely bound to a program or shared library. Specify the -qdatalocal option to identify variables to be treated as local to a compiled program or shared library. You can specify the option with no parameters to indicate that all appropriate variables are local. Alternatively, you can append a list of colon-separated names to the option to treat only a subset of the program arguments as local.

When it can be, a variable that is marked as local is embedded directly into a structure that is called the table of contents (TOC) instead of in a separate global piece of memory. The prerequisite is that the variable's storage must be no more than the pointer size for it to be embedded in the TOC. Usually, pointers to data are stored in the TOC. The -qdatalocal option allows storage of data directly in the TOC, hence reducing data accesses from two load instructions to one load instruction.

-qdataimported

Imported variables are stored according to the default memory allocation scheme. The -qdataimported option is the default data binding mechanism. Specifying the option implies that the data is visible to other program or shared library that is linked. As a result, specifying variable names as arguments to the -qdataimported option or compiling with the -qdataimported option without arguments in isolation has no effect.

The -qdataimported option is useful when you use it in combination with -qdatalocal. Because it is unlikely that you want to store all data in the TOC, the -qdataimported option can override -qdatalocal for variables external to a program or shared library. For example, the use of options -qdatalocal -qdataimported=<variable> stores all global data in the TOC except for <variable>.



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us