9 Using Mapfiles

This chapter describes with examples how to use the mapfile option.

“Controlling Mapfiles with the -k Option” (page 191)

“Changing Mapfiles with -k filename and +nodefaultmap” (page 191)

“Mapfile Example: Using -k mapfile and +nodefaultmap ” (page 191)

“Default HP-UX 11.0 Release Mapfile” (page 193)

“Defining Syntax for Mapfile Directives” (page 195)

“Defining Mapfile Segment Declarations” (page 196)

“Internal Map Structure” (page 198)

“Placement of Segments in an Executable” (page 198)

“Fatal Errors” (page 200)

NOTE: In most cases, the linker produces a correct executable without the use of the mapfile option. The mapfile option is an advanced feature of the linker toolset intended for system programming use, not for application programming use. When using the mapfile option, you can easily create executable files that do not execute.

Controlling Mapfiles with the -k Option

The -koption told specifies a text file containing mapfile directives:

ld -k mapfile [flags] files ...

The ld command automatically maps sections from input object files onto output segments in executable files. The mapfile option allows you to change the default mapping provided by the linker. Use the -kmapfile option to specify a text file that contains mapfile directives. The linker appends the specified mapfile to the default mapfile unless you specify the +nodefaultmap option.

Changing Mapfiles with -k filename and +nodefaultmap

The +nodefaultmap option used with -koption prevents the linker from concatenating the default memory map to the map provided by mapfile. If you specify +nodefaultmap, the linker does not append the default mapfile to your mapfile. If you do not specify +nodefaultmap with -k, the linker appends the default to the output file.

Mapfile Example: Using -k mapfile and +nodefaultmap

cat mapfile

text = LOAD ?RX V0x1000; text : .rodata;

text : .PARISC.milli;

text : .dynamic;

text : .dynsym;

text : .dynstr;

text : .hash;

text : $PROGBITS ?AX;

text : .PARISC.unwind;

text : $UNWIND;

data = LOAD ?RW V0x4000000040001000; data : .opd;

data : .plt;

data : .dlt;

Controlling Mapfiles with the -k Option 191