This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
elf_backend_count_relocs
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sourceware dot org
- Date: Mon, 20 Oct 2008 21:36:24 +1030
- Subject: elf_backend_count_relocs
SPU is the only target to currently implement elf_backend_count_relocs,
so it makes sense to move code reading relocs into the backend. I
also have some further changes to spu_elf_count_relocs in the pipeline.
* elflink.c (bfd_elf_final_link): Move code reading relocs to..
* elf32-spu.c (spu_elf_count_relocs): ..here. Adjust params.
* elf-bfd.h (struct elf_backend_data): Update elf_backend_count_relocs
params.
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.267
diff -u -p -r1.267 elf-bfd.h
--- bfd/elf-bfd.h 20 Aug 2008 23:28:58 -0000 1.267
+++ bfd/elf-bfd.h 17 Oct 2008 05:43:54 -0000
@@ -1012,7 +1012,7 @@ struct elf_backend_data
/* Count relocations. Not called for relocatable links
or if all relocs are being preserved in the output. */
unsigned int (*elf_backend_count_relocs)
- (asection *, Elf_Internal_Rela *);
+ (struct bfd_link_info *, asection *);
/* This function, if defined, is called when an NT_PRSTATUS note is found
in a core file. */
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.313
diff -u -p -r1.313 elflink.c
--- bfd/elflink.c 3 Oct 2008 09:40:48 -0000 1.313
+++ bfd/elflink.c 17 Oct 2008 05:44:16 -0000
@@ -10095,22 +10095,7 @@ bfd_elf_final_link (bfd *abfd, struct bf
if (info->relocatable || info->emitrelocations)
reloc_count = sec->reloc_count;
else if (bed->elf_backend_count_relocs)
- {
- Elf_Internal_Rela * relocs;
-
- relocs = _bfd_elf_link_read_relocs (sec->owner, sec,
- NULL, NULL,
- info->keep_memory);
-
- if (relocs != NULL)
- {
- reloc_count
- = (*bed->elf_backend_count_relocs) (sec, relocs);
-
- if (elf_section_data (sec)->relocs != relocs)
- free (relocs);
- }
- }
+ reloc_count = (*bed->elf_backend_count_relocs) (info, sec);
if (sec->rawsize > max_contents_size)
max_contents_size = sec->rawsize;
Index: bfd/elf32-spu.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-spu.c,v
retrieving revision 1.52
diff -u -p -r1.52 elf32-spu.c
--- bfd/elf32-spu.c 29 Sep 2008 14:12:02 -0000 1.52
+++ bfd/elf32-spu.c 17 Oct 2008 05:44:04 -0000
@@ -3895,16 +4349,27 @@ spu_elf_final_link (bfd *output_bfd, str
that need to be emitted. */
static unsigned int
-spu_elf_count_relocs (asection *sec, Elf_Internal_Rela *relocs)
+spu_elf_count_relocs (struct bfd_link_info *info, asection *sec)
{
+ Elf_Internal_Rela *relocs;
unsigned int count = 0;
- Elf_Internal_Rela *relend = relocs + sec->reloc_count;
- for (; relocs < relend; relocs++)
+ relocs = _bfd_elf_link_read_relocs (sec->owner, sec, NULL, NULL,
+ info->keep_memory);
+ if (relocs != NULL)
{
- int r_type = ELF32_R_TYPE (relocs->r_info);
- if (r_type == R_SPU_PPU32 || r_type == R_SPU_PPU64)
- ++count;
+ Elf_Internal_Rela *rel;
+ Elf_Internal_Rela *relend = relocs + sec->reloc_count;
+
+ for (rel = relocs; rel < relend; rel++)
+ {
+ int r_type = ELF32_R_TYPE (rel->r_info);
+ if (r_type == R_SPU_PPU32 || r_type == R_SPU_PPU64)
+ ++count;
+ }
+
+ if (elf_section_data (sec)->relocs != relocs)
+ free (relocs);
}
return count;
--
Alan Modra
Australia Development Lab, IBM