@@ -774,60 +774,95 @@ static bool isPCRelativeRISCV(uint64_t Type) {
774
774
}
775
775
776
776
bool Relocation::isSupported (uint64_t Type) {
777
- if (Arch == Triple::aarch64)
777
+ switch (Arch) {
778
+ default :
779
+ return false ;
780
+ case Triple::aarch64:
778
781
return isSupportedAArch64 (Type);
779
- if (Arch == Triple::riscv64)
782
+ case Triple::riscv64:
780
783
return isSupportedRISCV (Type);
781
- return isSupportedX86 (Type);
784
+ case Triple::x86_64:
785
+ return isSupportedX86 (Type);
786
+ }
782
787
}
783
788
784
789
size_t Relocation::getSizeForType (uint64_t Type) {
785
- if (Arch == Triple::aarch64)
790
+ switch (Arch) {
791
+ default :
792
+ llvm_unreachable (" Unsupported architecture" );
793
+ case Triple::aarch64:
786
794
return getSizeForTypeAArch64 (Type);
787
- if (Arch == Triple::riscv64)
795
+ case Triple::riscv64:
788
796
return getSizeForTypeRISCV (Type);
789
- return getSizeForTypeX86 (Type);
797
+ case Triple::x86_64:
798
+ return getSizeForTypeX86 (Type);
799
+ }
790
800
}
791
801
792
802
bool Relocation::skipRelocationType (uint64_t Type) {
793
- if (Arch == Triple::aarch64)
803
+ switch (Arch) {
804
+ default :
805
+ llvm_unreachable (" Unsupported architecture" );
806
+ case Triple::aarch64:
794
807
return skipRelocationTypeAArch64 (Type);
795
- if (Arch == Triple::riscv64)
808
+ case Triple::riscv64:
796
809
return skipRelocationTypeRISCV (Type);
797
- return skipRelocationTypeX86 (Type);
810
+ case Triple::x86_64:
811
+ return skipRelocationTypeX86 (Type);
812
+ }
798
813
}
799
814
800
815
bool Relocation::skipRelocationProcess (uint64_t &Type, uint64_t Contents) {
801
- if (Arch == Triple::aarch64)
816
+ switch (Arch) {
817
+ default :
818
+ llvm_unreachable (" Unsupported architecture" );
819
+ case Triple::aarch64:
802
820
return skipRelocationProcessAArch64 (Type, Contents);
803
- if (Arch == Triple::riscv64)
804
- skipRelocationProcessRISCV (Type, Contents);
805
- return skipRelocationProcessX86 (Type, Contents);
821
+ case Triple::riscv64:
822
+ return skipRelocationProcessRISCV (Type, Contents);
823
+ case Triple::x86_64:
824
+ return skipRelocationProcessX86 (Type, Contents);
825
+ }
806
826
}
807
827
808
828
uint64_t Relocation::encodeValue (uint64_t Type, uint64_t Value, uint64_t PC) {
809
- if (Arch == Triple::aarch64)
829
+ switch (Arch) {
830
+ default :
831
+ llvm_unreachable (" Unsupported architecture" );
832
+ case Triple::aarch64:
810
833
return encodeValueAArch64 (Type, Value, PC);
811
- if (Arch == Triple::riscv64)
834
+ case Triple::riscv64:
812
835
return encodeValueRISCV (Type, Value, PC);
813
- return encodeValueX86 (Type, Value, PC);
836
+ case Triple::x86_64:
837
+ return encodeValueX86 (Type, Value, PC);
838
+ }
814
839
}
815
840
816
841
uint64_t Relocation::extractValue (uint64_t Type, uint64_t Contents,
817
842
uint64_t PC) {
818
- if (Arch == Triple::aarch64)
843
+ switch (Arch) {
844
+ default :
845
+ llvm_unreachable (" Unsupported architecture" );
846
+ case Triple::aarch64:
819
847
return extractValueAArch64 (Type, Contents, PC);
820
- if (Arch == Triple::riscv64)
848
+ case Triple::riscv64:
821
849
return extractValueRISCV (Type, Contents, PC);
822
- return extractValueX86 (Type, Contents, PC);
850
+ case Triple::x86_64:
851
+ return extractValueX86 (Type, Contents, PC);
852
+ }
823
853
}
824
854
825
855
bool Relocation::isGOT (uint64_t Type) {
826
- if (Arch == Triple::aarch64)
856
+ switch (Arch) {
857
+ default :
858
+ llvm_unreachable (" Unsupported architecture" );
859
+ case Triple::aarch64:
827
860
return isGOTAArch64 (Type);
828
- if (Arch == Triple::riscv64)
861
+ case Triple::riscv64:
829
862
return isGOTRISCV (Type);
830
- return isGOTX86 (Type);
863
+ case Triple::x86_64:
864
+ return isGOTX86 (Type);
865
+ }
831
866
}
832
867
833
868
bool Relocation::isX86GOTPCRELX (uint64_t Type) {
@@ -845,27 +880,42 @@ bool Relocation::isX86GOTPC64(uint64_t Type) {
845
880
bool Relocation::isNone (uint64_t Type) { return Type == getNone (); }
846
881
847
882
bool Relocation::isRelative (uint64_t Type) {
848
- if (Arch == Triple::aarch64)
883
+ switch (Arch) {
884
+ default :
885
+ llvm_unreachable (" Unsupported architecture" );
886
+ case Triple::aarch64:
849
887
return Type == ELF::R_AARCH64_RELATIVE;
850
- if (Arch == Triple::riscv64)
888
+ case Triple::riscv64:
851
889
return Type == ELF::R_RISCV_RELATIVE;
852
- return Type == ELF::R_X86_64_RELATIVE;
890
+ case Triple::x86_64:
891
+ return Type == ELF::R_X86_64_RELATIVE;
892
+ }
853
893
}
854
894
855
895
bool Relocation::isIRelative (uint64_t Type) {
856
- if (Arch == Triple::aarch64)
896
+ switch (Arch) {
897
+ default :
898
+ llvm_unreachable (" Unsupported architecture" );
899
+ case Triple::aarch64:
857
900
return Type == ELF::R_AARCH64_IRELATIVE;
858
- if (Arch == Triple::riscv64)
901
+ case Triple::riscv64:
859
902
llvm_unreachable (" not implemented" );
860
- return Type == ELF::R_X86_64_IRELATIVE;
903
+ case Triple::x86_64:
904
+ return Type == ELF::R_X86_64_IRELATIVE;
905
+ }
861
906
}
862
907
863
908
bool Relocation::isTLS (uint64_t Type) {
864
- if (Arch == Triple::aarch64)
909
+ switch (Arch) {
910
+ default :
911
+ llvm_unreachable (" Unsupported architecture" );
912
+ case Triple::aarch64:
865
913
return isTLSAArch64 (Type);
866
- if (Arch == Triple::riscv64)
914
+ case Triple::riscv64:
867
915
return isTLSRISCV (Type);
868
- return isTLSX86 (Type);
916
+ case Triple::x86_64:
917
+ return isTLSX86 (Type);
918
+ }
869
919
}
870
920
871
921
bool Relocation::isInstructionReference (uint64_t Type) {
@@ -882,49 +932,81 @@ bool Relocation::isInstructionReference(uint64_t Type) {
882
932
}
883
933
884
934
uint64_t Relocation::getNone () {
885
- if (Arch == Triple::aarch64)
935
+ switch (Arch) {
936
+ default :
937
+ llvm_unreachable (" Unsupported architecture" );
938
+ case Triple::aarch64:
886
939
return ELF::R_AARCH64_NONE;
887
- if (Arch == Triple::riscv64)
940
+ case Triple::riscv64:
888
941
return ELF::R_RISCV_NONE;
889
- return ELF::R_X86_64_NONE;
942
+ case Triple::x86_64:
943
+ return ELF::R_X86_64_NONE;
944
+ }
890
945
}
891
946
892
947
uint64_t Relocation::getPC32 () {
893
- if (Arch == Triple::aarch64)
948
+ switch (Arch) {
949
+ default :
950
+ llvm_unreachable (" Unsupported architecture" );
951
+ case Triple::aarch64:
894
952
return ELF::R_AARCH64_PREL32;
895
- if (Arch == Triple::riscv64)
953
+ case Triple::riscv64:
896
954
return ELF::R_RISCV_32_PCREL;
897
- return ELF::R_X86_64_PC32;
955
+ case Triple::x86_64:
956
+ return ELF::R_X86_64_PC32;
957
+ }
898
958
}
899
959
900
960
uint64_t Relocation::getPC64 () {
901
- if (Arch == Triple::aarch64)
961
+ switch (Arch) {
962
+ default :
963
+ llvm_unreachable (" Unsupported architecture" );
964
+ case Triple::aarch64:
902
965
return ELF::R_AARCH64_PREL64;
903
- if (Arch == Triple::riscv64)
966
+ case Triple::riscv64:
904
967
llvm_unreachable (" not implemented" );
905
- return ELF::R_X86_64_PC64;
968
+ case Triple::x86_64:
969
+ return ELF::R_X86_64_PC64;
970
+ }
906
971
}
907
972
908
973
bool Relocation::isPCRelative (uint64_t Type) {
909
- if (Arch == Triple::aarch64)
974
+ switch (Arch) {
975
+ default :
976
+ llvm_unreachable (" Unsupported architecture" );
977
+ case Triple::aarch64:
910
978
return isPCRelativeAArch64 (Type);
911
- if (Arch == Triple::riscv64)
979
+ case Triple::riscv64:
912
980
return isPCRelativeRISCV (Type);
913
- return isPCRelativeX86 (Type);
981
+ case Triple::x86_64:
982
+ return isPCRelativeX86 (Type);
983
+ }
914
984
}
915
985
916
986
uint64_t Relocation::getAbs64 () {
917
- if (Arch == Triple::aarch64)
987
+ switch (Arch) {
988
+ default :
989
+ llvm_unreachable (" Unsupported architecture" );
990
+ case Triple::aarch64:
918
991
return ELF::R_AARCH64_ABS64;
919
- if (Arch == Triple::riscv64)
992
+ case Triple::riscv64:
920
993
return ELF::R_RISCV_64;
921
- return ELF::R_X86_64_64;
994
+ case Triple::x86_64:
995
+ return ELF::R_X86_64_64;
996
+ }
922
997
}
923
998
924
999
uint64_t Relocation::getRelative () {
925
- if (Arch == Triple::aarch64)
1000
+ switch (Arch) {
1001
+ default :
1002
+ llvm_unreachable (" Unsupported architecture" );
1003
+ case Triple::aarch64:
926
1004
return ELF::R_AARCH64_RELATIVE;
927
- return ELF::R_X86_64_RELATIVE;
1005
+ case Triple::riscv64:
1006
+ llvm_unreachable (" not implemented" );
1007
+ case Triple::x86_64:
1008
+ return ELF::R_X86_64_RELATIVE;
1009
+ }
928
1010
}
929
1011
930
1012
size_t Relocation::emit (MCStreamer *Streamer) const {
@@ -991,9 +1073,16 @@ void Relocation::print(raw_ostream &OS) const {
991
1073
static const char *AArch64RelocNames[] = {
992
1074
#include " llvm/BinaryFormat/ELFRelocs/AArch64.def"
993
1075
};
994
- if (Arch == Triple::aarch64)
1076
+ switch (Arch) {
1077
+ default :
1078
+ OS << " RType:" << Twine::utohexstr (Type);
1079
+ break ;
1080
+
1081
+ case Triple::aarch64:
995
1082
OS << AArch64RelocNames[Type];
996
- else if (Arch == Triple::riscv64) {
1083
+ break ;
1084
+
1085
+ case Triple::riscv64:
997
1086
// RISC-V relocations are not sequentially numbered so we cannot use an
998
1087
// array
999
1088
switch (Type) {
@@ -1006,8 +1095,12 @@ void Relocation::print(raw_ostream &OS) const {
1006
1095
break ;
1007
1096
#include " llvm/BinaryFormat/ELFRelocs/RISCV.def"
1008
1097
}
1009
- } else
1098
+ break ;
1099
+
1100
+ case Triple::x86_64:
1010
1101
OS << X86RelocNames[Type];
1102
+ break ;
1103
+ }
1011
1104
OS << " , 0x" << Twine::utohexstr (Offset);
1012
1105
if (Symbol) {
1013
1106
OS << " , " << Symbol->getName ();
0 commit comments