+
+ // second pass, assign section addresses to sections in segments that are ordered after a segment with a fixed address
+ if ( haveFixedSegments && !_options.segmentOrder().empty() ) {
+ if ( log ) fprintf(stderr, "After Fixed address segments:\n");
+ lastSegName = "";
+ ld::Internal::FinalSection* lastSect = NULL;
+ for (std::vector<ld::Internal::FinalSection*>::iterator it = sections.begin(); it != sections.end(); ++it) {
+ ld::Internal::FinalSection* sect = *it;
+ if ( (sect->address == ULLONG_MAX) && _options.segmentOrderAfterFixedAddressSegment(sect->segmentName()) ) {
+ address = lastSect->address + lastSect->size;
+ if ( (strcmp(lastSegName, sect->segmentName()) != 0) && segmentsArePageAligned ) {
+ // round up size of last segment
+ address = pageAlign(address, _options.segPageSize(lastSegName));
+ }
+ // adjust section address based on alignment
+ uint64_t unalignedAddress = address;
+ uint64_t alignment = (1 << sect->alignment);
+ address = ( (unalignedAddress+alignment-1) & (-alignment) );
+ sect->alignmentPaddingBytes = (address - unalignedAddress);
+ sect->address = address;
+ if ( log ) fprintf(stderr, " address=0x%08llX, hidden=%d, alignment=%02d, section=%s,%s\n",
+ sect->address, sect->isSectionHidden(), sect->alignment, sect->segmentName(), sect->sectionName());
+ // update running totals
+ if ( !sect->isSectionHidden() || hiddenSectionsOccupyAddressSpace )
+ address += sect->size;
+ }
+ lastSegName = sect->segmentName();
+ lastSect = sect;
+ }
+ }
+
+ // last pass, assign addresses to remaining sections