Copyright (C) 2000-2012 |
Whole document tree
3.1.1 Read-only dataRead-only data, such as string literals and other constant data, are put into code sections rather than the global data section. This saves global data space, which is in short supply, and is valid since the data, just like the code resources that contain them, are read-only. When an item of read-only data has file or global scope, it will be placed in the main code section. When it is local to a function, it will mostly, but not always, be placed in the same code section as that function. GCC's optimizer will usually notice when a string literal (or other constant) is identical to one which has been previously emitted, and will reuse the storage previously emitted rather than reserving more space for a duplicate.
Thus, in the following example, when optimisation is on, the string literal
referenced from
The code emitted for such a reference is similar to that emitted for an inter-section function call: when there is a data reference in which the referring function and the referenced item of read-only data are in different sections, the code emitted uses the item's code resource's pointer, which is located in the application's global data. This means that you must ensure that this sort of reference doesn't occur when globals are not available. Because this compiler optimisation (of course) occurs only within a single compilation unit, a sufficient (but not necessary) way to ensure this is by placing functions which are in different sections in different compilation units (e.g., in separate `.c' files).
In particular, all read-only data referenced while processing a launch code
that doesn't give you globals must be in the main code section. (Thus, in
the example above, This can be arranged in the following ways, amongst others:
This document was generated by root on January, 30 2002 using texi2html |