Removing Unused Sections

An ELF section, from an input relocatable object file, is determined to be unused when three conditions are true.

  • The section provides no global symbols.

  • The section contributes to an allocatable segment.

  • The section is not referenced by any other used section, from any object, that contributes to the link-edit.

Unused sections can be discarded from the link-edit by using the -z discard-unused=sections option.

You can improve the link-editor's ability to diagnose and discard unused sections by defining the dynamic object's external interfaces. See Interfaces and Versioning. By defining an interface, global symbols that are not defined as part of the interface are reduced to locals. Reduced symbols that are unreferenced from other objects, are then clearly identified as candidates for discarding.

Individual functions and data variables can be discarded by the link-editor if these items are assigned to their own sections. This section refinement can be achieved by using the -xF compiler option.