HP 3000 Manuals

Linking for Shared Global Data [ Technical Addendum for HP Link Editor/iX ] MPE/iX 5.5 Documentation


Technical Addendum for HP Link Editor/iX

Linking for Shared Global Data 

To link a program file for shared global data, it is not necessary to
specify RL files at link time if you want any unresolved data references
to be satisfied at load time by an XL. The default behavior remains
linking for non-shared data.  To link for shared data, you must use the
new SHARE option.  The loader automatically searches XL.PUB.SYS at
run-time if you did not specify it at link time.  You can override an XL
specified at link time by specifying the XL at run time using the XL=
option in the RUN command.

SHARE Option 

The SHARE option instructs the Link Editor to link for shared data.
Linking for shared data means all non-hidden Data Universals and Storage
Universals are exported, and all Data Unsats and Storage Universals are
imported.  If you want to selectively export Data Universals and Storage
Universals, you can take the definitions out of the source code of the
program file or library and add the objects to an RL. Use the HIDERL
command to hide the definitions and add the resulting RL to an XL. At
link time, specify the XL on the link line so the loader will know it
needs to search that XL first.  The data symbols you want hidden are not
exportable from the XL or program file.

Example 

     LINK FROM=^indirect_file;SHARE;XL=MYXL;TO=MYOUT;RL=LIBCSHR.LIB.SYS

The object files in indirect_file and the RL LIBCSHR are linked to form
an executable program file called MYOUT. At run time, the loader loads
the XL MYXL followed by XL.PUB.SYS and attempts to satisfy unresolved
data references in MYOUT with data exports in MYXL and XL.PUB.SYS. The
loader issues an error message if it cannot resolve a data reference.


