lot of instances of off_t.
// 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())
{
// 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);
// 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;
++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());
// 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.
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;
}
// 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
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)
*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();
}
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();
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.
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;
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;
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;
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.
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
// 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();
// 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();
// 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();
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);
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;
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,
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,
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();
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);
}
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();
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);
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);
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);
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);
// 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));
// 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;
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>
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)
// 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(),
// 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.
// 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_;
};
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),
// 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&);
// 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
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);
// 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
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.
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,
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,
// 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);
// 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;
// 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();
// 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.
// 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
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)
{ }
start() const
{ return this->start_; }
- off_t
+ section_size_type
size() const
{ return this->size_; }
View& operator=(const View&);
off_t start_;
- off_t size_;
+ section_size_type size_;
const unsigned char* data_;
int lock_count_;
bool cache_;
// 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
// 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
#endif // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS)
-} // End namespace gold.
-
-namespace gold
-{
+// General declarations.
class General_options;
class Command_line;
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;
extern const char*
get_version_string();
+// Convert numeric types without unnoticed loss of precision.
+template<typename To, typename From>
+inline To
+convert_types(const From from)
+{
+ To to = from;
+ gold_assert(to == from);
+ return to;
+}
+
+// A common case of convert_types<>: convert to section_size_type.
+template<typename From>
+inline section_size_type
+convert_to_section_size_type(const From from)
+{ return convert_types<section_size_type, From>(from); }
+
// Queue up the first set of tasks.
extern void
queue_initial_tasks(const General_options&,
// output section. An OUTPUT_OFFSET of -1 means that the bytes are
// discarded.
void
- add_mapping(const Merge_map*, unsigned int shndx, off_t offset, off_t length,
- off_t output_offset);
+ add_mapping(const Merge_map*, unsigned int shndx, section_offset_type offset,
+ section_size_type length, section_offset_type output_offset);
// Get the output offset for an input address in MERGE_MAP. The
// input address is at offset OFFSET in section SHNDX. This sets
// -1 if the bytes are not being copied to the output. This returns
// true if the mapping is known, false otherwise.
bool
- get_output_offset(const Merge_map*, unsigned int shndx, off_t offset,
- off_t *output_offset);
+ get_output_offset(const Merge_map*, unsigned int shndx,
+ section_offset_type offset,
+ section_offset_type *output_offset);
private:
// Map input section offsets to a length and an output section
struct Input_merge_entry
{
// The offset in the input section.
- off_t input_offset;
+ section_offset_type input_offset;
// The length.
- off_t length;
+ section_size_type length;
// The offset in the output section.
- off_t output_offset;
+ section_offset_type output_offset;
};
// A less-than comparison routine for Input_merge_entry.
void
Object_merge_map::add_mapping(const Merge_map* merge_map, unsigned int shndx,
- off_t input_offset, off_t length,
- off_t output_offset)
+ section_offset_type input_offset,
+ section_size_type length,
+ section_offset_type output_offset)
{
Input_merge_map* map = this->get_or_make_input_merge_map(merge_map, shndx);
{
Input_merge_entry& entry(map->entries.back());
+ // Use section_size_type to avoid signed/unsigned warnings.
+ section_size_type input_offset_u = input_offset;
+ section_size_type output_offset_u = output_offset;
+
// If this entry is not in order, we need to sort the vector
// before looking anything up.
- if (input_offset < entry.input_offset + entry.length)
+ if (input_offset_u < entry.input_offset + entry.length)
{
- gold_assert(input_offset < entry.input_offset
- && input_offset + length <= entry.input_offset);
+ gold_assert(input_offset < entry.input_offset);
+ gold_assert(input_offset_u + length
+ <= static_cast<section_size_type>(entry.input_offset));
map->sorted = false;
}
- else if (entry.input_offset + entry.length == input_offset
+ else if (entry.input_offset + entry.length == input_offset_u
&& (output_offset == -1
? entry.output_offset == -1
- : entry.output_offset + entry.length == output_offset))
+ : entry.output_offset + entry.length == output_offset_u))
{
entry.length += length;
return;
bool
Object_merge_map::get_output_offset(const Merge_map* merge_map,
- unsigned int shndx, off_t input_offset,
- off_t *output_offset)
+ unsigned int shndx,
+ section_offset_type input_offset,
+ section_offset_type *output_offset)
{
Input_merge_map* map = this->get_input_merge_map(shndx);
if (map == NULL || map->merge_map != merge_map)
gold_assert(p->input_offset <= input_offset);
}
- if (input_offset - p->input_offset >= p->length)
+ if (input_offset - p->input_offset
+ >= static_cast<section_offset_type>(p->length))
return false;
*output_offset = p->output_offset;
void
Merge_map::add_mapping(Relobj* object, unsigned int shndx,
- off_t offset, off_t length, off_t output_offset)
+ section_offset_type offset, section_size_type length,
+ section_offset_type output_offset)
{
Object_merge_map* object_merge_map = object->merge_map();
if (object_merge_map == NULL)
bool
Merge_map::get_output_offset(const Relobj* object, unsigned int shndx,
- off_t offset, off_t* output_offset) const
+ section_offset_type offset,
+ section_offset_type* output_offset) const
{
Object_merge_map* object_merge_map = object->merge_map();
if (object_merge_map == NULL)
bool
Output_merge_base::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);
}
Output_merge_data::Merge_data_hash::operator()(Merge_data_key k) const
{
const unsigned char* p = this->pomd_->constant(k);
- uint64_t entsize = this->pomd_->entsize();
+ section_size_type entsize =
+ convert_to_section_size_type(this->pomd_->entsize());
// Fowler/Noll/Vo (FNV) hash (type FNV-1a).
if (sizeof(size_t) == 8)
{
size_t result = static_cast<size_t>(14695981039346656037ULL);
- for (uint64_t i = 0; i < entsize; ++i)
+ for (section_size_type i = 0; i < entsize; ++i)
{
result &= (size_t) *p++;
result *= 1099511628211ULL;
else
{
size_t result = 2166136261UL;
- for (uint64_t i = 0; i < entsize; ++i)
+ for (section_size_type i = 0; i < entsize; ++i)
{
result ^= (size_t) *p++;
result *= 16777619UL;
void
Output_merge_data::add_constant(const unsigned char* p)
{
- uint64_t entsize = this->entsize();
- uint64_t addsize = std::max(entsize, this->addralign());
+ section_size_type entsize = convert_to_section_size_type(this->entsize());
+ section_size_type addralign =
+ convert_to_section_size_type(this->addralign());
+ section_size_type addsize = std::max(entsize, addralign);
if (this->len_ + addsize > this->alc_)
{
if (this->alc_ == 0)
bool
Output_merge_data::do_add_input_section(Relobj* object, unsigned int shndx)
{
- off_t len;
+ section_size_type len;
const unsigned char* p = object->section_contents(shndx, &len, false);
- uint64_t entsize = this->entsize();
+ section_size_type entsize = convert_to_section_size_type(this->entsize());
if (len % entsize != 0)
return false;
- for (off_t i = 0; i < len; i += entsize, p += entsize)
+ for (section_size_type i = 0; i < len; i += entsize, p += entsize)
{
// Add the constant to the section contents. If we find that it
// is already in the hash table, we will remove it again.
Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
unsigned int shndx)
{
- off_t len;
+ section_size_type len;
const unsigned char* pdata = object->section_contents(shndx, &len, false);
const Char_type* p = reinterpret_cast<const Char_type*>(pdata);
}
// The index I is in bytes, not characters.
- off_t i = 0;
+ section_size_type i = 0;
while (i < len)
{
const Char_type* pl;
const Char_type* str = this->stringpool_.add_prefix(p, pl - p, NULL);
- size_t bytelen_with_null = ((pl - p) + 1) * sizeof(Char_type);
+ section_size_type bytelen_with_null = ((pl - p) + 1) * sizeof(Char_type);
this->merged_strings_.push_back(Merged_string(object, shndx, i, str,
bytelen_with_null));
// section, and return the final data size.
template<typename Char_type>
-off_t
+section_size_type
Output_merge_string<Char_type>::finalize_merged_data()
{
this->stringpool_.set_string_offsets();
// output section. An OUTPUT_OFFSET of -1 means that the bytes are
// discarded.
void
- add_mapping(Relobj* object, unsigned int shndx, off_t offset, off_t length,
- off_t output_offset);
+ add_mapping(Relobj* object, unsigned int shndx,
+ section_offset_type offset, section_size_type length,
+ section_offset_type output_offset);
// Return the output offset for an input address. The input address
// is at offset OFFSET in section SHNDX in OBJECT. This sets
// -1 if the bytes are not being copied to the output. This returns
// true if the mapping is known, false otherwise.
bool
- get_output_offset(const Relobj* object, unsigned int shndx, off_t offset,
- off_t *output_offset) const;
+ get_output_offset(const Relobj* object, unsigned int shndx,
+ section_offset_type offset,
+ section_offset_type *output_offset) const;
};
// A general class for SHF_MERGE data, to hold functions shared by
// Return the output offset for an input offset.
bool
- do_output_offset(const Relobj* object, unsigned int shndx, off_t offset,
- off_t* poutput) const;
+ do_output_offset(const Relobj* object, unsigned int shndx,
+ section_offset_type offset,
+ section_offset_type* poutput) const;
protected:
// Return the entry size.
// Add a mapping from an OFFSET in input section SHNDX in object
// OBJECT to an OUTPUT_OFFSET in the output section.
void
- add_mapping(Relobj* object, unsigned int shndx, off_t offset,
- off_t length, off_t output_offset)
+ add_mapping(Relobj* object, unsigned int shndx, section_offset_type offset,
+ section_size_type length, section_offset_type output_offset)
{
this->merge_map_.add_mapping(object, shndx, offset, length, output_offset);
}
// A key in the hash table. This is an offset in the section
// contents we are building.
- typedef off_t Merge_data_key;
+ typedef section_offset_type Merge_data_key;
// Compute the hash code. To do this we need a pointer back to the
// object holding the data.
const unsigned char*
constant(Merge_data_key k) const
{
- gold_assert(k >= 0 && k < this->len_);
+ gold_assert(k >= 0 && k < static_cast<section_offset_type>(this->len_));
return this->p_ + k;
}
// The accumulated data.
unsigned char* p_;
// The length of the accumulated data.
- off_t len_;
+ section_size_type len_;
// The size of the allocated buffer.
- size_t alc_;
+ section_size_type alc_;
// The hash table.
Merge_data_hashtable hashtable_;
};
// Do all the final processing after the input sections are read in.
// Returns the final data size.
- off_t
+ section_size_type
finalize_merged_data();
// Set the final data size.
// Writes the stringpool to a buffer.
void
- stringpool_to_buffer(unsigned char* buffer, size_t buffer_size)
+ stringpool_to_buffer(unsigned char* buffer, section_size_type buffer_size)
{ this->stringpool_.write_to_buffer(buffer, buffer_size); }
// Clears all the data in the stringpool, to save on memory.
// The input section in the input object.
unsigned int shndx;
// The offset in the input section.
- off_t offset;
+ section_offset_type offset;
// The string itself, a pointer into a Stringpool.
const Char_type* string;
// The length of the string in bytes, including the null terminator.
size_t length;
- Merged_string(Relobj *objecta, unsigned int shndxa, off_t offseta,
- const Char_type* stringa, size_t lengtha)
+ Merged_string(Relobj *objecta, unsigned int shndxa,
+ section_offset_type offseta, const Char_type* stringa,
+ size_t lengtha)
: object(objecta), shndx(shndxa), offset(offseta), string(stringa),
length(lengtha)
{ }
// Return a view of the contents of a section.
const unsigned char*
-Object::section_contents(unsigned int shndx, off_t* plen, bool cache)
+Object::section_contents(unsigned int shndx, section_size_type* plen,
+ bool cache)
{
Location loc(this->do_section_contents(shndx));
- *plen = loc.data_size;
- return this->get_view(loc.file_offset, loc.data_size, cache);
+ *plen = convert_to_section_size_type(loc.data_size);
+ return this->get_view(loc.file_offset, *plen, cache);
}
// Read the section data into SD. This is code common to Sized_relobj
this->error(_("section name section has wrong type: %u"),
static_cast<unsigned int>(shdrnames.get_sh_type()));
- sd->section_names_size = shdrnames.get_sh_size();
+ sd->section_names_size =
+ convert_to_section_size_type(shdrnames.get_sh_size());
sd->section_names = this->get_lasting_view(shdrnames.get_sh_offset(),
sd->section_names_size, false);
}
template<int size, bool big_endian>
bool
-Sized_relobj<size, big_endian>::find_eh_frame(const unsigned char* pshdrs,
- const char* names,
- off_t names_size) const
+Sized_relobj<size, big_endian>::find_eh_frame(
+ const unsigned char* pshdrs,
+ const char* names,
+ section_size_type names_size) const
{
const unsigned int shnum = this->shnum();
const unsigned char* p = pshdrs + This::shdr_size;
const unsigned int loccount = symtabshdr.get_sh_info();
this->local_symbol_count_ = loccount;
this->local_values_.resize(loccount);
- off_t locsize = loccount * sym_size;
+ section_offset_type locsize = loccount * sym_size;
off_t dataoff = symtabshdr.get_sh_offset();
- off_t datasize = symtabshdr.get_sh_size();
+ section_size_type datasize =
+ convert_to_section_size_type(symtabshdr.get_sh_size());
off_t extoff = dataoff + locsize;
- off_t extsize = datasize - locsize;
+ section_size_type extsize = datasize - locsize;
off_t readoff = this->has_eh_frame_ ? dataoff : extoff;
- off_t readsize = this->has_eh_frame_ ? datasize : extsize;
+ section_size_type readsize = this->has_eh_frame_ ? datasize : extsize;
File_view* fvsymtab = this->get_lasting_view(readoff, readsize, false);
sd->symbols_size = readsize;
sd->external_symbols_offset = this->has_eh_frame_ ? locsize : 0;
sd->symbol_names = fvstrtab;
- sd->symbol_names_size = strtabshdr.get_sh_size();
+ sd->symbol_names_size =
+ convert_to_section_size_type(strtabshdr.get_sh_size());
}
// Return the section index of symbol SYM. Set *VALUE to its value in
Sized_relobj<size, big_endian>::symbol_section_and_value(unsigned int sym,
Address* value)
{
- off_t symbols_size;
+ section_size_type symbols_size;
const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
&symbols_size,
false);
elfcpp::Sym<size, big_endian> sym(psym);
// Read the symbol table names.
- off_t symnamelen;
+ section_size_type symnamelen;
const unsigned char* psymnamesu;
psymnamesu = this->section_contents(symshdr.get_sh_link(), &symnamelen,
true);
const int sym_size = This::sym_size;
size_t symcount = ((sd->symbols_size - sd->external_symbols_offset)
/ sym_size);
- if (static_cast<off_t>(symcount * sym_size)
- != sd->symbols_size - sd->external_symbols_offset)
+ if (symcount * sym_size != sd->symbols_size - sd->external_symbols_offset)
{
this->error(_("size of symbols is not multiple of symbol size"));
return;
// Read the symbol names.
const unsigned int strtab_shndx = symtabshdr.get_sh_link();
- off_t strtab_size;
+ section_size_type strtab_size;
const unsigned char* pnamesu = this->section_contents(strtab_shndx,
&strtab_size,
true);
// Read the symbol names.
const unsigned int strtab_shndx = symtabshdr.get_sh_link();
- off_t strtab_size;
+ section_size_type strtab_size;
const unsigned char* pnamesu = this->section_contents(strtab_shndx,
&strtab_size,
true);
if (this->symtab_shndx_ == 0)
return false;
- off_t symbols_size;
+ section_size_type symbols_size;
const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
&symbols_size,
false);
unsigned int symbol_names_shndx = this->section_link(this->symtab_shndx_);
- off_t names_size;
+ section_size_type names_size;
const unsigned char* symbol_names_u =
this->section_contents(symbol_names_shndx, &names_size, false);
const char* symbol_names = reinterpret_cast<const char*>(symbol_names_u);
Object*
make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
- const unsigned char* p, off_t bytes)
+ const unsigned char* p, section_offset_type bytes)
{
if (bytes < elfcpp::EI_NIDENT)
{
// Section names.
File_view* section_names;
// Size of section name data in bytes.
- off_t section_names_size;
+ section_size_type section_names_size;
// Symbol data.
File_view* symbols;
// Size of symbol data in bytes.
- off_t symbols_size;
+ section_size_type symbols_size;
// Offset of external symbols within symbol data. This structure
// sometimes contains only external symbols, in which case this will
// be zero. Sometimes it contains all symbols.
- off_t external_symbols_offset;
+ section_offset_type external_symbols_offset;
// Symbol names.
File_view* symbol_names;
// Size of symbol name data in bytes.
- off_t symbol_names_size;
+ section_size_type symbol_names_size;
// Version information. This is only used on dynamic objects.
// Version symbol data (from SHT_GNU_versym section).
File_view* versym;
- off_t versym_size;
+ section_size_type versym_size;
// Version definition data (from SHT_GNU_verdef section).
File_view* verdef;
- off_t verdef_size;
+ section_size_type verdef_size;
unsigned int verdef_info;
// Needed version data (from SHT_GNU_verneed section).
File_view* verneed;
- off_t verneed_size;
+ section_size_type verneed_size;
unsigned int verneed_info;
};
// Return a view of the contents of a section. Set *PLEN to the
// size. CACHE is a hint as in File_read::get_view.
const unsigned char*
- section_contents(unsigned int shndx, off_t* plen, bool cache);
+ section_contents(unsigned int shndx, section_size_type* plen, bool cache);
// Return the name of a section given a section index. This is only
// used for error messages.
// Return a View.
View
- view(off_t file_offset, off_t data_size)
+ view(off_t file_offset, section_size_type data_size)
{ return View(this->get_view(file_offset, data_size, true)); }
// Report an error.
off_t file_offset;
off_t data_size;
- Location(off_t fo, off_t ds)
+ Location(off_t fo, section_size_type ds)
: file_offset(fo), data_size(ds)
{ }
};
// 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 + this->offset_, size,
cache);
// Get a lasting view into the underlying file.
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)
{
return this->input_file()->file().get_lasting_view(start + this->offset_,
size, cache);
// Read data from the underlying file.
void
- read(off_t start, off_t size, void* p) const
+ read(off_t start, section_size_type size, void* p) const
{ this->input_file()->file().read(start + this->offset_, size, p); }
// Set the target.
// and set *POFF to the offset within that section. *POFF will be
// set to -1 if the section requires special handling.
inline Output_section*
- output_section(unsigned int shndx, off_t* poff) const;
+ output_section(unsigned int shndx, section_offset_type* poff) const;
// Set the offset of an input section within its output section.
void
- set_section_offset(unsigned int shndx, off_t off)
+ set_section_offset(unsigned int shndx, section_offset_type off)
{
gold_assert(shndx < this->map_to_output_.size());
this->map_to_output_[shndx].offset = off;
Output_section* output_section;
// The offset within the output section. This is -1 if the
// section requires special handling.
- off_t offset;
+ section_offset_type offset;
};
// Read the relocs--implemented by child class.
// Implement Object::output_section inline for efficiency.
inline Output_section*
-Relobj::output_section(unsigned int shndx, off_t* poff) const
+Relobj::output_section(unsigned int shndx, section_offset_type* poff) const
{
gold_assert(shndx < this->map_to_output_.size());
const Map_to_output& mo(this->map_to_output_[shndx]);
// a GNU style exception frame section.
bool
find_eh_frame(const unsigned char* pshdrs, const char* names,
- off_t names_size) const;
+ section_size_type names_size) const;
// Whether to include a section group in the link.
bool
unsigned char* view;
typename elfcpp::Elf_types<size>::Elf_Addr address;
off_t offset;
- off_t view_size;
+ section_size_type view_size;
bool is_input_output_view;
bool is_postprocessing_view;
};
extern Object*
make_elf_object(const std::string& name, Input_file*,
off_t offset, const unsigned char* p,
- off_t bytes);
+ section_offset_type bytes);
} // end namespace gold
Address address = this->address_;
if (this->shndx_ != INVALID_CODE)
{
- off_t off;
+ section_offset_type off;
Output_section* os = this->u2_.relobj->output_section(this->shndx_,
&off);
gold_assert(os != NULL);
this->entries_.push_back(Got_entry());
unsigned int got_offset = this->last_got_offset();
object->set_local_tls_got_offset(symndx, got_offset, need_pair);
- off_t off;
+ section_offset_type off;
Output_section* os = object->output_section(shndx, &off);
rel_dyn->add_output_section(os, r_type, this, got_offset);
this->entries_.push_back(Got_entry());
unsigned int got_offset = this->last_got_offset();
object->set_local_tls_got_offset(symndx, got_offset, need_pair);
- off_t off;
+ section_offset_type off;
Output_section* os = object->output_section(shndx, &off);
rela_dyn->add_output_section(os, r_type, this, got_offset, 0);
// Try to turn an input offset into an output offset.
bool
-Output_section::Input_section::output_offset(const Relobj* object,
- unsigned int shndx,
- off_t offset,
- off_t *poutput) const
+Output_section::Input_section::output_offset(
+ const Relobj* object,
+ unsigned int shndx,
+ section_offset_type offset,
+ section_offset_type *poutput) const
{
if (!this->is_input_section())
return this->u2_.posd->output_offset(object, shndx, offset, poutput);
{
if (this->shndx_ != shndx || this->u2_.object != object)
return false;
- off_t output_offset;
+ section_offset_type output_offset;
Output_section* os = object->output_section(shndx, &output_offset);
gold_assert(os != NULL);
gold_assert(output_offset != -1);
p != this->input_sections_.end();
++p)
{
- off_t output_offset;
+ section_offset_type output_offset;
if (p->output_offset(object, shndx, offset, &output_offset))
return output_offset != -1;
}
// start of the section. This should only be called if SHNDX in
// OBJECT has a special mapping.
-off_t
+section_offset_type
Output_section::output_offset(const Relobj* object, unsigned int shndx,
- off_t offset) const
+ section_offset_type offset) const
{
gold_assert(object->is_section_specially_mapped(shndx));
// This can only be called meaningfully when layout is complete.
p != this->input_sections_.end();
++p)
{
- off_t output_offset;
+ section_offset_type output_offset;
if (p->output_offset(object, shndx, offset, &output_offset))
return output_offset;
}
++p)
{
addr = align_address(addr, p->addralign());
- off_t output_offset;
+ section_offset_type output_offset;
if (p->output_offset(object, shndx, offset, &output_offset))
{
if (output_offset == -1)
// sets *POUTPUT to the output offset. The value -1 indicates that
// this input offset is being discarded.
virtual bool
- output_offset(const Relobj* object, unsigned int shndx, off_t offset,
- off_t *poutput) const
+ output_offset(const Relobj* object, unsigned int shndx,
+ section_offset_type offset,
+ section_offset_type *poutput) const
{ return this->do_output_offset(object, shndx, offset, poutput); }
// Write the contents to a buffer. This is used for sections which
// The child class may implement output_offset.
virtual bool
- do_output_offset(const Relobj*, unsigned int, off_t, off_t*) const
+ do_output_offset(const Relobj*, unsigned int, section_offset_type,
+ section_offset_type*) const
{ return false; }
// The child class may implement write_to_buffer. Most child
// Return the offset within the output section of OFFSET relative to
// the start of input section SHNDX in object OBJECT.
- off_t
- output_offset(const Relobj* object, unsigned int shndx, off_t offset) const;
+ section_offset_type
+ output_offset(const Relobj* object, unsigned int shndx,
+ section_offset_type offset) const;
// Return the output virtual address of OFFSET relative to the start
// of input section SHNDX in object OBJECT.
// this function returns true, it sets *POUTPUT to the output
// offset.
bool
- output_offset(const Relobj* object, unsigned int shndx, off_t offset,
- off_t *poutput) const;
+ output_offset(const Relobj* object, unsigned int shndx,
+ section_offset_type offset,
+ section_offset_type *poutput) const;
// Write out the data. This does nothing for an input section.
void
// The contents of the input object's reloc section.
const unsigned char* prelocs_;
// The length of the reloc section.
- off_t len_;
+ section_size_type len_;
// Our current position in the reloc section.
- off_t pos_;
+ section_size_type pos_;
// The size of the relocs in the section.
int reloc_size_;
};
// directly.
const Key k = this->next_uncopied_key_;
- const off_t ozero = 0;
+ const section_offset_type ozero = 0;
std::pair<Hashkey, Hashval> element(Hashkey(s),
std::make_pair(k, ozero));
// The contents of the string stay the same, so we don't need to
// adjust hk.hash_code or hk.length.
- const off_t ozero = 0;
+ const section_offset_type ozero = 0;
std::pair<Hashkey, Hashval> element(hk, std::make_pair(k, ozero));
typedef std::pair<typename String_set_type::iterator, bool> Insert_type;
const size_t charsize = sizeof(Stringpool_char);
// Offset 0 may be reserved for the empty string.
- off_t offset = this->zero_null_ ? charsize : 0;
+ section_offset_type offset = this->zero_null_ ? charsize : 0;
// Sorting to find suffixes can take over 25% of the total CPU time
// used by the linker. Since it's merely an optimization to reduce
// exist.
template<typename Stringpool_char>
-off_t
+section_offset_type
Stringpool_template<Stringpool_char>::get_offset(const Stringpool_char* s)
const
{
template<typename Stringpool_char>
void
-Stringpool_template<Stringpool_char>::write_to_buffer(unsigned char* buffer,
- size_t bufsize)
+Stringpool_template<Stringpool_char>::write_to_buffer(
+ unsigned char* buffer,
+ section_size_type bufsize)
{
gold_assert(this->strtab_size_ != 0);
- // Quiet the compiler in opt mode.
- if (bufsize < static_cast<size_t>(this->strtab_size_))
- gold_assert(bufsize >= static_cast<size_t>(this->strtab_size_));
+ gold_assert(bufsize >= this->strtab_size_);
if (this->zero_null_)
buffer[0] = '\0';
for (typename String_set_type::const_iterator p = this->string_set_.begin();
++p)
{
const int len = (p->first.length + 1) * sizeof(Stringpool_char);
- gold_assert(p->second.second + len <= this->strtab_size_);
+ gold_assert(static_cast<section_size_type>(p->second.second) + len
+ <= this->strtab_size_);
memcpy(buffer + p->second.second, p->first.string, len);
}
}
// Get the offset of the string S in the string table. This returns
// the offset in bytes, not in units of Stringpool_char. This may
// only be called after set_string_offsets has been called.
- off_t
+ section_offset_type
get_offset(const Stringpool_char* s) const;
// Get the offset of the string S in the string table.
- off_t
+ section_offset_type
get_offset(const std::basic_string<Stringpool_char>& s) const
{ return this->get_offset(s.c_str()); }
// Get the size of the string table. This returns the number of
// bytes, not in units of Stringpool_char.
- off_t
+ section_size_type
get_strtab_size() const
{
gold_assert(this->strtab_size_ != 0);
// specified size. buffer_size should be at least
// get_strtab_size().
void
- write_to_buffer(unsigned char* buffer, size_t buffer_size);
+ write_to_buffer(unsigned char* buffer, section_size_type buffer_size);
// Dump statistical information to stderr.
void
// table offsets. We only use the offsets if we turn this into an
// string table section.
- typedef std::pair<Key, off_t> Hashval;
+ typedef std::pair<Key, section_offset_type> Hashval;
typedef Unordered_map<Hashkey, Hashval, Stringpool_hash,
Stringpool_eq> String_set_type;
// List of buffers.
Stringdata_list strings_;
// Size of string table.
- off_t strtab_size_;
+ section_size_type strtab_size_;
// Next Stringdata index.
unsigned int next_index_;
// Next key value for a string we don't copy.
else
{
Relobj* relobj = static_cast<Relobj*>(symobj);
- off_t secoff;
+ section_offset_type secoff;
Output_section* os = relobj->output_section(shndx, &secoff);
if (os == NULL)
else
{
Relobj* relobj = static_cast<Relobj*>(symobj);
- off_t secoff;
+ section_offset_type secoff;
Output_section* os = relobj->output_section(in_shndx,
&secoff);
gold_assert(os != NULL);
{
Task_lock_obj<Object> tl(task, p->second.object);
const unsigned char* c;
- off_t len;
+ section_size_type len;
c = p->second.object->section_contents(p->second.shndx, &len,
false);
p->second.set_text(reinterpret_cast<const char*>(c), len);
}
void
- set_text(const char* t, off_t l)
+ set_text(const char* t, section_size_type l)
{ this->text.assign(t, l); }
};