Commit 8383303e authored by Ian Lance Taylor's avatar Ian Lance Taylor
Browse files

Add section_size_type and section_offset_type, use them to replace a

lot of instances of off_t.
parent 3d372cd7
......@@ -84,7 +84,8 @@ Archive::setup(Task* task)
// The first member of the archive should be the symbol table.
std::string armap_name;
off_t armap_size = this->read_header(sarmag, &armap_name);
section_size_type armap_size =
convert_to_section_size_type(this->read_header(sarmag, &armap_name));
off_t off = sarmag;
if (armap_name.empty())
{
......@@ -115,7 +116,7 @@ Archive::setup(Task* task)
// Read the archive symbol map.
void
Archive::read_armap(off_t start, off_t size)
Archive::read_armap(off_t start, section_size_type size)
{
// Read in the entire armap.
const unsigned char* p = this->get_view(start, size, false);
......@@ -127,12 +128,13 @@ Archive::read_armap(off_t start, off_t size)
// Note that the addition is in units of sizeof(elfcpp::Elf_Word).
const char* pnames = reinterpret_cast<const char*>(pword + nsyms);
off_t names_size = reinterpret_cast<const char*>(p) + size - pnames;
section_size_type names_size =
reinterpret_cast<const char*>(p) + size - pnames;
this->armap_names_.assign(pnames, names_size);
this->armap_.resize(nsyms);
off_t name_offset = 0;
section_offset_type name_offset = 0;
for (unsigned int i = 0; i < nsyms; ++i)
{
this->armap_[i].name_offset = name_offset;
......@@ -141,7 +143,7 @@ Archive::read_armap(off_t start, off_t size)
++pword;
}
if (reinterpret_cast<const unsigned char*>(pnames) - p > size)
if (static_cast<section_size_type>(name_offset) > names_size)
gold_error(_("%s: bad archive symbol table names"),
this->name().c_str());
......
......@@ -110,12 +110,12 @@ class Archive
// Get a view into the underlying file.
const unsigned char*
get_view(off_t start, off_t size, bool cache)
get_view(off_t start, section_size_type size, bool cache)
{ return this->input_file_->file().get_view(start, size, cache); }
// Read the archive symbol map.
void
read_armap(off_t start, off_t size);
read_armap(off_t start, section_size_type size);
// Read an archive member header at OFF. Return the size of the
// member, and set *PNAME to the name.
......
......@@ -127,9 +127,9 @@ Sized_dwarf_line_info<size, big_endian>::Sized_dwarf_line_info(Object* object,
for (debug_shndx = 0; debug_shndx < object->shnum(); ++debug_shndx)
if (object->section_name(debug_shndx) == ".debug_line")
{
off_t buffer_size;
this->buffer_ = object->section_contents(
debug_shndx, &buffer_size, false);
section_size_type buffer_size;
this->buffer_ = object->section_contents(debug_shndx, &buffer_size,
false);
this->buffer_end_ = this->buffer_ + buffer_size;
break;
}
......
......@@ -172,7 +172,7 @@ class Sized_dwarf_line_info : public Dwarf_line_info
// This is used to figure out what section to apply a relocation to.
const unsigned char* symtab_buffer_;
off_t symtab_buffer_size_;
section_size_type symtab_buffer_size_;
// Holds the directories and files as we see them. We have an array
// of directory-lists, one for each .o file we're reading (usually
......
......@@ -162,7 +162,7 @@ Sized_dynobj<size, big_endian>::read_dynsym_section(
elfcpp::SHT type,
unsigned int link,
File_view** view,
off_t* view_size,
section_size_type* view_size,
unsigned int* view_info)
{
if (shndx == -1U)
......@@ -183,7 +183,7 @@ Sized_dynobj<size, big_endian>::read_dynsym_section(
*view = this->get_lasting_view(shdr.get_sh_offset(), shdr.get_sh_size(),
false);
*view_size = shdr.get_sh_size();
*view_size = convert_to_section_size_type(shdr.get_sh_size());
*view_info = shdr.get_sh_info();
}
......@@ -313,7 +313,8 @@ Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
sd->symbols = this->get_lasting_view(dynsymshdr.get_sh_offset(),
dynsymshdr.get_sh_size(), false);
sd->symbols_size = dynsymshdr.get_sh_size();
sd->symbols_size =
convert_to_section_size_type(dynsymshdr.get_sh_size());
// Get the symbol names.
strtab_shndx = dynsymshdr.get_sh_link();
......@@ -335,7 +336,8 @@ Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
sd->symbol_names = this->get_lasting_view(strtabshdr.get_sh_offset(),
strtabshdr.get_sh_size(),
true);
sd->symbol_names_size = strtabshdr.get_sh_size();
sd->symbol_names_size =
convert_to_section_size_type(strtabshdr.get_sh_size());
// Get the version information.
......@@ -444,10 +446,10 @@ Sized_dynobj<size, big_endian>::make_verdef_map(
return;
const char* names = reinterpret_cast<const char*>(sd->symbol_names->data());
off_t names_size = sd->symbol_names_size;
section_size_type names_size = sd->symbol_names_size;
const unsigned char* pverdef = sd->verdef->data();
off_t verdef_size = sd->verdef_size;
section_size_type verdef_size = sd->verdef_size;
const unsigned int count = sd->verdef_info;
const unsigned char* p = pverdef;
......@@ -519,10 +521,10 @@ Sized_dynobj<size, big_endian>::make_verneed_map(
return;
const char* names = reinterpret_cast<const char*>(sd->symbol_names->data());
off_t names_size = sd->symbol_names_size;
section_size_type names_size = sd->symbol_names_size;
const unsigned char* pverneed = sd->verneed->data();
const off_t verneed_size = sd->verneed_size;
const section_size_type verneed_size = sd->verneed_size;
const unsigned int count = sd->verneed_info;
const unsigned char* p = pverneed;
......@@ -621,7 +623,7 @@ Sized_dynobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
const int sym_size = This::sym_size;
const size_t symcount = sd->symbols_size / sym_size;
gold_assert(sd->external_symbols_offset == 0);
if (static_cast<off_t>(symcount * sym_size) != sd->symbols_size)
if (symcount * sym_size != sd->symbols_size)
{
this->error(_("size of dynamic symbols is not multiple of symbol size"));
return;
......
......@@ -229,7 +229,7 @@ class Sized_dynobj : public Dynobj
void
read_dynsym_section(const unsigned char* pshdrs, unsigned int shndx,
elfcpp::SHT type, unsigned int link,
File_view** view, off_t* view_size,
File_view** view, section_size_type* view_size,
unsigned int* view_info);
// Read the dynamic tags.
......
......@@ -237,7 +237,7 @@ typename elfcpp::Elf_types<size>::Elf_Addr
Eh_frame_hdr::get_fde_pc(
typename elfcpp::Elf_types<size>::Elf_Addr eh_frame_address,
const unsigned char* eh_frame_contents,
off_t fde_offset,
section_offset_type fde_offset,
unsigned char fde_encoding)
{
// The FDE starts with a 4 byte length and a 4 byte offset to the
......@@ -339,9 +339,10 @@ Eh_frame_hdr::get_fde_addresses(Output_file* of,
// CIE. Record the FDE pc for EH_FRAME_HDR. Return the new offset.
template<int size, bool big_endian>
off_t
Fde::write(unsigned char* oview, off_t offset, off_t cie_offset,
unsigned char fde_encoding, Eh_frame_hdr* eh_frame_hdr)
section_offset_type
Fde::write(unsigned char* oview, section_offset_type offset,
section_offset_type cie_offset, unsigned char fde_encoding,
Eh_frame_hdr* eh_frame_hdr)
{
size_t length = this->contents_.length();
......@@ -383,8 +384,9 @@ Cie::~Cie()
// Set the output offset of a CIE. Return the new output offset.
off_t
Cie::set_output_offset(off_t output_offset, unsigned int addralign,
section_offset_type
Cie::set_output_offset(section_offset_type output_offset,
unsigned int addralign,
Merge_map* merge_map)
{
size_t length = this->contents_.length();
......@@ -413,10 +415,11 @@ Cie::set_output_offset(off_t output_offset, unsigned int addralign,
// recording. Return the new offset.
template<int size, bool big_endian>
off_t
Cie::write(unsigned char* oview, off_t offset, Eh_frame_hdr* eh_frame_hdr)
section_offset_type
Cie::write(unsigned char* oview, section_offset_type offset,
Eh_frame_hdr* eh_frame_hdr)
{
off_t cie_offset = offset;
section_offset_type cie_offset = offset;
size_t length = this->contents_.length();
......@@ -512,15 +515,15 @@ bool
Eh_frame::add_ehframe_input_section(
Sized_relobj<size, big_endian>* object,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
unsigned int shndx,
unsigned int reloc_shndx,
unsigned int reloc_type)
{
// Get the section contents.
off_t contents_len;
section_size_type contents_len;
const unsigned char* pcontents = object->section_contents(shndx,
&contents_len,
false);
......@@ -576,14 +579,14 @@ bool
Eh_frame::do_add_ehframe_input_section(
Sized_relobj<size, big_endian>* object,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
unsigned int shndx,
unsigned int reloc_shndx,
unsigned int reloc_type,
const unsigned char* pcontents,
off_t contents_len,
section_size_type contents_len,
New_cies* new_cies)
{
typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
......@@ -664,9 +667,9 @@ bool
Eh_frame::read_cie(Sized_relobj<size, big_endian>* object,
unsigned int shndx,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
const unsigned char* pcontents,
const unsigned char* pcie,
const unsigned char *pcieend,
......@@ -918,7 +921,7 @@ bool
Eh_frame::read_fde(Sized_relobj<size, big_endian>* object,
unsigned int shndx,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* pcontents,
unsigned int offset,
const unsigned char* pfde,
......@@ -1001,7 +1004,7 @@ void
Eh_frame::set_final_data_size()
{
off_t start_file_offset = this->offset();
off_t output_offset = 0;
section_offset_type output_offset = 0;
for (Unmergeable_cie_offsets::iterator p =
this->unmergeable_cie_offsets_.begin();
......@@ -1032,7 +1035,8 @@ Eh_frame::set_final_data_size()
bool
Eh_frame::do_output_offset(const Relobj* object, unsigned int shndx,
off_t offset, off_t* poutput) const
section_offset_type offset,
section_offset_type* poutput) const
{
return this->merge_map_.get_output_offset(object, shndx, offset, poutput);
}
......@@ -1096,7 +1100,7 @@ template<int size, bool big_endian>
void
Eh_frame::do_sized_write(unsigned char* oview)
{
off_t o = 0;
section_offset_type o = 0;
for (Unmergeable_cie_offsets::iterator p =
this->unmergeable_cie_offsets_.begin();
p != this->unmergeable_cie_offsets_.end();
......@@ -1114,9 +1118,9 @@ bool
Eh_frame::add_ehframe_input_section<32, false>(
Sized_relobj<32, false>* object,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
unsigned int shndx,
unsigned int reloc_shndx,
unsigned int reloc_type);
......@@ -1128,9 +1132,9 @@ bool
Eh_frame::add_ehframe_input_section<32, true>(
Sized_relobj<32, true>* object,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
unsigned int shndx,
unsigned int reloc_shndx,
unsigned int reloc_type);
......@@ -1142,9 +1146,9 @@ bool
Eh_frame::add_ehframe_input_section<64, false>(
Sized_relobj<64, false>* object,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
unsigned int shndx,
unsigned int reloc_shndx,
unsigned int reloc_type);
......@@ -1156,9 +1160,9 @@ bool
Eh_frame::add_ehframe_input_section<64, true>(
Sized_relobj<64, true>* object,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
unsigned int shndx,
unsigned int reloc_shndx,
unsigned int reloc_type);
......
......@@ -57,7 +57,7 @@ class Eh_frame_hdr : public Output_section_data
// Record an FDE.
void
record_fde(off_t fde_offset, unsigned char fde_encoding)
record_fde(section_offset_type fde_offset, unsigned char fde_encoding)
{
if (!this->any_unrecognized_eh_frame_sections_)
this->fde_offsets_.push_back(std::make_pair(fde_offset, fde_encoding));
......@@ -79,7 +79,7 @@ class Eh_frame_hdr : public Output_section_data
// The data we record for one FDE: the offset of the FDE within the
// .eh_frame section, and the FDE encoding.
typedef std::pair<off_t, unsigned char> Fde_offset;
typedef std::pair<section_offset_type, unsigned char> Fde_offset;
// The list of information we record for an FDE.
typedef std::vector<Fde_offset> Fde_offsets;
......@@ -133,7 +133,7 @@ class Eh_frame_hdr : public Output_section_data
typename elfcpp::Elf_types<size>::Elf_Addr
get_fde_pc(typename elfcpp::Elf_types<size>::Elf_Addr eh_frame_address,
const unsigned char* eh_frame_contents,
off_t fde_offset, unsigned char fde_encoding);
section_offset_type fde_offset, unsigned char fde_encoding);
// Convert Fde_offsets to Fde_addresses.
template<int size, bool big_endian>
......@@ -158,7 +158,7 @@ class Eh_frame_hdr : public Output_section_data
class Fde
{
public:
Fde(Relobj* object, unsigned int shndx, off_t input_offset,
Fde(Relobj* object, unsigned int shndx, section_offset_type input_offset,
const unsigned char* contents, size_t length)
: object_(object), shndx_(shndx), input_offset_(input_offset),
contents_(reinterpret_cast<const char*>(contents), length)
......@@ -172,7 +172,7 @@ class Fde
// Add a mapping for this FDE to MERGE_MAP.
void
add_mapping(off_t output_offset, Merge_map* merge_map) const
add_mapping(section_offset_type output_offset, Merge_map* merge_map) const
{
merge_map->add_mapping(this->object_, this->shndx_,
this->input_offset_, this->length(),
......@@ -183,9 +183,10 @@ class Fde
// encoding, from the CIE. Record the FDE in EH_FRAME_HDR. Return
// the new offset.
template<int size, bool big_endian>
off_t
write(unsigned char* oview, off_t offset, off_t cie_offset,
unsigned char fde_encoding, Eh_frame_hdr* eh_frame_hdr);
section_offset_type
write(unsigned char* oview, section_offset_type offset,
section_offset_type cie_offset, unsigned char fde_encoding,
Eh_frame_hdr* eh_frame_hdr);
private:
// The object in which this FDE was seen.
......@@ -193,7 +194,7 @@ class Fde
// Input section index for this FDE.
unsigned int shndx_;
// Offset within the input section for this FDE.
off_t input_offset_;
section_offset_type input_offset_;
// FDE data.
std::string contents_;
};
......@@ -203,7 +204,7 @@ class Fde
class Cie
{
public:
Cie(Relobj* object, unsigned int shndx, off_t input_offset,
Cie(Relobj* object, unsigned int shndx, section_offset_type input_offset,
unsigned char fde_encoding, const char* personality_name,
const unsigned char* contents, size_t length)
: object_(object),
......@@ -243,14 +244,16 @@ class Cie
// followed by all its FDEs. ADDRALIGN is the required address
// alignment, typically 4 or 8. This updates MERGE_MAP with the
// mapping. It returns the new output offset.
off_t
set_output_offset(off_t output_offset, unsigned int addralign, Merge_map*);
section_offset_type
set_output_offset(section_offset_type output_offset, unsigned int addralign,
Merge_map*);
// Write the CIE to OVIEW starting at OFFSET. EH_FRAME_HDR is the
// exception frame header for FDE recording. Return the new offset.
template<int size, bool big_endian>
off_t
write(unsigned char* oview, off_t offset, Eh_frame_hdr* eh_frame_hdr);
section_offset_type
write(unsigned char* oview, section_offset_type offset,
Eh_frame_hdr* eh_frame_hdr);
friend bool operator<(const Cie&, const Cie&);
friend bool operator==(const Cie&, const Cie&);
......@@ -264,7 +267,7 @@ class Cie
// Input section index for this CIE.
unsigned int shndx_;
// Offset within the input section for this CIE.
off_t input_offset_;
section_offset_type input_offset_;
// The encoding of the FDE. This is a DW_EH_PE code.
unsigned char fde_encoding_;
// The name of the personality routine. This will be the name of a
......@@ -303,9 +306,9 @@ class Eh_frame : public Output_section_data
bool
add_ehframe_input_section(Sized_relobj<size, big_endian>* object,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
unsigned int shndx, unsigned int reloc_shndx,
unsigned int reloc_type);
......@@ -319,8 +322,9 @@ class Eh_frame : public Output_section_data
// Return the output address for an input address.
bool
do_output_offset(const Relobj*, unsigned int shndx, off_t offset,
off_t* poutput) const;
do_output_offset(const Relobj*, unsigned int shndx,
section_offset_type offset,
section_offset_type* poutput) const;
// Write the data to the file.
void
......@@ -358,14 +362,14 @@ class Eh_frame : public Output_section_data
bool
do_add_ehframe_input_section(Sized_relobj<size, big_endian>* object,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
unsigned int shndx,
unsigned int reloc_shndx,
unsigned int reloc_type,
const unsigned char* pcontents,
off_t contents_len,
section_size_type contents_len,
New_cies*);
// Read a CIE.
......@@ -374,9 +378,9 @@ class Eh_frame : public Output_section_data
read_cie(Sized_relobj<size, big_endian>* object,
unsigned int shndx,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* symbol_names,
off_t symbol_names_size,
section_size_type symbol_names_size,
const unsigned char* pcontents,
const unsigned char* pcie,
const unsigned char *pcieend,
......@@ -390,7 +394,7 @@ class Eh_frame : public Output_section_data
read_fde(Sized_relobj<size, big_endian>* object,
unsigned int shndx,
const unsigned char* symbols,
off_t symbols_size,
section_size_type symbols_size,
const unsigned char* pcontents,
unsigned int offset,
const unsigned char* pfde,
......
......@@ -191,7 +191,7 @@ File_read::is_locked() const
// SIZE bytes. Return a pointer to the View if found, NULL if not.
inline File_read::View*
File_read::find_view(off_t start, off_t size) const
File_read::find_view(off_t start, section_size_type size) const
{
off_t page = File_read::page_offset(start);
Views::const_iterator p = this->views_.find(page);
......@@ -257,7 +257,7 @@ File_read::read(off_t start, off_t size, void* p) const
// Find an existing view or make a new one.
File_read::View*
File_read::find_or_make_view(off_t start, off_t size, bool cache)
File_read::find_or_make_view(off_t start, section_size_type size, bool cache)
{
gold_assert(!this->token_.is_writable());
this->released_ = false;
......@@ -326,14 +326,14 @@ File_read::find_or_make_view(off_t start, off_t size, bool cache)
// Get a view into the file.
const unsigned char*
File_read::get_view(off_t start, off_t size, bool cache)
File_read::get_view(off_t start, section_size_type size, bool cache)
{
File_read::View* pv = this->find_or_make_view(start, size, cache);
return pv->data() + (start - pv->start());
}
File_view*
File_read::get_lasting_view(off_t start, off_t size, bool cache)
File_read::get_lasting_view(off_t start, section_size_type size, bool cache)
{
File_read::View* pv = this->find_or_make_view(start, size, cache);
pv->lock();
......
......@@ -110,7 +110,7 @@ class File_read
// to get_view, read, or get_lasting_view which retrieve the same
// data.
const unsigned char*
get_view(off_t start, off_t size, bool cache);
get_view(off_t start, section_size_type size, bool cache);
// Read data from the file into the buffer P starting at file offset
// START for SIZE bytes.
......@@ -124,7 +124,7 @@ class File_read
// error if we can not read enough data from the file. The CACHE
// parameter is as in get_view.
File_view*
get_lasting_view(off_t start, off_t size, bool cache);
get_lasting_view(off_t start, section_size_type size, bool cache);
// Dump statistical information to stderr.
static void
......@@ -151,8 +151,8 @@ class File_read
class View
{
public:
View(off_t start, off_t size, const unsigned char* data, bool cache,
bool mapped)
View(off_t start, section_size_type size, const unsigned char* data,
bool cache, bool mapped)
: start_(start), size_(size), data_(data), lock_count_(0),
cache_(cache), mapped_(mapped)
{ }
......@@ -163,7 +163,7 @@ class File_read
start() const
{ return this->start_; }
off_t
section_size_type
size() const
{ return this->size_; }
......@@ -193,7 +193,7 @@ class File_read
View& operator=(const View&);
off_t start_;
off_t size_;
section_size_type size_;
const unsigned char* data_;
int lock_count_;
bool cache_;
......@@ -205,7 +205,7 @@ class File_read
// Find a view into the file.
View*
find_view(off_t start, off_t size) const;
find_view(off_t start, section_size_type size) const;
// Read data from the file into a buffer.
void
......@@ -213,7 +213,7 @@ class File_read
// Find or make a view into the file.
View*
find_or_make_view(off_t start, off_t size, bool cache);
find_or_make_view(off_t start, section_size_type size, bool cache);
// Clear the file views.
void
......
......@@ -161,10 +161,7 @@ class Select_size_endian { };
#endif // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS)
} // End namespace gold.
namespace gold
{
// General declarations.
class General_options;
class Command_line;
......@@ -180,6 +177,17 @@ class Output_file;
template<int size, bool big_endian>
struct Relocate_info;
// Some basic types. For these we use lower case initial letters.
// For an offset in an input or output file, use off_t. Note that
// this will often be a 64-bit type even for a 32-bit build.
// The size of a section if we are going to look at the contents.
typedef size_t section_size_type;
// An offset within a section when we are looking at the contents.
typedef ptrdiff_t section_offset_type;
// The name of the program as used in error messages.
extern const char* program_name;
......@@ -250,6 +258,22 @@ print_version(bool print_short);
extern const char*
get_version_string();