Sections and Segments (OS/2, Windows)

When a module is built, code and data are separated into sections and segments. These 2 terms have been used interchangeably and alternatively over the years with slightly different meanings.

Sections are created at compile time to contain specific types of elements. You can use the default section names, or rename the sections using the following code generation options:

option name section contains default section name
gen(codeSeg, name) generated code and initialized text CODE32
gen(constSeg, name) constants CONST32_RO
gen(dataSeg, name) data DATA32
gen(ehCodeSeg, name) C++ exception handling code EH_CODE
gen(ehDataSeg, name) C++ exception handling data EH_DATA
gen(uninitSeg, name) uninitialized data BSS32
gen(vftSeg, name) virtual function table __VFT

You can create additional sections with #pragma alloc_text or #pragma data_seg in your code.

The sections are assigned attributes at link time. The most common attributes are read, write, execute and shared. Again, you can accept defaults, or override them with the following link options:

option name type of section default attributes
link(code, attributes) code read and execute
link(data, attributes) data read and write
link(section, name, attributes) N/A N/A

For example, the following line specifies that the section named dseg1 is read-only and shared:

link(section, dseg1, "RS")

The linker orders sections by type and attributes. Generally it groups sections into segments to make efficient use of storage.

Segments appear in a link map. To generate a map build with link(map). You can use the map as an aid to debugging.



Incremental C++ Builds
C Compilation
Debugging with VisualAge C++


Set Build Options
Build


Section Attributes
Code Generation Options
Link Options