+// Layout an input .eh_frame section.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_file<size, big_endian>::layout_eh_frame_section(
+ Layout* layout,
+ const unsigned char* symbols_data,
+ section_size_type symbols_size,
+ const unsigned char* symbol_names_data,
+ section_size_type symbol_names_size,
+ unsigned int shndx,
+ const typename This::Shdr& shdr,
+ unsigned int reloc_shndx,
+ unsigned int reloc_type)
+{
+ gold_assert(this->has_eh_frame_);
+
+ off_t offset;
+ Output_section* os = layout->layout_eh_frame(this,
+ symbols_data,
+ symbols_size,
+ symbol_names_data,
+ symbol_names_size,
+ shndx,
+ shdr,
+ reloc_shndx,
+ reloc_type,
+ &offset);
+ this->output_sections()[shndx] = os;
+ if (os == NULL || offset == -1)
+ this->section_offsets()[shndx] = invalid_address;
+ else
+ this->section_offsets()[shndx] = convert_types<Address, off_t>(offset);
+
+ // If this section requires special handling, and if there are
+ // relocs that aply to it, then we must do the special handling
+ // before we apply the relocs.
+ if (os != NULL && offset == -1 && reloc_shndx != 0)
+ this->set_relocs_must_follow_section_writes();
+}
+
+// Layout an input .note.gnu.property section.
+
+// This note section has an *extremely* non-standard layout.
+// The gABI spec says that ELF-64 files should have 8-byte fields and
+// 8-byte alignment in the note section, but the Gnu tools generally
+// use 4-byte fields and 4-byte alignment (see the comment for
+// Layout::create_note). This section uses 4-byte fields (i.e.,
+// namesz, descsz, and type are always 4 bytes), the name field is
+// padded to a multiple of 4 bytes, but the desc field is padded
+// to a multiple of 4 or 8 bytes, depending on the ELF class.
+// The individual properties within the desc field always use
+// 4-byte pr_type and pr_datasz fields, but pr_data is padded to
+// a multiple of 4 or 8 bytes, depending on the ELF class.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_file<size, big_endian>::layout_gnu_property_section(
+ Layout* layout,
+ unsigned int shndx)
+{
+ section_size_type contents_len;
+ const unsigned char* pcontents = this->section_contents(shndx,
+ &contents_len,
+ false);
+ const unsigned char* pcontents_end = pcontents + contents_len;
+
+ // Loop over all the notes in this section.
+ while (pcontents < pcontents_end)
+ {
+ if (pcontents + 16 > pcontents_end)
+ {
+ gold_warning(_("%s: corrupt .note.gnu.property section "
+ "(note too short)"),
+ this->name().c_str());
+ return;
+ }
+
+ size_t namesz = elfcpp::Swap<32, big_endian>::readval(pcontents);
+ size_t descsz = elfcpp::Swap<32, big_endian>::readval(pcontents + 4);
+ unsigned int ntype = elfcpp::Swap<32, big_endian>::readval(pcontents + 8);
+ const unsigned char* pname = pcontents + 12;
+
+ if (namesz != 4 || strcmp(reinterpret_cast<const char*>(pname), "GNU") != 0)
+ {
+ gold_warning(_("%s: corrupt .note.gnu.property section "
+ "(name is not 'GNU')"),
+ this->name().c_str());
+ return;
+ }
+
+ if (ntype != elfcpp::NT_GNU_PROPERTY_TYPE_0)
+ {
+ gold_warning(_("%s: unsupported note type %d "
+ "in .note.gnu.property section"),
+ this->name().c_str(), ntype);
+ return;
+ }
+
+ size_t aligned_namesz = align_address(namesz, 4);
+ const unsigned char* pdesc = pname + aligned_namesz;
+
+ if (pdesc + descsz > pcontents + contents_len)
+ {
+ gold_warning(_("%s: corrupt .note.gnu.property section"),
+ this->name().c_str());
+ return;
+ }
+
+ const unsigned char* pprop = pdesc;
+
+ // Loop over the program properties in this note.
+ while (pprop < pdesc + descsz)
+ {
+ if (pprop + 8 > pdesc + descsz)
+ {
+ gold_warning(_("%s: corrupt .note.gnu.property section"),
+ this->name().c_str());
+ return;
+ }
+ unsigned int pr_type = elfcpp::Swap<32, big_endian>::readval(pprop);
+ size_t pr_datasz = elfcpp::Swap<32, big_endian>::readval(pprop + 4);
+ pprop += 8;
+ if (pprop + pr_datasz > pdesc + descsz)
+ {
+ gold_warning(_("%s: corrupt .note.gnu.property section"),
+ this->name().c_str());
+ return;
+ }
+ layout->layout_gnu_property(ntype, pr_type, pr_datasz, pprop, this);
+ pprop += align_address(pr_datasz, size / 8);
+ }
+
+ pcontents = pdesc + align_address(descsz, size / 8);
+ }
+}
+
+// This a copy of lto_section defined in GCC (lto-streamer.h)
+
+struct lto_section
+{
+ int16_t major_version;
+ int16_t minor_version;
+ unsigned char slim_object;
+
+ /* Flags is a private field that is not defined publicly. */
+ uint16_t flags;
+};
+