NOTE If you are using C and want to link for shared global data, you must link with LIBCSHR (see "New LIBC/iX Library," following). If you do not want to link for shared global data you can continue to link with LIBCINIT.
New LIBC/iX Library A new C library, libcshr.lib.sys, takes advantage of the Shared Global feature. This library allows you to link your program with other executable libraries (XLs) in addition to xl.pub.sys. You can use it in the same way you use other libc libraries, but you must have the new share keyword. For example: link from=myobj;to=myprog;rl=libcansi.lib.sys,libcshr.lib.sys;share This links an ANSI-conforming application myobj into a program file myprog with all libc functions and global variables resolved in xl.pub.sys.
NOTE The keyword share must be specified since the default linking mode is not shared.
Linking shared programs results in a much smaller application and allows you to take advantage of any new system releases without having to relink. Existing programs and scripts that use libc.lib.sys and libcinit.lib.sys continue to work unchanged. However, libcshr.lib.sys is the recommended library to use. The scripts ccxllk.pub.sys and ccxlgo.pub.sys link with libcshr. Linking a C Application with C Libraries. There are three suggested methods for linking a C application and libraries: 1. Archive Linking - Link with LIBC which is nonsharable. All libc functions are completely integrated into the application. link from=cobj;to=cprog;rl=libcansi.lib.sys,libcinit.lib.sys 2. Semi-Shared Linking - Link with LIBCINIT which is designed to reinitialize the XL.PUB.SYS global pointers and redirect them to the program's globals at process startup. Most of the libc functions are in XL.PUB.SYS and are shared partly by the application. link from=cobj;to=cprog;rl=libcansi.lib.sys,libc.lib.sys 3. Shared Linking - Link with LIBCSHR, which is completely sharable. All the libc functions are in XL.PUB.SYS. They are shared by the application's linked executable libraries. It is the recommended method for sharing global data. link from= cobj;to=cprog;rl=libcansi.lib.sys,libcshr.lib.sys;share Guidelines for the Linkage Method. * Use non-shared linkage for self-contained and highly portable applications. This is the traditional linkage method. * Use semi-shared linkage for applications that want partial sharing but maintain a high degree of compatibility. This is the current shared linkage method. * Use shared linkage for applications that want maximum sharing without any of the semi-shared linkage restrictions or workarounds. This is the new, true shared linkage method. POSIX Links All POSIX links using c89 or /lib/libc.a/ are linked for shared code and data. Hiding Data Symbols You are now able to hide data symbols as well as code symbols in RLs. The HIDERL command sets a bit called the hidden bit for each symbol marked as hidden in an RL. When the RL is added to an XL or program file, the Link Editor does not build LST export records for these symbols. The symbols are not visible or accessible to modules in the same XL, other XLs, or program files. There are two options to the HIDERL command to support hiding data symbols: ALL_DATA Specifies that all Data Universals and Storage Requests are marked as hidden in the RL. The hidden bit is set in the symbol dictionary for these symbols. DATA=data_item Specifies that data_item is marked as hidden in the RL. Note that data_item is case-sensitive and must be a Data Universal or Storage Request. As with code symbols, the hiding takes place when the RL is added to the XL or program. Therefore, if you link with an RL that has hidden symbols, those hidden symbols are still exportable to the program file and can satisfy imports in the program file. When the RL is added to an XL or program file, no LST import or export record is generated in the XL's LST area for the hidden symbols. The hidden symbols are therefore not sharable with other modules. Like Code Unsats, Data Unsats cannot be hidden even though the hidden bit is set. Duplicate data symbols are allowed in RLs. When hiding data or storage symbols, the Link Editor hides each occurrence of the symbol. For example, if there are five data or storage symbols called foo, all five are marked as hidden. Using HIDERL to hide data symbols is the recommended way to keep data symbols internal (that is, not externally visible) to the load module. Example HIDERL RL=MYRL;DATA=foo HIDERL RL=MYRL2;ALL_DATA ADDXL FROM=MYRL;TO=MYXL ADDXL FROM=MYRL2;TO=MYXLA2 MYXL does not export foo because it is marked as hidden. foo is not visible to any other module in MYXL, other XLs, or program files. MYXLA2 does not export any data symbols because all data symbols are marked as hidden. Linking With Hidden Data Symbols Because data in RLs can be hidden, when linking or doing an ADDXL;MERGE with modules that have hidden data symbols, if a hidden data symbol is processed, all occurrences of that symbol must also be marked as hidden. If one of the occurrences is not marked as hidden, the Link Editor emits a warning message and marks the symbol as hidden. Refer to "Diagnostic Messages" for the warning message. Revealing Data Symbols You are now able to reveal, or unhide, data symbols as well as code symbols in RLs. The REVEALRL command unsets the hidden bit for each symbol specified. When the RL is added to an XL, the Link Editor exports all unhidden symbols. The symbols become visible and accessible to the same XL, other XLs, and program files. There are two new options to the REVEALRL command to support unhiding data symbols: ALL_DATA Specifies that all Data Universals and Storage Requests are marked as unhidden in the RL. The hidden bit, if set, is unset for these symbols. DATA=data_item Specifies that data_item is marked as unhidden in the RL. Note that data_item is case-sensitive and must be a Data Universal or Storage Request. As with code symbols, the revealing takes place when the RL is added to the XL or program file. When this happens, the symbols become sharable with other modules. Duplicate data symbols are allowed in RLs. When revealing data or storage symbols, the Link Editor reveals each occurrence of the symbol. For example, if there are five data or storage symbols called foo, all five are revealed. Example REVEALRL RL=MYRL;DATA=foo REVEALRL RL=MYRL2;ALL_DATA ADDXL FROM=MYRL;TO=MYXL ADDXL FROM=MYRL2;TO=MYXL2 MYXL exports foo because it is revealed, or unhidden. Modules in MYXL, as well as in other XLs or program files, can access foo. MYXL2 exports all data symbols. Modules in MYXL2, as well as other XLs or program files, can access those data symbols.


MPE/iX 5.5 Documentation