+ /* If this is the first subspace in the space, and we are
+ building an executable, then take care to make sure all
+ the alignments are correct and update the exec header. */
+ if (first_subspace
+ && (abfd->flags & EXEC_P))
+ {
+ /* Demand paged executables have each space aligned to a
+ page boundary. Sharable executables (write-protected
+ text) have just the private (aka data & bss) space aligned
+ to a page boundary. Ugh. Not true for HPUX.
+
+ The HPUX kernel requires the text to always be page aligned
+ within the file regardless of the executable's type. */
+ if (abfd->flags & D_PAGED
+ || (subsection->flags & SEC_CODE)
+ || ((abfd->flags & WP_TEXT)
+ && (subsection->flags & SEC_DATA)))
+ current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
+
+ /* Update the exec header. */
+ if (subsection->flags & SEC_CODE && exec_header.exec_tfile == 0)
+ {
+ exec_header.exec_tmem = section->vma;
+ exec_header.exec_tfile = current_offset;
+ }
+ if (subsection->flags & SEC_DATA && exec_header.exec_dfile == 0)
+ {
+ exec_header.exec_dmem = section->vma;
+ exec_header.exec_dfile = current_offset;
+ }
+
+ /* Keep track of exactly where we are within a particular
+ space. This is necessary as the braindamaged HPUX
+ loader will create holes between subspaces *and*
+ subspace alignments are *NOT* preserved. What a crock. */
+ subspace_offset = subsection->vma;
+
+ /* Only do this for the first subspace within each space. */
+ first_subspace = 0;
+ }
+ else if (abfd->flags & EXEC_P)
+ {
+ /* The braindamaged HPUX loader may have created a hole
+ between two subspaces. It is *not* sufficient to use
+ the alignment specifications within the subspaces to
+ account for these holes -- I've run into at least one
+ case where the loader left one code subspace unaligned
+ in a final executable.
+
+ To combat this we keep a current offset within each space,
+ and use the subspace vma fields to detect and preserve
+ holes. What a crock!
+
+ ps. This is not necessary for unloadable space/subspaces. */
+ current_offset += subsection->vma - subspace_offset;
+ if (subsection->flags & SEC_CODE)
+ exec_header.exec_tsize += subsection->vma - subspace_offset;
+ else
+ exec_header.exec_dsize += subsection->vma - subspace_offset;
+ subspace_offset += subsection->vma - subspace_offset;
+ }
+
+
+ subsection->target_index = total_subspaces++;