This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] gold: fix some signed-unsigned comparison warnings
> diff --git a/gold/arm.cc b/gold/arm.cc
> index 5770c8a..d53ef6b 100644
> --- a/gold/arm.cc
> +++ b/gold/arm.cc
> @@ -9688,7 +9688,7 @@ Target_arm<big_endian>::relocate_special_relocatable(
>
> Arm_address offset = reloc.get_r_offset();
> Arm_address new_offset;
> - if (offset_in_output_section != invalid_address)
> + if (offset_in_output_section != (off_t) invalid_address)
> new_offset = offset + offset_in_output_section;
> else
> {
> @@ -9707,7 +9707,7 @@ Target_arm<big_endian>::relocate_special_relocatable(
> if (!parameters->options().relocatable())
> {
> new_offset += view_address;
> - if (offset_in_output_section != invalid_address)
> + if (offset_in_output_section != (off_t) invalid_address)
> new_offset -= offset_in_output_section;
> }
Seems to me that offset_in_output_section is misdeclared here. As
passed from relocate_relocs(), the actual parameter is declared as an
Elf_Addr, which is unsigned. I think offset_in_output_section should
be Arm_address here.
> diff --git a/gold/dwarf_reader.cc b/gold/dwarf_reader.cc
> index c80e8cb..50942d6 100644
> --- a/gold/dwarf_reader.cc
> +++ b/gold/dwarf_reader.cc
> @@ -57,7 +57,7 @@ Sized_elf_reloc_mapper<size, big_endian>::symbol_section(
> unsigned int symndx, Address* value, bool* is_ordinary)
> {
> const int symsize = elfcpp::Elf_sizes<size>::sym_size;
> - gold_assert((symndx + 1) * symsize <= this->symtab_size_);
> + gold_assert((off_t) ((symndx + 1) * symsize) <= this->symtab_size_);
> elfcpp::Sym<size, big_endian> elfsym(this->symtab_ + symndx * symsize);
> *value = elfsym.get_st_value();
> return this->object_->adjust_sym_shndx(symndx, elfsym.get_st_shndx(),
And here, I think the right thing to do is declare symsize as an
off_t, since that's what Sized_elf_reloc_mapper::symtab_size_ is.
> diff --git a/gold/incremental.cc b/gold/incremental.cc
> index acabaea..9898434 100644
> --- a/gold/incremental.cc
> +++ b/gold/incremental.cc
> @@ -1432,7 +1432,7 @@ Output_section_incremental_inputs<size,
> big_endian>::do_write(Output_file* of)
> gold_assert(pov - oview == oview_size);
>
> // Write the .gnu_incremental_symtab section.
> - gold_assert(global_sym_count * 4 == symtab_size);
> + gold_assert((off_t) global_sym_count * 4 == symtab_size);
This is the right thing here, but it's preferable to use C++
static_cast<off_t>(...).
> --- a/gold/output.cc
> +++ b/gold/output.cc
> @@ -1935,7 +1935,7 @@ Output_symtab_xindex::endian_do_write(unsigned
> char* const oview)
> ++p)
> {
> unsigned int symndx = p->first;
> - gold_assert(symndx * 4 < this->data_size());
> + gold_assert((off_t) symndx * 4 < this->data_size());
Likewise.
-cary