+static uint64_t
+count_relr_relocations (Filedata * filedata,
+ Elf_Internal_Shdr * section)
+{
+ uint64_t * relrs;
+ uint64_t nentries;
+ uint64_t i;
+ uint64_t count;
+ int entsize;
+
+ if (section == NULL
+ || section->sh_type != SHT_RELR
+ || section->sh_size == 0)
+ return 0;
+
+ entsize = section->sh_entsize;
+ if (entsize == 0)
+ entsize = is_32bit_elf
+ ? sizeof (Elf32_External_Relr) : sizeof (Elf64_External_Relr);
+ else if (entsize != sizeof (Elf32_External_Relr)
+ && entsize != sizeof (Elf64_External_Relr))
+ return 0;
+
+ nentries = section->sh_size / entsize;
+ if (nentries == 0)
+ return 0;
+
+ /* FIXME: This call to get_data duplicates one that follows in
+ dump_relr_relocations(). They could be combined into just
+ one call. */
+ relrs = get_data (NULL, filedata, section->sh_offset, 1,
+ section->sh_size, _("RELR relocation data"));
+ if (relrs == NULL)
+ return 0;
+
+ for (count = i = 0; i < nentries; i++)
+ {
+ uint64_t entry;
+
+ if (entsize == sizeof (Elf32_External_Relr))
+ entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
+ else
+ entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
+
+ if ((entry & 1) == 0)
+ {
+ ++ count;
+ }
+ else
+ {
+ if (entry == 1)
+ continue;
+
+ for (; entry >>= 1;)
+ if ((entry & 1) == 1)
+ ++ count;
+ }
+ }
+
+ free (relrs);
+ return count;
+}
+