+
+ // Get views into the output file for the portions of the symbol table
+ // and the dynamic symbol table that we will be writing.
+ off_t symtab_off = layout->symtab_section()->offset();
+ off_t output_size = this->local_symbol_count_ * This::sym_size;
+ unsigned char* oview = NULL;
+ if (output_size > 0)
+ oview = of->get_output_view(symtab_off + this->local_symbol_offset_,
+ output_size);
+
+ off_t dyn_output_size = this->output_local_dynsym_count_ * sym_size;
+ unsigned char* dyn_oview = NULL;
+ if (dyn_output_size > 0)
+ dyn_oview = of->get_output_view(this->local_dynsym_offset_,
+ dyn_output_size);
+
+ // Write the local symbols.
+ unsigned char* ov = oview;
+ unsigned char* dyn_ov = dyn_oview;
+ const Stringpool* sympool = layout->sympool();
+ const Stringpool* dynpool = layout->dynpool();
+ Output_symtab_xindex* symtab_xindex = layout->symtab_xindex();
+ Output_symtab_xindex* dynsym_xindex = layout->dynsym_xindex();
+ for (unsigned int i = 0; i < this->local_symbol_count_; ++i)
+ {
+ Local_symbol& lsym(this->local_symbols_[i]);
+
+ bool is_ordinary;
+ unsigned int st_shndx = this->adjust_sym_shndx(i, lsym.st_shndx,
+ &is_ordinary);
+ if (is_ordinary)
+ {
+ Output_section* os = this->ibase_->output_section(st_shndx);
+ st_shndx = os->out_shndx();
+ if (st_shndx >= elfcpp::SHN_LORESERVE)
+ {
+ symtab_xindex->add(this->local_symbol_index_ + i, st_shndx);
+ if (lsym.needs_dynsym_entry)
+ dynsym_xindex->add(lsym.output_dynsym_index, st_shndx);
+ st_shndx = elfcpp::SHN_XINDEX;
+ }
+ }
+
+ // Write the symbol to the output symbol table.
+ {
+ elfcpp::Sym_write<size, big_endian> osym(ov);
+ osym.put_st_name(sympool->get_offset(lsym.name));
+ osym.put_st_value(lsym.st_value);
+ osym.put_st_size(lsym.st_size);
+ osym.put_st_info(elfcpp::STB_LOCAL,
+ static_cast<elfcpp::STT>(lsym.st_type));
+ osym.put_st_other(0);
+ osym.put_st_shndx(st_shndx);
+ ov += sym_size;
+ }
+
+ // Write the symbol to the output dynamic symbol table.
+ if (lsym.needs_dynsym_entry)
+ {
+ gold_assert(dyn_ov < dyn_oview + dyn_output_size);
+ elfcpp::Sym_write<size, big_endian> osym(dyn_ov);
+ osym.put_st_name(dynpool->get_offset(lsym.name));
+ osym.put_st_value(lsym.st_value);
+ osym.put_st_size(lsym.st_size);
+ osym.put_st_info(elfcpp::STB_LOCAL,
+ static_cast<elfcpp::STT>(lsym.st_type));
+ osym.put_st_other(0);
+ osym.put_st_shndx(st_shndx);
+ dyn_ov += sym_size;
+ }
+ }
+
+ if (output_size > 0)
+ {
+ gold_assert(ov - oview == output_size);
+ of->write_output_view(symtab_off + this->local_symbol_offset_,
+ output_size, oview);
+ }
+
+ if (dyn_output_size > 0)
+ {
+ gold_assert(dyn_ov - dyn_oview == dyn_output_size);
+ of->write_output_view(this->local_dynsym_offset_, dyn_output_size,
+ dyn_oview);
+ }