Defining Tentative Symbols
A mapfile
can also be used to define a
COMMON
, or tentative, symbol.
Unlike other types of symbol definition, tentative symbols
do not occupy storage within a file, but define storage that
must be allocated at runtime. Therefore, symbol definitions
of this kind can contribute to the storage allocation of the
output file being generated.
A feature of tentative symbols that differs from
other symbol types is that their value
attribute indicates their alignment requirement. A
mapfile
definition can
therefore be used to realign tentative definitions that are
obtained from the input files of a link-edit.
The following example shows the definition of two tentative
symbols. The symbol foo
defines a new
storage region whereas the symbol bar
is
actually used to change the alignment of the same tentative
definition within the file
main.c
.
$ cat main.c #include <stdio.h> extern int foo; int bar[0x10]; void main() { (void) printf("&foo = 0x%p\n", &foo); (void) printf("&bar = 0x%p\n", &bar); } $ cat mapfile $mapfile_version 2 SYMBOL_SCOPE { global: foo { TYPE=COMMON; VALUE=0x4; SIZE=0x200 }; bar { TYPE=COMMON; VALUE=0x102; SIZE=0x40 }; }; $ cc -o prog -M mapfile main.c ld: warning: symbol 'bar' has differing alignments: (file mapfile value=0x102; file main.o value=0x4); largest value applied $ prog &foo = 0x21264 &bar = 0x21224 $ elfdump -sN.symtab prog | egrep 'foo$|bar$' [45] 0x21224 0x40 OBJT GLOB D 0 .bss bar [69] 0x21264 0x200 OBJT GLOB D 0 .bss foo
Note:
This symbol resolution diagnostic can be suppressed by using the link-editor's-t
option.