llvm.org GIT mirror llvm / bed93b0
Introduce convenience typedefs for the 4 ELF object types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181509 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
3 changed file(s) with 35 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
837837 ELFT::Is64Bits);
838838 }
839839 };
840
841 // Use an alignment of 2 for the typedefs since that is the worst case for
842 // ELF files in archives.
843 typedef ELFObjectFile > ELF32LEObjectFile;
844 typedef ELFObjectFile > ELF64LEObjectFile;
845 typedef ELFObjectFile > ELF32BEObjectFile;
846 typedef ELFObjectFile > ELF64BEObjectFile;
840847
841848 // Iterate through the version definitions, and place each Elf_Verdef
842849 // in the VersionMap according to its index.
29542961 const ObjectFile *Obj = R.getObjectFile();
29552962 DataRefImpl DRI = R.getRawDataRefImpl();
29562963 // Little-endian 32-bit
2957 if (const ELFObjectFile > *ELFObj =
2958 dyn_cast > >(Obj))
2964 if (const ELF32LEObjectFile *ELFObj = dyn_cast>(Obj))
29592965 return ELFObj->getRelocationAddend(DRI, Addend);
29602966
29612967 // Big-endian 32-bit
2962 if (const ELFObjectFile > *ELFObj =
2963 dyn_cast > >(Obj))
2968 if (const ELF32BEObjectFile *ELFObj = dyn_cast>(Obj))
29642969 return ELFObj->getRelocationAddend(DRI, Addend);
29652970
29662971 // Little-endian 64-bit
2967 if (const ELFObjectFile > *ELFObj =
2968 dyn_cast > >(Obj))
2972 if (const ELF64LEObjectFile *ELFObj = dyn_cast>(Obj))
29692973 return ELFObj->getRelocationAddend(DRI, Addend);
29702974
29712975 // Big-endian 64-bit
2972 if (const ELFObjectFile > *ELFObj =
2973 dyn_cast > >(Obj))
2976 if (const ELF64BEObjectFile *ELFObj = dyn_cast>(Obj))
29742977 return ELFObj->getRelocationAddend(DRI, Addend);
29752978
29762979 llvm_unreachable("Object passed to getELFRelocationAddend() is not ELF");
29832986 StringRef &Version,
29842987 bool &IsDefault) {
29852988 // Little-endian 32-bit
2986 if (const ELFObjectFile > *ELFObj =
2987 dyn_cast > >(Obj))
2989 if (const ELF32LEObjectFile *ELFObj = dyn_cast>(Obj))
29882990 return ELFObj->getSymbolVersion(Sym, Version, IsDefault);
29892991
29902992 // Big-endian 32-bit
2991 if (const ELFObjectFile > *ELFObj =
2992 dyn_cast > >(Obj))
2993 if (const ELF32BEObjectFile *ELFObj = dyn_cast>(Obj))
29932994 return ELFObj->getSymbolVersion(Sym, Version, IsDefault);
29942995
29952996 // Little-endian 64-bit
2996 if (const ELFObjectFile > *ELFObj =
2997 dyn_cast > >(Obj))
2997 if (const ELF64LEObjectFile *ELFObj = dyn_cast>(Obj))
29982998 return ELFObj->getSymbolVersion(Sym, Version, IsDefault);
29992999
30003000 // Big-endian 64-bit
3001 if (const ELFObjectFile > *ELFObj =
3002 dyn_cast > >(Obj))
3001 if (const ELF64BEObjectFile *ELFObj = dyn_cast>(Obj))
30033002 return ELFObj->getSymbolVersion(Sym, Version, IsDefault);
30043003
30053004 llvm_unreachable("Object passed to GetELFSymbolVersion() is not ELF");
7878
7979 void llvm::printELFFileHeader(const object::ObjectFile *Obj) {
8080 // Little-endian 32-bit
81 if (const ELFObjectFile > *ELFObj =
82 dyn_cast > >(Obj))
81 if (const ELF32LEObjectFile *ELFObj = dyn_cast>(Obj))
8382 printProgramHeaders(ELFObj);
8483
8584 // Big-endian 32-bit
86 if (const ELFObjectFile > *ELFObj =
87 dyn_cast > >(Obj))
85 if (const ELF32BEObjectFile *ELFObj = dyn_cast>(Obj))
8886 printProgramHeaders(ELFObj);
8987
9088 // Little-endian 64-bit
91 if (const ELFObjectFile > *ELFObj =
92 dyn_cast > >(Obj))
89 if (const ELF64LEObjectFile *ELFObj = dyn_cast>(Obj))
9390 printProgramHeaders(ELFObj);
9491
9592 // Big-endian 64-bit
96 if (const ELFObjectFile > *ELFObj =
97 dyn_cast > >(Obj))
93 if (const ELF64BEObjectFile *ELFObj = dyn_cast>(Obj))
9894 printProgramHeaders(ELFObj);
9995 }
6868
6969 namespace llvm {
7070
71 template
72 static error_code createELFDumper(const ELFObjectFile *Obj,
73 StreamWriter &Writer,
74 OwningPtr &Result) {
75 Result.reset(new ELFDumper(Obj, Writer));
76 return readobj_error::success;
77 }
78
7179 error_code createELFDumper(const object::ObjectFile *Obj,
7280 StreamWriter& Writer,
7381 OwningPtr &Result) {
74 typedef ELFType Little32ELF;
75 typedef ELFType Big32ELF;
76 typedef ELFType Little64ELF;
77 typedef ELFType Big64ELF;
78
79 typedef ELFObjectFile LittleELF32Obj;
80 typedef ELFObjectFile BigELF32Obj;
81 typedef ELFObjectFile LittleELF64Obj;
82 typedef ELFObjectFile BigELF64Obj;
83
8482 // Little-endian 32-bit
85 if (const LittleELF32Obj *ELFObj = dyn_cast(Obj)) {
86 Result.reset(new ELFDumper(ELFObj, Writer));
87 return readobj_error::success;
88 }
83 if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj))
84 return createELFDumper(ELFObj, Writer, Result);
8985
9086 // Big-endian 32-bit
91 if (const BigELF32Obj *ELFObj = dyn_cast(Obj)) {
92 Result.reset(new ELFDumper(ELFObj, Writer));
93 return readobj_error::success;
94 }
87 if (const ELF32BEObjectFile *ELFObj = dyn_cast(Obj))
88 return createELFDumper(ELFObj, Writer, Result);
9589
9690 // Little-endian 64-bit
97 if (const LittleELF64Obj *ELFObj = dyn_cast(Obj)) {
98 Result.reset(new ELFDumper(ELFObj, Writer));
99 return readobj_error::success;
100 }
91 if (const ELF64LEObjectFile *ELFObj = dyn_cast(Obj))
92 return createELFDumper(ELFObj, Writer, Result);
10193
10294 // Big-endian 64-bit
103 if (const BigELF64Obj *ELFObj = dyn_cast(Obj)) {
104 Result.reset(new ELFDumper(ELFObj, Writer));
105 return readobj_error::success;
106 }
95 if (const ELF64BEObjectFile *ELFObj = dyn_cast(Obj))
96 return createELFDumper(ELFObj, Writer, Result);
10797
10898 return readobj_error::unsupported_obj_file_format;
10999 }