@@ -2529,7 +2529,7 @@ loongarch_reloc_is_fatal (struct bfd_link_info *info,
2529
2529
({ \
2530
2530
bfd_vma __lo = (relocation & (bfd_vma)0xfff); \
2531
2531
relocation = (relocation & ~(bfd_vma)0xfff) \
2532
- - (pc & ~(bfd_vma)0xfff); \
2532
+ - ((pc) & ~(bfd_vma)0xfff); \
2533
2533
if (__lo > 0x7ff) \
2534
2534
relocation += (0x1000 - 0x100000000); \
2535
2535
if (relocation & 0x80000000) \
@@ -3534,14 +3534,16 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
3534
3534
}
3535
3535
break ;
3536
3536
3537
- case R_LARCH_PCALA64_LO20 :
3538
3537
case R_LARCH_PCALA64_HI12 :
3538
+ pc -= 4 ;
3539
+ /* Fall through. */
3540
+ case R_LARCH_PCALA64_LO20 :
3539
3541
if (h && h -> plt .offset != MINUS_ONE )
3540
3542
relocation = sec_addr (plt ) + h -> plt .offset ;
3541
3543
else
3542
3544
relocation += rel -> r_addend ;
3543
3545
3544
- RELOCATE_CALC_PC64_HI32 (relocation , pc );
3546
+ RELOCATE_CALC_PC64_HI32 (relocation , pc - 8 );
3545
3547
3546
3548
break ;
3547
3549
@@ -3668,9 +3670,10 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
3668
3670
relocation = got_off + sec_addr (got );
3669
3671
}
3670
3672
3671
- if (r_type == R_LARCH_GOT64_PC_HI12
3672
- || r_type == R_LARCH_GOT64_PC_LO20 )
3673
- RELOCATE_CALC_PC64_HI32 (relocation , pc );
3673
+ if (r_type == R_LARCH_GOT64_PC_HI12 )
3674
+ RELOCATE_CALC_PC64_HI32 (relocation , pc - 12 );
3675
+ else if (r_type == R_LARCH_GOT64_PC_LO20 )
3676
+ RELOCATE_CALC_PC64_HI32 (relocation , pc - 8 );
3674
3677
3675
3678
break ;
3676
3679
@@ -3871,13 +3874,14 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
3871
3874
/* Use both TLS_GD and TLS_DESC. */
3872
3875
if ((tls_type & GOT_TLS_GD ) && (tls_type & GOT_TLS_GDESC ))
3873
3876
relocation += 2 * GOT_ENTRY_SIZE ;
3874
- }
3875
3877
3876
- if (r_type == R_LARCH_TLS_DESC64_PC_LO20
3877
- || r_type == R_LARCH_TLS_DESC64_PC_HI12 )
3878
- RELOCATE_CALC_PC64_HI32 (relocation , pc );
3878
+ if (r_type == R_LARCH_TLS_DESC64_PC_LO20 )
3879
+ RELOCATE_CALC_PC64_HI32 (relocation , pc - 8 );
3880
+ else if (r_type == R_LARCH_TLS_DESC64_PC_HI12 )
3881
+ RELOCATE_CALC_PC64_HI32 (relocation , pc - 12 );
3879
3882
3880
3883
break ;
3884
+ }
3881
3885
3882
3886
case R_LARCH_TLS_DESC_LD :
3883
3887
case R_LARCH_TLS_DESC_CALL :
@@ -3906,9 +3910,10 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
3906
3910
else if (GOT_TLS_GD_ANY_P (tls_type ) && (tls_type & GOT_TLS_IE ))
3907
3911
relocation += 2 * GOT_ENTRY_SIZE ;
3908
3912
3909
- if (r_type == R_LARCH_TLS_IE64_PC_LO20
3910
- || r_type == R_LARCH_TLS_IE64_PC_HI12 )
3911
- RELOCATE_CALC_PC64_HI32 (relocation , pc );
3913
+ if (r_type == R_LARCH_TLS_IE64_PC_LO20 )
3914
+ RELOCATE_CALC_PC64_HI32 (relocation , pc - 8 );
3915
+ else if (r_type == R_LARCH_TLS_IE64_PC_HI12 )
3916
+ RELOCATE_CALC_PC64_HI32 (relocation , pc - 12 );
3912
3917
3913
3918
break ;
3914
3919
0 commit comments