@@ -717,84 +717,84 @@ static int64_t getTlsTpOffset(const Symbol &s) {
717
717
}
718
718
}
719
719
720
- uint64_t InputSectionBase::getRelocTargetVA (const InputFile *file, RelType type ,
721
- int64_t a, uint64_t p,
722
- const Symbol &sym, RelExpr expr) {
723
- switch (expr) {
720
+ uint64_t InputSectionBase::getRelocTargetVA (Ctx &ctx, const Relocation &r ,
721
+ uint64_t p) const {
722
+ int64_t a = r. addend ;
723
+ switch (r. expr ) {
724
724
case R_ABS:
725
725
case R_DTPREL:
726
726
case R_RELAX_TLS_LD_TO_LE_ABS:
727
727
case R_RELAX_GOT_PC_NOPIC:
728
728
case R_AARCH64_AUTH:
729
729
case R_RISCV_ADD:
730
730
case R_RISCV_LEB128:
731
- return sym. getVA (a);
731
+ return r. sym -> getVA (a);
732
732
case R_ADDEND:
733
733
return a;
734
734
case R_RELAX_HINT:
735
735
return 0 ;
736
736
case R_ARM_SBREL:
737
- return sym. getVA (a) - getARMStaticBase (sym);
737
+ return r. sym -> getVA (a) - getARMStaticBase (*r. sym );
738
738
case R_GOT:
739
739
case R_RELAX_TLS_GD_TO_IE_ABS:
740
- return sym. getGotVA () + a;
740
+ return r. sym -> getGotVA () + a;
741
741
case R_LOONGARCH_GOT:
742
- // The LoongArch TLS GD relocs reuse the R_LARCH_GOT_PC_LO12 reloc type
742
+ // The LoongArch TLS GD relocs reuse the R_LARCH_GOT_PC_LO12 reloc r. type
743
743
// for their page offsets. The arithmetics are different in the TLS case
744
744
// so we have to duplicate some logic here.
745
- if (sym. hasFlag (NEEDS_TLSGD) && type != R_LARCH_TLS_IE_PC_LO12)
745
+ if (r. sym -> hasFlag (NEEDS_TLSGD) && r. type != R_LARCH_TLS_IE_PC_LO12)
746
746
// Like R_LOONGARCH_TLSGD_PAGE_PC but taking the absolute value.
747
- return ctx.in .got ->getGlobalDynAddr (sym) + a;
748
- return getRelocTargetVA (file, type, a, p, sym, R_GOT) ;
747
+ return ctx.in .got ->getGlobalDynAddr (*r. sym ) + a;
748
+ return r. sym -> getGotVA () + a ;
749
749
case R_GOTONLY_PC:
750
750
return ctx.in .got ->getVA () + a - p;
751
751
case R_GOTPLTONLY_PC:
752
752
return ctx.in .gotPlt ->getVA () + a - p;
753
753
case R_GOTREL:
754
754
case R_PPC64_RELAX_TOC:
755
- return sym. getVA (a) - ctx.in .got ->getVA ();
755
+ return r. sym -> getVA (a) - ctx.in .got ->getVA ();
756
756
case R_GOTPLTREL:
757
- return sym. getVA (a) - ctx.in .gotPlt ->getVA ();
757
+ return r. sym -> getVA (a) - ctx.in .gotPlt ->getVA ();
758
758
case R_GOTPLT:
759
759
case R_RELAX_TLS_GD_TO_IE_GOTPLT:
760
- return sym. getGotVA () + a - ctx.in .gotPlt ->getVA ();
760
+ return r. sym -> getGotVA () + a - ctx.in .gotPlt ->getVA ();
761
761
case R_TLSLD_GOT_OFF:
762
762
case R_GOT_OFF:
763
763
case R_RELAX_TLS_GD_TO_IE_GOT_OFF:
764
- return sym. getGotOffset () + a;
764
+ return r. sym -> getGotOffset () + a;
765
765
case R_AARCH64_GOT_PAGE_PC:
766
766
case R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC:
767
- return getAArch64Page (sym. getGotVA () + a) - getAArch64Page (p);
767
+ return getAArch64Page (r. sym -> getGotVA () + a) - getAArch64Page (p);
768
768
case R_AARCH64_GOT_PAGE:
769
- return sym. getGotVA () + a - getAArch64Page (ctx.in .got ->getVA ());
769
+ return r. sym -> getGotVA () + a - getAArch64Page (ctx.in .got ->getVA ());
770
770
case R_GOT_PC:
771
771
case R_RELAX_TLS_GD_TO_IE:
772
- return sym. getGotVA () + a - p;
772
+ return r. sym -> getGotVA () + a - p;
773
773
case R_GOTPLT_GOTREL:
774
- return sym. getGotPltVA () + a - ctx.in .got ->getVA ();
774
+ return r. sym -> getGotPltVA () + a - ctx.in .got ->getVA ();
775
775
case R_GOTPLT_PC:
776
- return sym. getGotPltVA () + a - p;
776
+ return r. sym -> getGotPltVA () + a - p;
777
777
case R_LOONGARCH_GOT_PAGE_PC:
778
- if (sym. hasFlag (NEEDS_TLSGD))
779
- return getLoongArchPageDelta (ctx.in .got ->getGlobalDynAddr (sym) + a, p,
780
- type);
781
- return getLoongArchPageDelta (sym. getGotVA () + a, p, type);
778
+ if (r. sym -> hasFlag (NEEDS_TLSGD))
779
+ return getLoongArchPageDelta (ctx.in .got ->getGlobalDynAddr (*r. sym ) + a, p,
780
+ r. type );
781
+ return getLoongArchPageDelta (r. sym -> getGotVA () + a, p, r. type );
782
782
case R_MIPS_GOTREL:
783
- return sym. getVA (a) - ctx.in .mipsGot ->getGp (file);
783
+ return r. sym -> getVA (a) - ctx.in .mipsGot ->getGp (file);
784
784
case R_MIPS_GOT_GP:
785
785
return ctx.in .mipsGot ->getGp (file) + a;
786
786
case R_MIPS_GOT_GP_PC: {
787
- // R_MIPS_LO16 expression has R_MIPS_GOT_GP_PC type iif the target
787
+ // R_MIPS_LO16 expression has R_MIPS_GOT_GP_PC r. type iif the target
788
788
// is _gp_disp symbol. In that case we should use the following
789
789
// formula for calculation "AHL + GP - P + 4". For details see p. 4-19 at
790
790
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
791
791
// microMIPS variants of these relocations use slightly different
792
792
// expressions: AHL + GP - P + 3 for %lo() and AHL + GP - P - 1 for %hi()
793
793
// to correctly handle less-significant bit of the microMIPS symbol.
794
794
uint64_t v = ctx.in .mipsGot ->getGp (file) + a - p;
795
- if (type == R_MIPS_LO16 || type == R_MICROMIPS_LO16)
795
+ if (r. type == R_MIPS_LO16 || r. type == R_MICROMIPS_LO16)
796
796
v += 4 ;
797
- if (type == R_MICROMIPS_LO16 || type == R_MICROMIPS_HI16)
797
+ if (r. type == R_MICROMIPS_LO16 || r. type == R_MICROMIPS_HI16)
798
798
v -= 1 ;
799
799
return v;
800
800
}
@@ -803,81 +803,80 @@ uint64_t InputSectionBase::getRelocTargetVA(const InputFile *file, RelType type,
803
803
// should be initialized by 'page address'. This address is high 16-bits
804
804
// of sum the symbol's value and the addend.
805
805
return ctx.in .mipsGot ->getVA () +
806
- ctx.in .mipsGot ->getPageEntryOffset (file, sym, a) -
806
+ ctx.in .mipsGot ->getPageEntryOffset (file, *r. sym , a) -
807
807
ctx.in .mipsGot ->getGp (file);
808
808
case R_MIPS_GOT_OFF:
809
809
case R_MIPS_GOT_OFF32:
810
810
// In case of MIPS if a GOT relocation has non-zero addend this addend
811
811
// should be applied to the GOT entry content not to the GOT entry offset.
812
- // That is why we use separate expression type.
812
+ // That is why we use separate expression r. type.
813
813
return ctx.in .mipsGot ->getVA () +
814
- ctx.in .mipsGot ->getSymEntryOffset (file, sym, a) -
814
+ ctx.in .mipsGot ->getSymEntryOffset (file, *r. sym , a) -
815
815
ctx.in .mipsGot ->getGp (file);
816
816
case R_MIPS_TLSGD:
817
817
return ctx.in .mipsGot ->getVA () +
818
- ctx.in .mipsGot ->getGlobalDynOffset (file, sym) -
818
+ ctx.in .mipsGot ->getGlobalDynOffset (file, *r. sym ) -
819
819
ctx.in .mipsGot ->getGp (file);
820
820
case R_MIPS_TLSLD:
821
821
return ctx.in .mipsGot ->getVA () + ctx.in .mipsGot ->getTlsIndexOffset (file) -
822
822
ctx.in .mipsGot ->getGp (file);
823
823
case R_AARCH64_PAGE_PC: {
824
- uint64_t val = sym. isUndefWeak () ? p + a : sym. getVA (a);
824
+ uint64_t val = r. sym -> isUndefWeak () ? p + a : r. sym -> getVA (a);
825
825
return getAArch64Page (val) - getAArch64Page (p);
826
826
}
827
827
case R_RISCV_PC_INDIRECT: {
828
- if (const Relocation *hiRel = getRISCVPCRelHi20 (&sym, a))
829
- return getRelocTargetVA (file, hiRel->type , hiRel->addend , sym.getVA (),
830
- *hiRel->sym , hiRel->expr );
828
+ if (const Relocation *hiRel = getRISCVPCRelHi20 (r.sym , a))
829
+ return getRelocTargetVA (ctx, *hiRel, r.sym ->getVA ());
831
830
return 0 ;
832
831
}
833
832
case R_LOONGARCH_PAGE_PC:
834
- return getLoongArchPageDelta (sym. getVA (a), p, type);
833
+ return getLoongArchPageDelta (r. sym -> getVA (a), p, r. type );
835
834
case R_PC:
836
835
case R_ARM_PCA: {
837
836
uint64_t dest;
838
- if (expr == R_ARM_PCA)
837
+ if (r. expr == R_ARM_PCA)
839
838
// Some PC relative ARM (Thumb) relocations align down the place.
840
839
p = p & 0xfffffffc ;
841
- if (sym. isUndefined ()) {
840
+ if (r. sym -> isUndefined ()) {
842
841
// On ARM and AArch64 a branch to an undefined weak resolves to the next
843
842
// instruction, otherwise the place. On RISC-V, resolve an undefined weak
844
843
// to the same instruction to cause an infinite loop (making the user
845
844
// aware of the issue) while ensuring no overflow.
846
845
// Note: if the symbol is hidden, its binding has been converted to local,
847
846
// so we just check isUndefined() here.
848
847
if (ctx.arg .emachine == EM_ARM)
849
- dest = getARMUndefinedRelativeWeakVA (type, a, p);
848
+ dest = getARMUndefinedRelativeWeakVA (r. type , a, p);
850
849
else if (ctx.arg .emachine == EM_AARCH64)
851
- dest = getAArch64UndefinedRelativeWeakVA (type, p) + a;
850
+ dest = getAArch64UndefinedRelativeWeakVA (r. type , p) + a;
852
851
else if (ctx.arg .emachine == EM_PPC)
853
852
dest = p;
854
853
else if (ctx.arg .emachine == EM_RISCV)
855
- dest = getRISCVUndefinedRelativeWeakVA (type, p) + a;
854
+ dest = getRISCVUndefinedRelativeWeakVA (r. type , p) + a;
856
855
else
857
- dest = sym. getVA (a);
856
+ dest = r. sym -> getVA (a);
858
857
} else {
859
- dest = sym. getVA (a);
858
+ dest = r. sym -> getVA (a);
860
859
}
861
860
return dest - p;
862
861
}
863
862
case R_PLT:
864
- return sym. getPltVA () + a;
863
+ return r. sym -> getPltVA () + a;
865
864
case R_PLT_PC:
866
865
case R_PPC64_CALL_PLT:
867
- return sym. getPltVA () + a - p;
866
+ return r. sym -> getPltVA () + a - p;
868
867
case R_LOONGARCH_PLT_PAGE_PC:
869
- return getLoongArchPageDelta (sym. getPltVA () + a, p, type);
868
+ return getLoongArchPageDelta (r. sym -> getPltVA () + a, p, r. type );
870
869
case R_PLT_GOTPLT:
871
- return sym. getPltVA () + a - ctx.in .gotPlt ->getVA ();
870
+ return r. sym -> getPltVA () + a - ctx.in .gotPlt ->getVA ();
872
871
case R_PLT_GOTREL:
873
- return sym. getPltVA () + a - ctx.in .got ->getVA ();
872
+ return r. sym -> getPltVA () + a - ctx.in .got ->getVA ();
874
873
case R_PPC32_PLTREL:
875
874
// R_PPC_PLTREL24 uses the addend (usually 0 or 0x8000) to indicate r30
876
875
// stores _GLOBAL_OFFSET_TABLE_ or .got2+0x8000. The addend is ignored for
877
876
// target VA computation.
878
- return sym. getPltVA () - p;
877
+ return r. sym -> getPltVA () - p;
879
878
case R_PPC64_CALL: {
880
- uint64_t symVA = sym. getVA (a);
879
+ uint64_t symVA = r. sym -> getVA (a);
881
880
// If we have an undefined weak symbol, we might get here with a symbol
882
881
// address of zero. That could overflow, but the code must be unreachable,
883
882
// so don't bother doing anything at all.
@@ -890,13 +889,13 @@ uint64_t InputSectionBase::getRelocTargetVA(const InputFile *file, RelType type,
890
889
// the callee. For local calls the caller and callee share the same
891
890
// TOC base and so the TOC pointer initialization code should be skipped by
892
891
// branching to the local entry point.
893
- return symVA - p + getPPC64GlobalEntryToLocalEntryOffset (sym. stOther );
892
+ return symVA - p + getPPC64GlobalEntryToLocalEntryOffset (r. sym -> stOther );
894
893
}
895
894
case R_PPC64_TOCBASE:
896
895
return getPPC64TocBase (ctx) + a;
897
896
case R_RELAX_GOT_PC:
898
897
case R_PPC64_RELAX_GOT_PC:
899
- return sym. getVA (a) - p;
898
+ return r. sym -> getVA (a) - p;
900
899
case R_RELAX_TLS_GD_TO_LE:
901
900
case R_RELAX_TLS_IE_TO_LE:
902
901
case R_RELAX_TLS_LD_TO_LE:
@@ -905,36 +904,37 @@ uint64_t InputSectionBase::getRelocTargetVA(const InputFile *file, RelType type,
905
904
// --noinhibit-exec, even a non-weak undefined reference may reach here.
906
905
// Just return A, which matches R_ABS, and the behavior of some dynamic
907
906
// loaders.
908
- if (sym. isUndefined ())
907
+ if (r. sym -> isUndefined ())
909
908
return a;
910
- return getTlsTpOffset (sym) + a;
909
+ return getTlsTpOffset (*r. sym ) + a;
911
910
case R_RELAX_TLS_GD_TO_LE_NEG:
912
911
case R_TPREL_NEG:
913
- if (sym. isUndefined ())
912
+ if (r. sym -> isUndefined ())
914
913
return a;
915
- return -getTlsTpOffset (sym) + a;
914
+ return -getTlsTpOffset (*r. sym ) + a;
916
915
case R_SIZE:
917
- return sym. getSize () + a;
916
+ return r. sym -> getSize () + a;
918
917
case R_TLSDESC:
919
- return ctx.in .got ->getTlsDescAddr (sym) + a;
918
+ return ctx.in .got ->getTlsDescAddr (*r. sym ) + a;
920
919
case R_TLSDESC_PC:
921
- return ctx.in .got ->getTlsDescAddr (sym) + a - p;
920
+ return ctx.in .got ->getTlsDescAddr (*r. sym ) + a - p;
922
921
case R_TLSDESC_GOTPLT:
923
- return ctx.in .got ->getTlsDescAddr (sym) + a - ctx.in .gotPlt ->getVA ();
922
+ return ctx.in .got ->getTlsDescAddr (*r. sym ) + a - ctx.in .gotPlt ->getVA ();
924
923
case R_AARCH64_TLSDESC_PAGE:
925
- return getAArch64Page (ctx.in .got ->getTlsDescAddr (sym) + a) -
924
+ return getAArch64Page (ctx.in .got ->getTlsDescAddr (*r. sym ) + a) -
926
925
getAArch64Page (p);
927
926
case R_LOONGARCH_TLSDESC_PAGE_PC:
928
- return getLoongArchPageDelta (ctx.in .got ->getTlsDescAddr (sym) + a, p, type);
927
+ return getLoongArchPageDelta (ctx.in .got ->getTlsDescAddr (*r.sym ) + a, p,
928
+ r.type );
929
929
case R_TLSGD_GOT:
930
- return ctx.in .got ->getGlobalDynOffset (sym) + a;
930
+ return ctx.in .got ->getGlobalDynOffset (*r. sym ) + a;
931
931
case R_TLSGD_GOTPLT:
932
- return ctx.in .got ->getGlobalDynAddr (sym) + a - ctx.in .gotPlt ->getVA ();
932
+ return ctx.in .got ->getGlobalDynAddr (*r. sym ) + a - ctx.in .gotPlt ->getVA ();
933
933
case R_TLSGD_PC:
934
- return ctx.in .got ->getGlobalDynAddr (sym) + a - p;
934
+ return ctx.in .got ->getGlobalDynAddr (*r. sym ) + a - p;
935
935
case R_LOONGARCH_TLSGD_PAGE_PC:
936
- return getLoongArchPageDelta (ctx.in .got ->getGlobalDynAddr (sym) + a, p,
937
- type);
936
+ return getLoongArchPageDelta (ctx.in .got ->getGlobalDynAddr (*r. sym ) + a, p,
937
+ r. type );
938
938
case R_TLSLD_GOTPLT:
939
939
return ctx.in .got ->getVA () + ctx.in .got ->getTlsIndexOff () + a -
940
940
ctx.in .gotPlt ->getVA ();
0 commit comments