+ Section& section = this->sections_[shndx - 1];
+
+ section_offset_type section_offset;
+
+ if (section_id == elfcpp::DW_SECT_INFO)
+ {
+ // Write the .debug_info.dwo section directly.
+ // We do not need to free the memory in this case.
+ off_t file_offset = this->next_file_offset_;
+ gold_assert(this->size_ > 0 && file_offset > 0);
+
+ file_offset = align_offset(file_offset, align);
+ if (section.offset == 0)
+ section.offset = file_offset;
+
+ if (align > section.align)
+ {
+ // Since we've already committed to the layout for this
+ // section, an unexpected large alignment boundary may
+ // be impossible to honor.
+ if (align_offset(section.offset, align) != section.offset)
+ gold_fatal(_("%s: alignment (%d) for section '%s' "
+ "cannot be honored"),
+ this->name_, align, section_name);
+ section.align = align;
+ }
+
+ section_offset = file_offset - section.offset;
+ section.size = file_offset + len - section.offset;
+
+ ::fseek(this->fd_, file_offset, SEEK_SET);
+ if (::fwrite(contents, 1, len, this->fd_) < len)
+ gold_fatal(_("%s: error writing section '%s'"), this->name_,
+ section_name);
+ this->next_file_offset_ = file_offset + len;
+ }
+ else
+ {
+ // Collect the contributions and keep track of the total size.
+ if (align > section.align)
+ section.align = align;
+ section_offset = align_offset(section.size, align);
+ section.size = section_offset + len;
+ Contribution contrib = { section_offset, len, contents };
+ section.contributions.push_back(contrib);
+ }
+
+ return section_offset;