@@ -6935,6 +6935,23 @@ is_insn_dq_form (unsigned int insn)
69356935 && (insn & 3 ) == 1 ));
69366936}
69376937
6938+ static bool
6939+ swap_reloc_out (bfd * obfd , Elf_Internal_Rela * rel , bfd_byte * loc , asection * s )
6940+ {
6941+ if ((size_t ) (loc - s -> contents ) >= s -> size )
6942+ return false;
6943+ bfd_elf32_swap_reloca_out (obfd , rel , loc );
6944+ return true;
6945+ }
6946+
6947+ static bool
6948+ count_and_swap_reloc_out (bfd * obfd , Elf_Internal_Rela * rel , asection * s )
6949+ {
6950+ bfd_byte * loc = s -> contents ;
6951+ loc += s -> reloc_count ++ * sizeof (Elf32_External_Rela );
6952+ return swap_reloc_out (obfd , rel , loc , s );
6953+ }
6954+
69386955/* The RELOCATE_SECTION function is called by the ELF backend linker
69396956 to handle the relocations for a section.
69406957
@@ -7806,7 +7823,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
78067823 : sym -> st_shndx != SHN_ABS )))
78077824 {
78087825 asection * rsec = htab -> elf .srelgot ;
7809- bfd_byte * loc ;
78107826
78117827 if (ifunc != NULL )
78127828 {
@@ -7825,11 +7841,9 @@ ppc_elf_relocate_section (bfd *output_bfd,
78257841 outrel .r_info = ELF32_R_INFO (indx , R_PPC_DTPMOD32 );
78267842 if (tls_ty == (TLS_TLS | TLS_GD ))
78277843 {
7828- loc = rsec -> contents ;
7829- loc += (rsec -> reloc_count ++
7830- * sizeof (Elf32_External_Rela ));
7831- bfd_elf32_swap_reloca_out (output_bfd ,
7832- & outrel , loc );
7844+ BFD_ASSERT (count_and_swap_reloc_out (output_bfd ,
7845+ & outrel ,
7846+ rsec ));
78337847 outrel .r_offset += 4 ;
78347848 outrel .r_info
78357849 = ELF32_R_INFO (indx , R_PPC_DTPREL32 );
@@ -7856,10 +7870,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
78567870 outrel .r_addend -= htab -> elf .tls_sec -> vma ;
78577871 }
78587872 }
7859- loc = rsec -> contents ;
7860- loc += (rsec -> reloc_count ++
7861- * sizeof (Elf32_External_Rela ));
7862- bfd_elf32_swap_reloca_out (output_bfd , & outrel , loc );
7873+ BFD_ASSERT (count_and_swap_reloc_out (output_bfd ,
7874+ & outrel , rsec ));
78637875 }
78647876
78657877 /* Init the .got section contents if we're not
@@ -8089,7 +8101,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
80898101 && h -> dyn_relocs != NULL ))
80908102 {
80918103 int skip ;
8092- bfd_byte * loc ;
80938104 asection * sreloc ;
80948105 long indx = 0 ;
80958106
@@ -8221,9 +8232,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
82218232 if (sreloc == NULL )
82228233 return false;
82238234
8224- loc = sreloc -> contents ;
8225- loc += sreloc -> reloc_count ++ * sizeof (Elf32_External_Rela );
8226- bfd_elf32_swap_reloca_out (output_bfd , & outrel , loc );
8235+ BFD_ASSERT (count_and_swap_reloc_out (output_bfd , & outrel ,
8236+ sreloc ));
82278237
82288238 if (skip == -1 )
82298239 goto copy_reloc ;
@@ -9573,7 +9583,8 @@ write_global_sym_plt (struct elf_link_hash_entry *h, void *inf)
95739583 rela .r_info = ELF32_R_INFO (htab -> elf .hgot -> indx ,
95749584 R_PPC_ADDR16_HA );
95759585 rela .r_addend = got_offset ;
9576- bfd_elf32_swap_reloca_out (info -> output_bfd , & rela , loc );
9586+ BFD_ASSERT (swap_reloc_out (info -> output_bfd , & rela , loc ,
9587+ htab -> srelplt2 ));
95779588 loc += sizeof (Elf32_External_Rela );
95789589
95799590 /* Provide the @l relocation for the second instruction. */
@@ -9583,7 +9594,8 @@ write_global_sym_plt (struct elf_link_hash_entry *h, void *inf)
95839594 rela .r_info = ELF32_R_INFO (htab -> elf .hgot -> indx ,
95849595 R_PPC_ADDR16_LO );
95859596 rela .r_addend = got_offset ;
9586- bfd_elf32_swap_reloca_out (info -> output_bfd , & rela , loc );
9597+ BFD_ASSERT (swap_reloc_out (info -> output_bfd , & rela , loc ,
9598+ htab -> srelplt2 ));
95879599 loc += sizeof (Elf32_External_Rela );
95889600
95899601 /* Provide a relocation for the GOT entry corresponding to this
@@ -9594,7 +9606,8 @@ write_global_sym_plt (struct elf_link_hash_entry *h, void *inf)
95949606 rela .r_info = ELF32_R_INFO (htab -> elf .hplt -> indx ,
95959607 R_PPC_ADDR32 );
95969608 rela .r_addend = ent -> plt .offset + 16 ;
9597- bfd_elf32_swap_reloca_out (info -> output_bfd , & rela , loc );
9609+ BFD_ASSERT (swap_reloc_out (info -> output_bfd , & rela , loc ,
9610+ htab -> srelplt2 ));
95989611 }
95999612
96009613 /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
@@ -9676,7 +9689,8 @@ write_global_sym_plt (struct elf_link_hash_entry *h, void *inf)
96769689 if (h -> type == STT_GNU_IFUNC && is_static_defined (h ))
96779690 htab -> maybe_local_ifunc_resolver = 1 ;
96789691 }
9679- bfd_elf32_swap_reloca_out (info -> output_bfd , & rela , loc );
9692+ BFD_ASSERT (swap_reloc_out (info -> output_bfd , & rela ,
9693+ loc , relplt ));
96809694 }
96819695 doneone = true;
96829696 }
@@ -9793,9 +9807,8 @@ ppc_finish_symbols (struct bfd_link_info *info)
97939807 + plt -> output_offset
97949808 + plt -> output_section -> vma );
97959809 rela .r_addend = val ;
9796- loc = relplt -> contents + (relplt -> reloc_count ++
9797- * sizeof (Elf32_External_Rela ));
9798- bfd_elf32_swap_reloca_out (info -> output_bfd , & rela , loc );
9810+ BFD_ASSERT (count_and_swap_reloc_out (info -> output_bfd , & rela ,
9811+ relplt ));
97999812
98009813 p = (unsigned char * ) htab -> glink -> contents + ent -> glink_offset ;
98019814 write_glink_stub (NULL , ent , htab -> elf .iplt , p , info );
@@ -9879,7 +9892,6 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
98799892 {
98809893 asection * s ;
98819894 Elf_Internal_Rela rela ;
9882- bfd_byte * loc ;
98839895
98849896 /* This symbols needs a copy reloc. Set it up. */
98859897
@@ -9900,8 +9912,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
99009912 rela .r_offset = SYM_VAL (h );
99019913 rela .r_info = ELF32_R_INFO (h -> dynindx , R_PPC_COPY );
99029914 rela .r_addend = 0 ;
9903- loc = s -> contents + s -> reloc_count ++ * sizeof (Elf32_External_Rela );
9904- bfd_elf32_swap_reloca_out (output_bfd , & rela , loc );
9915+ BFD_ASSERT (count_and_swap_reloc_out (output_bfd , & rela , s ));
99059916 }
99069917
99079918#ifdef DEBUG
@@ -10105,7 +10116,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
1010510116 + 2 );
1010610117 rela .r_info = ELF32_R_INFO (htab -> elf .hgot -> indx , R_PPC_ADDR16_HA );
1010710118 rela .r_addend = 0 ;
10108- bfd_elf32_swap_reloca_out ( output_bfd , & rela , loc );
10119+ BFD_ASSERT ( swap_reloc_out ( output_bfd , & rela , loc , htab -> srelplt2 ) );
1010910120 loc += sizeof (Elf32_External_Rela );
1011010121
1011110122 /* Output the @l relocation for the second instruction. */
@@ -10114,7 +10125,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
1011410125 + 6 );
1011510126 rela .r_info = ELF32_R_INFO (htab -> elf .hgot -> indx , R_PPC_ADDR16_LO );
1011610127 rela .r_addend = 0 ;
10117- bfd_elf32_swap_reloca_out ( output_bfd , & rela , loc );
10128+ BFD_ASSERT ( swap_reloc_out ( output_bfd , & rela , loc , htab -> srelplt2 ) );
1011810129 loc += sizeof (Elf32_External_Rela );
1011910130
1012010131 /* Fix up the remaining relocations. They may have the wrong
0 commit comments