+ elfcpp::Elf_Xword flags = this->flags();
+ if (compress == gabi_zlib)
+ {
+ // Set the SHF_COMPRESSED bit.
+ flags |= elfcpp::SHF_COMPRESSED;
+ const bool is_big_endian = parameters->target().is_big_endian();
+ uint64_t addralign = this->addralign();
+ if (size == 32)
+ {
+ if (is_big_endian)
+ {
+ elfcpp::Chdr_write<32, true> chdr(this->data_);
+ chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB);
+ chdr.put_ch_size(uncompressed_size);
+ chdr.put_ch_addralign(addralign);
+ }
+ else
+ {
+ elfcpp::Chdr_write<32, false> chdr(this->data_);
+ chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB);
+ chdr.put_ch_size(uncompressed_size);
+ chdr.put_ch_addralign(addralign);
+ }
+ }
+ else if (size == 64)
+ {
+ if (is_big_endian)
+ {
+ elfcpp::Chdr_write<64, true> chdr(this->data_);
+ chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB);
+ chdr.put_ch_size(uncompressed_size);
+ chdr.put_ch_addralign(addralign);
+ }
+ else
+ {
+ elfcpp::Chdr_write<64, false> chdr(this->data_);
+ chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB);
+ chdr.put_ch_size(uncompressed_size);
+ chdr.put_ch_addralign(addralign);
+ }
+ }
+ else
+ gold_unreachable();
+ }
+ else
+ {
+ // Write out the zlib header.
+ memcpy(this->data_, "ZLIB", 4);
+ elfcpp::Swap_unaligned<64, true>::writeval(this->data_ + 4,
+ uncompressed_size);
+ // This converts .debug_foo to .zdebug_foo
+ this->new_section_name_ = std::string(".z") + (this->name() + 1);
+ this->set_name(this->new_section_name_.c_str());
+ }
+ this->set_flags(flags);