@@ -6935,6 +6935,23 @@ is_insn_dq_form (unsigned int insn)
6935
6935
&& (insn & 3 ) == 1 ));
6936
6936
}
6937
6937
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
+
6938
6955
/* The RELOCATE_SECTION function is called by the ELF backend linker
6939
6956
to handle the relocations for a section.
6940
6957
@@ -7806,7 +7823,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
7806
7823
: sym -> st_shndx != SHN_ABS )))
7807
7824
{
7808
7825
asection * rsec = htab -> elf .srelgot ;
7809
- bfd_byte * loc ;
7810
7826
7811
7827
if (ifunc != NULL )
7812
7828
{
@@ -7825,11 +7841,9 @@ ppc_elf_relocate_section (bfd *output_bfd,
7825
7841
outrel .r_info = ELF32_R_INFO (indx , R_PPC_DTPMOD32 );
7826
7842
if (tls_ty == (TLS_TLS | TLS_GD ))
7827
7843
{
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 ));
7833
7847
outrel .r_offset += 4 ;
7834
7848
outrel .r_info
7835
7849
= ELF32_R_INFO (indx , R_PPC_DTPREL32 );
@@ -7856,10 +7870,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
7856
7870
outrel .r_addend -= htab -> elf .tls_sec -> vma ;
7857
7871
}
7858
7872
}
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 ));
7863
7875
}
7864
7876
7865
7877
/* Init the .got section contents if we're not
@@ -8089,7 +8101,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
8089
8101
&& h -> dyn_relocs != NULL ))
8090
8102
{
8091
8103
int skip ;
8092
- bfd_byte * loc ;
8093
8104
asection * sreloc ;
8094
8105
long indx = 0 ;
8095
8106
@@ -8221,9 +8232,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
8221
8232
if (sreloc == NULL )
8222
8233
return false;
8223
8234
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 ));
8227
8237
8228
8238
if (skip == -1 )
8229
8239
goto copy_reloc ;
@@ -9573,7 +9583,8 @@ write_global_sym_plt (struct elf_link_hash_entry *h, void *inf)
9573
9583
rela .r_info = ELF32_R_INFO (htab -> elf .hgot -> indx ,
9574
9584
R_PPC_ADDR16_HA );
9575
9585
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 ));
9577
9588
loc += sizeof (Elf32_External_Rela );
9578
9589
9579
9590
/* Provide the @l relocation for the second instruction. */
@@ -9583,7 +9594,8 @@ write_global_sym_plt (struct elf_link_hash_entry *h, void *inf)
9583
9594
rela .r_info = ELF32_R_INFO (htab -> elf .hgot -> indx ,
9584
9595
R_PPC_ADDR16_LO );
9585
9596
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 ));
9587
9599
loc += sizeof (Elf32_External_Rela );
9588
9600
9589
9601
/* 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)
9594
9606
rela .r_info = ELF32_R_INFO (htab -> elf .hplt -> indx ,
9595
9607
R_PPC_ADDR32 );
9596
9608
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 ));
9598
9611
}
9599
9612
9600
9613
/* 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)
9676
9689
if (h -> type == STT_GNU_IFUNC && is_static_defined (h ))
9677
9690
htab -> maybe_local_ifunc_resolver = 1 ;
9678
9691
}
9679
- bfd_elf32_swap_reloca_out (info -> output_bfd , & rela , loc );
9692
+ BFD_ASSERT (swap_reloc_out (info -> output_bfd , & rela ,
9693
+ loc , relplt ));
9680
9694
}
9681
9695
doneone = true;
9682
9696
}
@@ -9793,9 +9807,8 @@ ppc_finish_symbols (struct bfd_link_info *info)
9793
9807
+ plt -> output_offset
9794
9808
+ plt -> output_section -> vma );
9795
9809
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 ));
9799
9812
9800
9813
p = (unsigned char * ) htab -> glink -> contents + ent -> glink_offset ;
9801
9814
write_glink_stub (NULL , ent , htab -> elf .iplt , p , info );
@@ -9879,7 +9892,6 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
9879
9892
{
9880
9893
asection * s ;
9881
9894
Elf_Internal_Rela rela ;
9882
- bfd_byte * loc ;
9883
9895
9884
9896
/* This symbols needs a copy reloc. Set it up. */
9885
9897
@@ -9900,8 +9912,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
9900
9912
rela .r_offset = SYM_VAL (h );
9901
9913
rela .r_info = ELF32_R_INFO (h -> dynindx , R_PPC_COPY );
9902
9914
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 ));
9905
9916
}
9906
9917
9907
9918
#ifdef DEBUG
@@ -10105,7 +10116,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
10105
10116
+ 2 );
10106
10117
rela .r_info = ELF32_R_INFO (htab -> elf .hgot -> indx , R_PPC_ADDR16_HA );
10107
10118
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 ) );
10109
10120
loc += sizeof (Elf32_External_Rela );
10110
10121
10111
10122
/* Output the @l relocation for the second instruction. */
@@ -10114,7 +10125,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
10114
10125
+ 6 );
10115
10126
rela .r_info = ELF32_R_INFO (htab -> elf .hgot -> indx , R_PPC_ADDR16_LO );
10116
10127
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 ) );
10118
10129
loc += sizeof (Elf32_External_Rela );
10119
10130
10120
10131
/* Fix up the remaining relocations. They may have the wrong
0 commit comments