// elfcpp_file.h -- file access for elfcpp -*- C++ -*-
-// Copyright 2006, 2007, Free Software Foundation, Inc.
+// Copyright (C) 2006-2015 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of elfcpp.
return this->shnum_;
}
+ unsigned int
+ shnum() const
+ {
+ if (this->shnum_ == 0 && this->shoff_ != 0)
+ this->file_->error(_("ELF file has not been initialized yet"
+ " (internal error)"));
+ return this->shnum_;
+ }
+
// Return the section index of the section name string table.
unsigned int
shstrndx()
return this->shstrndx_;
}
+ unsigned int
+ shstrndx() const
+ {
+ if (this->shstrndx_ == SHN_XINDEX && this->shoff_ != 0)
+ {
+ this->file_->error(_("ELF file has not been initialized yet"
+ " (internal error)"));
+ return 0;
+ }
+ return this->shstrndx_;
+ }
+
// Return the value to subtract from section indexes >=
// SHN_LORESERVE. See the comment in initialize_shnum.
int
return this->large_shndx_offset_;
}
+ int
+ large_shndx_offset() const
+ {
+ if (this->shstrndx_ == SHN_XINDEX && this->shoff_ != 0)
+ this->file_->error(_("ELF file has not been initialized yet"
+ " (internal error)"));
+ return this->large_shndx_offset_;
+ }
+
// Return the location of the header of section SHNDX.
typename File::Location
section_header(unsigned int shndx)
// Return the name of section SHNDX.
std::string
- section_name(unsigned int shndx);
+ section_name(unsigned int shndx) const;
// Return the location of the contents of section SHNDX.
typename File::Location
// Return the file offset of the header of section SHNDX.
off_t
- section_header_offset(unsigned int shndx);
+ section_header_offset(unsigned int shndx) const;
// The file we are reading.
File* file_;
unsigned int
Elf_file<size, big_endian, File>::find_section_by_type(unsigned int type)
{
- unsigned int tshnum = this->shnum();
+ unsigned int shnum = this->shnum();
typename File::View v(this->file_->view(this->shoff_,
- This::shdr_size * tshnum));
- for (unsigned int i = 0; i < tshnum; i++)
+ This::shdr_size * shnum));
+ for (unsigned int i = 0; i < shnum; i++)
{
Ef_shdr shdr(v.data() + This::shdr_size * i);
if (shdr.get_sh_type() == type)
template<int size, bool big_endian, typename File>
off_t
-Elf_file<size, big_endian, File>::section_header_offset(unsigned int shndx)
+Elf_file<size, big_endian, File>::section_header_offset(unsigned int shndx) const
{
if (shndx >= this->shnum())
this->file_->error(_("section_header_offset: bad shndx %u >= %u"),
template<int size, bool big_endian, typename File>
std::string
-Elf_file<size, big_endian, File>::section_name(unsigned int shndx)
+Elf_file<size, big_endian, File>::section_name(unsigned int shndx) const
{
File* const file = this->file_;
off_t shstr_off;
typename Elf_types<size>::Elf_WXword shstr_size;
{
- const unsigned int fshstrndx = this->shstrndx_;
- typename File::View v(file->view(this->section_header_offset(fshstrndx),
+ const unsigned int shstrndx = this->shstrndx_;
+ typename File::View v(file->view(this->section_header_offset(shstrndx),
This::shdr_size));
Ef_shdr shstr_shdr(v.data());
shstr_off = shstr_shdr.get_sh_offset();