Init and Fini sections

References:

Dynamic object can supply code that provides for runtime initialization and termination processing. The initialization code of a dynamic object is executed once each time the dynamic object is loaded in a process. The termination code of a dynamic object is executed once each time the dynamic object is unloaded from a process or at process termination. This code can be encapsulated in one of two section types, either an array of function pointers or a single code block. Each of these section types is built from a concatenation of like sections from the input relocatable objects.

  • .pre_initarray, pre-initialization functions. Applicable to dynamic executables only.
  • .init_array, initialization functions
  • .fini_array, termination functions

When creating a dynamic object, the linker-editor identifies these arrays with the .dynamic tag pairs DT_PREINIT_[ARRAY/ARRAYSZ], DT_INIT_[ARRAY/ARRAYSZ], and DT_FINI_[ARRAY/ARRAYSZ] accordingly. These tags identify the associated sections so that the sections can be called by the runtime linker.

Functions that are assigned to these arrays must be provided from the object that is being built.

  • .init, runtime initialization code block.
  • .fini, runtime termination code block.

The compiler drivers typically supply .init and .fini sections with files they add to the beginning and end of your input file list. These compiler provided files have the effect of encapsulating the .init and .fini code from your relocatable objects into individual functions. These functions are identified by the reserved symbol names _init and _fini respectively.

When creating a dynamic object, the link-editor identifies these symbols with the .dynamic tags DT_INIT and DT_FINI accordingly. These tags identify the associated sections so they can be called by the runtime linker.

More

Created Aug 9, 2020 // Last Updated Aug 10, 2020

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?