diff options
Diffstat (limited to 'ELF/Arch/MipsArchTree.cpp')
-rw-r--r-- | ELF/Arch/MipsArchTree.cpp | 239 |
1 files changed, 119 insertions, 120 deletions
diff --git a/ELF/Arch/MipsArchTree.cpp b/ELF/Arch/MipsArchTree.cpp index 98ceac3075e0c..f64d03756457d 100644 --- a/ELF/Arch/MipsArchTree.cpp +++ b/ELF/Arch/MipsArchTree.cpp @@ -1,9 +1,8 @@ //===- MipsArchTree.cpp --------------------------------------------------===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===---------------------------------------------------------------------===// // @@ -29,18 +28,18 @@ using namespace lld::elf; namespace { struct ArchTreeEdge { - uint32_t Child; - uint32_t Parent; + uint32_t child; + uint32_t parent; }; struct FileFlags { - InputFile *File; - uint32_t Flags; + InputFile *file; + uint32_t flags; }; } // namespace -static StringRef getAbiName(uint32_t Flags) { - switch (Flags) { +static StringRef getAbiName(uint32_t flags) { + switch (flags) { case 0: return "n64"; case EF_MIPS_ABI2: @@ -58,76 +57,76 @@ static StringRef getAbiName(uint32_t Flags) { } } -static StringRef getNanName(bool IsNan2008) { - return IsNan2008 ? "2008" : "legacy"; +static StringRef getNanName(bool isNan2008) { + return isNan2008 ? "2008" : "legacy"; } -static StringRef getFpName(bool IsFp64) { return IsFp64 ? "64" : "32"; } +static StringRef getFpName(bool isFp64) { return isFp64 ? "64" : "32"; } -static void checkFlags(ArrayRef<FileFlags> Files) { - assert(!Files.empty() && "expected non-empty file list"); +static void checkFlags(ArrayRef<FileFlags> files) { + assert(!files.empty() && "expected non-empty file list"); - uint32_t ABI = Files[0].Flags & (EF_MIPS_ABI | EF_MIPS_ABI2); - bool Nan = Files[0].Flags & EF_MIPS_NAN2008; - bool Fp = Files[0].Flags & EF_MIPS_FP64; + uint32_t abi = files[0].flags & (EF_MIPS_ABI | EF_MIPS_ABI2); + bool nan = files[0].flags & EF_MIPS_NAN2008; + bool fp = files[0].flags & EF_MIPS_FP64; - for (const FileFlags &F : Files) { - if (Config->Is64 && F.Flags & EF_MIPS_MICROMIPS) - error(toString(F.File) + ": microMIPS 64-bit is not supported"); + for (const FileFlags &f : files) { + if (config->is64 && f.flags & EF_MIPS_MICROMIPS) + error(toString(f.file) + ": microMIPS 64-bit is not supported"); - uint32_t ABI2 = F.Flags & (EF_MIPS_ABI | EF_MIPS_ABI2); - if (ABI != ABI2) - error(toString(F.File) + ": ABI '" + getAbiName(ABI2) + - "' is incompatible with target ABI '" + getAbiName(ABI) + "'"); + uint32_t abi2 = f.flags & (EF_MIPS_ABI | EF_MIPS_ABI2); + if (abi != abi2) + error(toString(f.file) + ": ABI '" + getAbiName(abi2) + + "' is incompatible with target ABI '" + getAbiName(abi) + "'"); - bool Nan2 = F.Flags & EF_MIPS_NAN2008; - if (Nan != Nan2) - error(toString(F.File) + ": -mnan=" + getNanName(Nan2) + - " is incompatible with target -mnan=" + getNanName(Nan)); + bool nan2 = f.flags & EF_MIPS_NAN2008; + if (nan != nan2) + error(toString(f.file) + ": -mnan=" + getNanName(nan2) + + " is incompatible with target -mnan=" + getNanName(nan)); - bool Fp2 = F.Flags & EF_MIPS_FP64; - if (Fp != Fp2) - error(toString(F.File) + ": -mfp" + getFpName(Fp2) + - " is incompatible with target -mfp" + getFpName(Fp)); + bool fp2 = f.flags & EF_MIPS_FP64; + if (fp != fp2) + error(toString(f.file) + ": -mfp" + getFpName(fp2) + + " is incompatible with target -mfp" + getFpName(fp)); } } -static uint32_t getMiscFlags(ArrayRef<FileFlags> Files) { - uint32_t Ret = 0; - for (const FileFlags &F : Files) - Ret |= F.Flags & +static uint32_t getMiscFlags(ArrayRef<FileFlags> files) { + uint32_t ret = 0; + for (const FileFlags &f : files) + ret |= f.flags & (EF_MIPS_ABI | EF_MIPS_ABI2 | EF_MIPS_ARCH_ASE | EF_MIPS_NOREORDER | EF_MIPS_MICROMIPS | EF_MIPS_NAN2008 | EF_MIPS_32BITMODE); - return Ret; + return ret; } -static uint32_t getPicFlags(ArrayRef<FileFlags> Files) { +static uint32_t getPicFlags(ArrayRef<FileFlags> files) { // Check PIC/non-PIC compatibility. - bool IsPic = Files[0].Flags & (EF_MIPS_PIC | EF_MIPS_CPIC); - for (const FileFlags &F : Files.slice(1)) { - bool IsPic2 = F.Flags & (EF_MIPS_PIC | EF_MIPS_CPIC); - if (IsPic && !IsPic2) - warn(toString(F.File) + + bool isPic = files[0].flags & (EF_MIPS_PIC | EF_MIPS_CPIC); + for (const FileFlags &f : files.slice(1)) { + bool isPic2 = f.flags & (EF_MIPS_PIC | EF_MIPS_CPIC); + if (isPic && !isPic2) + warn(toString(f.file) + ": linking non-abicalls code with abicalls code " + - toString(Files[0].File)); - if (!IsPic && IsPic2) - warn(toString(F.File) + + toString(files[0].file)); + if (!isPic && isPic2) + warn(toString(f.file) + ": linking abicalls code with non-abicalls code " + - toString(Files[0].File)); + toString(files[0].file)); } // Compute the result PIC/non-PIC flag. - uint32_t Ret = Files[0].Flags & (EF_MIPS_PIC | EF_MIPS_CPIC); - for (const FileFlags &F : Files.slice(1)) - Ret &= F.Flags & (EF_MIPS_PIC | EF_MIPS_CPIC); + uint32_t ret = files[0].flags & (EF_MIPS_PIC | EF_MIPS_CPIC); + for (const FileFlags &f : files.slice(1)) + ret &= f.flags & (EF_MIPS_PIC | EF_MIPS_CPIC); // PIC code is inherently CPIC and may not set CPIC flag explicitly. - if (Ret & EF_MIPS_PIC) - Ret |= EF_MIPS_CPIC; - return Ret; + if (ret & EF_MIPS_PIC) + ret |= EF_MIPS_CPIC; + return ret; } -static ArchTreeEdge ArchTree[] = { +static ArchTreeEdge archTree[] = { // MIPS32R6 and MIPS64R6 are not compatible with other extensions // MIPS64R2 extensions. {EF_MIPS_ARCH_64R2 | EF_MIPS_MACH_OCTEON3, EF_MIPS_ARCH_64R2}, @@ -167,25 +166,25 @@ static ArchTreeEdge ArchTree[] = { {EF_MIPS_ARCH_2, EF_MIPS_ARCH_1}, }; -static bool isArchMatched(uint32_t New, uint32_t Res) { - if (New == Res) +static bool isArchMatched(uint32_t New, uint32_t res) { + if (New == res) return true; - if (New == EF_MIPS_ARCH_32 && isArchMatched(EF_MIPS_ARCH_64, Res)) + if (New == EF_MIPS_ARCH_32 && isArchMatched(EF_MIPS_ARCH_64, res)) return true; - if (New == EF_MIPS_ARCH_32R2 && isArchMatched(EF_MIPS_ARCH_64R2, Res)) + if (New == EF_MIPS_ARCH_32R2 && isArchMatched(EF_MIPS_ARCH_64R2, res)) return true; - for (const auto &Edge : ArchTree) { - if (Res == Edge.Child) { - Res = Edge.Parent; - if (Res == New) + for (const auto &edge : archTree) { + if (res == edge.child) { + res = edge.parent; + if (res == New) return true; } } return false; } -static StringRef getMachName(uint32_t Flags) { - switch (Flags & EF_MIPS_MACH) { +static StringRef getMachName(uint32_t flags) { + switch (flags & EF_MIPS_MACH) { case EF_MIPS_MACH_NONE: return ""; case EF_MIPS_MACH_3900: @@ -229,8 +228,8 @@ static StringRef getMachName(uint32_t Flags) { } } -static StringRef getArchName(uint32_t Flags) { - switch (Flags & EF_MIPS_ARCH) { +static StringRef getArchName(uint32_t flags) { + switch (flags & EF_MIPS_ARCH) { case EF_MIPS_ARCH_1: return "mips1"; case EF_MIPS_ARCH_2: @@ -258,12 +257,12 @@ static StringRef getArchName(uint32_t Flags) { } } -static std::string getFullArchName(uint32_t Flags) { - StringRef Arch = getArchName(Flags); - StringRef Mach = getMachName(Flags); - if (Mach.empty()) - return Arch.str(); - return (Arch + " (" + Mach + ")").str(); +static std::string getFullArchName(uint32_t flags) { + StringRef arch = getArchName(flags); + StringRef mach = getMachName(flags); + if (mach.empty()) + return arch.str(); + return (arch + " (" + mach + ")").str(); } // There are (arguably too) many MIPS ISAs out there. Their relationships @@ -275,55 +274,55 @@ static std::string getFullArchName(uint32_t Flags) { // Output file gets EF_MIPS_ARCH_2 flag. From the other side mips3 and mips32 // are incompatible because nor mips3 is a parent for misp32, nor mips32 // is a parent for mips3. -static uint32_t getArchFlags(ArrayRef<FileFlags> Files) { - uint32_t Ret = Files[0].Flags & (EF_MIPS_ARCH | EF_MIPS_MACH); +static uint32_t getArchFlags(ArrayRef<FileFlags> files) { + uint32_t ret = files[0].flags & (EF_MIPS_ARCH | EF_MIPS_MACH); - for (const FileFlags &F : Files.slice(1)) { - uint32_t New = F.Flags & (EF_MIPS_ARCH | EF_MIPS_MACH); + for (const FileFlags &f : files.slice(1)) { + uint32_t New = f.flags & (EF_MIPS_ARCH | EF_MIPS_MACH); // Check ISA compatibility. - if (isArchMatched(New, Ret)) + if (isArchMatched(New, ret)) continue; - if (!isArchMatched(Ret, New)) { - error("incompatible target ISA:\n>>> " + toString(Files[0].File) + ": " + - getFullArchName(Ret) + "\n>>> " + toString(F.File) + ": " + + if (!isArchMatched(ret, New)) { + error("incompatible target ISA:\n>>> " + toString(files[0].file) + ": " + + getFullArchName(ret) + "\n>>> " + toString(f.file) + ": " + getFullArchName(New)); return 0; } - Ret = New; + ret = New; } - return Ret; + return ret; } template <class ELFT> uint32_t elf::calcMipsEFlags() { - std::vector<FileFlags> V; - for (InputFile *F : ObjectFiles) - V.push_back({F, cast<ObjFile<ELFT>>(F)->getObj().getHeader()->e_flags}); - if (V.empty()) + std::vector<FileFlags> v; + for (InputFile *f : objectFiles) + v.push_back({f, cast<ObjFile<ELFT>>(f)->getObj().getHeader()->e_flags}); + if (v.empty()) return 0; - checkFlags(V); - return getMiscFlags(V) | getPicFlags(V) | getArchFlags(V); + checkFlags(v); + return getMiscFlags(v) | getPicFlags(v) | getArchFlags(v); } -static int compareMipsFpAbi(uint8_t FpA, uint8_t FpB) { - if (FpA == FpB) +static int compareMipsFpAbi(uint8_t fpA, uint8_t fpB) { + if (fpA == fpB) return 0; - if (FpB == Mips::Val_GNU_MIPS_ABI_FP_ANY) + if (fpB == Mips::Val_GNU_MIPS_ABI_FP_ANY) return 1; - if (FpB == Mips::Val_GNU_MIPS_ABI_FP_64A && - FpA == Mips::Val_GNU_MIPS_ABI_FP_64) + if (fpB == Mips::Val_GNU_MIPS_ABI_FP_64A && + fpA == Mips::Val_GNU_MIPS_ABI_FP_64) return 1; - if (FpB != Mips::Val_GNU_MIPS_ABI_FP_XX) + if (fpB != Mips::Val_GNU_MIPS_ABI_FP_XX) return -1; - if (FpA == Mips::Val_GNU_MIPS_ABI_FP_DOUBLE || - FpA == Mips::Val_GNU_MIPS_ABI_FP_64 || - FpA == Mips::Val_GNU_MIPS_ABI_FP_64A) + if (fpA == Mips::Val_GNU_MIPS_ABI_FP_DOUBLE || + fpA == Mips::Val_GNU_MIPS_ABI_FP_64 || + fpA == Mips::Val_GNU_MIPS_ABI_FP_64A) return 1; return -1; } -static StringRef getMipsFpAbiName(uint8_t FpAbi) { - switch (FpAbi) { +static StringRef getMipsFpAbiName(uint8_t fpAbi) { + switch (fpAbi) { case Mips::Val_GNU_MIPS_ABI_FP_ANY: return "any"; case Mips::Val_GNU_MIPS_ABI_FP_DOUBLE: @@ -345,43 +344,43 @@ static StringRef getMipsFpAbiName(uint8_t FpAbi) { } } -uint8_t elf::getMipsFpAbiFlag(uint8_t OldFlag, uint8_t NewFlag, - StringRef FileName) { - if (compareMipsFpAbi(NewFlag, OldFlag) >= 0) - return NewFlag; - if (compareMipsFpAbi(OldFlag, NewFlag) < 0) - error(FileName + ": floating point ABI '" + getMipsFpAbiName(NewFlag) + +uint8_t elf::getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag, + StringRef fileName) { + if (compareMipsFpAbi(newFlag, oldFlag) >= 0) + return newFlag; + if (compareMipsFpAbi(oldFlag, newFlag) < 0) + error(fileName + ": floating point ABI '" + getMipsFpAbiName(newFlag) + "' is incompatible with target floating point ABI '" + - getMipsFpAbiName(OldFlag) + "'"); - return OldFlag; + getMipsFpAbiName(oldFlag) + "'"); + return oldFlag; } -template <class ELFT> static bool isN32Abi(const InputFile *F) { - if (auto *EF = dyn_cast<ELFFileBase<ELFT>>(F)) - return EF->getObj().getHeader()->e_flags & EF_MIPS_ABI2; +template <class ELFT> static bool isN32Abi(const InputFile *f) { + if (auto *ef = dyn_cast<ELFFileBase>(f)) + return ef->template getObj<ELFT>().getHeader()->e_flags & EF_MIPS_ABI2; return false; } -bool elf::isMipsN32Abi(const InputFile *F) { - switch (Config->EKind) { +bool elf::isMipsN32Abi(const InputFile *f) { + switch (config->ekind) { case ELF32LEKind: - return isN32Abi<ELF32LE>(F); + return isN32Abi<ELF32LE>(f); case ELF32BEKind: - return isN32Abi<ELF32BE>(F); + return isN32Abi<ELF32BE>(f); case ELF64LEKind: - return isN32Abi<ELF64LE>(F); + return isN32Abi<ELF64LE>(f); case ELF64BEKind: - return isN32Abi<ELF64BE>(F); + return isN32Abi<ELF64BE>(f); default: llvm_unreachable("unknown Config->EKind"); } } -bool elf::isMicroMips() { return Config->EFlags & EF_MIPS_MICROMIPS; } +bool elf::isMicroMips() { return config->eflags & EF_MIPS_MICROMIPS; } bool elf::isMipsR6() { - uint32_t Arch = Config->EFlags & EF_MIPS_ARCH; - return Arch == EF_MIPS_ARCH_32R6 || Arch == EF_MIPS_ARCH_64R6; + uint32_t arch = config->eflags & EF_MIPS_ARCH; + return arch == EF_MIPS_ARCH_32R6 || arch == EF_MIPS_ARCH_64R6; } template uint32_t elf::calcMipsEFlags<ELF32LE>(); |