[lld] c4dc5ed - [ELF] Avoid some toStr and ErrAlways
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 24 11:43:45 PST 2024
Author: Fangrui Song
Date: 2024-11-24T11:43:40-08:00
New Revision: c4dc5ed8254e6b318200496d687b0a7b3163dc26
URL: https://github.com/llvm/llvm-project/commit/c4dc5ed8254e6b318200496d687b0a7b3163dc26
DIFF: https://github.com/llvm/llvm-project/commit/c4dc5ed8254e6b318200496d687b0a7b3163dc26.diff
LOG: [ELF] Avoid some toStr and ErrAlways
Added:
Modified:
lld/ELF/Arch/AMDGPU.cpp
lld/ELF/Arch/ARM.cpp
lld/ELF/Arch/MipsArchTree.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/Target.h
Removed:
################################################################################
diff --git a/lld/ELF/Arch/AMDGPU.cpp b/lld/ELF/Arch/AMDGPU.cpp
index ab948e65c25ed0..52fc779855a36e 100644
--- a/lld/ELF/Arch/AMDGPU.cpp
+++ b/lld/ELF/Arch/AMDGPU.cpp
@@ -73,7 +73,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
// features in the same category are either ANY, ANY and ON, or ANY and OFF).
for (InputFile *f : ArrayRef(ctx.objectFiles).slice(1)) {
if (retMach != (getEFlags(f) & EF_AMDGPU_MACH)) {
- ErrAlways(ctx) << "incompatible mach: " << f;
+ Err(ctx) << "incompatible mach: " << f;
return 0;
}
@@ -82,7 +82,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
(getEFlags(f) & EF_AMDGPU_FEATURE_XNACK_V4)
!= EF_AMDGPU_FEATURE_XNACK_ANY_V4)) {
if (retXnack != (getEFlags(f) & EF_AMDGPU_FEATURE_XNACK_V4)) {
- ErrAlways(ctx) << "incompatible xnack: " << f;
+ Err(ctx) << "incompatible xnack: " << f;
return 0;
}
} else {
@@ -95,7 +95,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
(getEFlags(f) & EF_AMDGPU_FEATURE_SRAMECC_V4) !=
EF_AMDGPU_FEATURE_SRAMECC_ANY_V4)) {
if (retSramEcc != (getEFlags(f) & EF_AMDGPU_FEATURE_SRAMECC_V4)) {
- ErrAlways(ctx) << "incompatible sramecc: " << f;
+ Err(ctx) << "incompatible sramecc: " << f;
return 0;
}
} else {
@@ -143,7 +143,7 @@ uint32_t AMDGPU::calcEFlags() const {
case ELFABIVERSION_AMDGPU_HSA_V6:
return calcEFlagsV6();
default:
- ErrAlways(ctx) << "unknown abi version: " << abiVersion;
+ Err(ctx) << "unknown abi version: " << abiVersion;
return 0;
}
}
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index f32c43067c3daf..e253aab8c08fc6 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -1219,22 +1219,20 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
sym->stOther = eSym.st_other;
if (eSym.st_shndx != SHN_ABS) {
- ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
- << "' in import library '" << this << "' is not absolute";
+ Err(ctx) << "CMSE symbol '" << sym->getName() << "' in import library '"
+ << this << "' is not absolute";
continue;
}
if (!(eSym.st_value & 1) || (eSym.getType() != STT_FUNC)) {
- ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
- << "' in import library '" << this
- << "' is not a Thumb function definition";
+ Err(ctx) << "CMSE symbol '" << sym->getName() << "' in import library '"
+ << this << "' is not a Thumb function definition";
continue;
}
if (ctx.symtab->cmseImportLib.count(sym->getName())) {
- ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
- << "' is multiply defined in import library '" << this
- << "'";
+ Err(ctx) << "CMSE symbol '" << sym->getName()
+ << "' is multiply defined in import library '" << this << "'";
continue;
}
@@ -1289,8 +1287,7 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
// If input object build attributes do not support CMSE, error and disable
// further scanning for <sym>, __acle_se_<sym> pairs.
if (!ctx.arg.armCMSESupport) {
- ErrAlways(ctx)
- << "CMSE is only supported by ARMv8-M architecture or later";
+ Err(ctx) << "CMSE is only supported by ARMv8-M architecture or later";
ctx.arg.cmseImplib = false;
break;
}
@@ -1300,17 +1297,16 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
StringRef name = acleSeSym->getName().substr(std::strlen(ACLESESYM_PREFIX));
Symbol *sym = ctx.symtab->find(name);
if (!sym) {
- ErrAlways(ctx)
- << acleSeSym->file << ": cmse special symbol '"
- << acleSeSym->getName()
- << "' detected, but no associated entry function definition '" << name
- << "' with external linkage found";
+ Err(ctx) << acleSeSym->file << ": cmse special symbol '"
+ << acleSeSym->getName()
+ << "' detected, but no associated entry function definition '"
+ << name << "' with external linkage found";
continue;
}
std::string errMsg = checkCmseSymAttributes(ctx, acleSeSym, sym);
if (!errMsg.empty()) {
- ErrAlways(ctx) << errMsg;
+ Err(ctx) << errMsg;
continue;
}
@@ -1496,8 +1492,8 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
Expected<std::unique_ptr<FileOutputBuffer>> bufferOrErr =
FileOutputBuffer::create(ctx.arg.cmseOutputLib, fileSize, flags);
if (!bufferOrErr) {
- ErrAlways(ctx) << "failed to open " << ctx.arg.cmseOutputLib << ": "
- << bufferOrErr.takeError();
+ Err(ctx) << "failed to open " << ctx.arg.cmseOutputLib << ": "
+ << bufferOrErr.takeError();
return;
}
diff --git a/lld/ELF/Arch/MipsArchTree.cpp b/lld/ELF/Arch/MipsArchTree.cpp
index 0c64a46fe85d08..197cb30cdb8a56 100644
--- a/lld/ELF/Arch/MipsArchTree.cpp
+++ b/lld/ELF/Arch/MipsArchTree.cpp
@@ -72,24 +72,23 @@ static void checkFlags(Ctx &ctx, ArrayRef<FileFlags> files) {
for (const FileFlags &f : files) {
if (ctx.arg.is64 && f.flags & EF_MIPS_MICROMIPS)
- ErrAlways(ctx) << f.file << ": microMIPS 64-bit is not supported";
+ Err(ctx) << f.file << ": microMIPS 64-bit is not supported";
uint32_t abi2 = f.flags & (EF_MIPS_ABI | EF_MIPS_ABI2);
if (abi != abi2)
- ErrAlways(ctx) << f.file << ": ABI '" << getAbiName(abi2)
- << "' is incompatible with target ABI '" << getAbiName(abi)
- << "'";
+ Err(ctx) << f.file << ": ABI '" << getAbiName(abi2)
+ << "' is incompatible with target ABI '" << getAbiName(abi)
+ << "'";
bool nan2 = f.flags & EF_MIPS_NAN2008;
if (nan != nan2)
- ErrAlways(ctx) << f.file << ": -mnan=" << getNanName(nan2)
- << " is incompatible with target -mnan="
- << getNanName(nan);
+ Err(ctx) << f.file << ": -mnan=" << getNanName(nan2)
+ << " is incompatible with target -mnan=" << getNanName(nan);
bool fp2 = f.flags & EF_MIPS_FP64;
if (fp != fp2)
- ErrAlways(ctx) << f.file << ": -mfp" << getFpName(fp2)
- << " is incompatible with target -mfp" << getFpName(fp);
+ Err(ctx) << f.file << ": -mfp" << getFpName(fp2)
+ << " is incompatible with target -mfp" << getFpName(fp);
}
}
@@ -284,9 +283,9 @@ static uint32_t getArchFlags(Ctx &ctx, ArrayRef<FileFlags> files) {
if (isArchMatched(newFlags, ret))
continue;
if (!isArchMatched(ret, newFlags)) {
- ErrAlways(ctx) << "incompatible target ISA:\n>>> " << files[0].file
- << ": " << getFullArchName(ret) << "\n>>> " << f.file
- << ": " << getFullArchName(newFlags);
+ Err(ctx) << "incompatible target ISA:\n>>> " << files[0].file << ": "
+ << getFullArchName(ret) << "\n>>> " << f.file << ": "
+ << getFullArchName(newFlags);
return 0;
}
ret = newFlags;
@@ -350,15 +349,14 @@ static StringRef getMipsFpAbiName(uint8_t fpAbi) {
}
}
-uint8_t elf::getMipsFpAbiFlag(Ctx &ctx, uint8_t oldFlag, uint8_t newFlag,
- StringRef fileName) {
+uint8_t elf::getMipsFpAbiFlag(Ctx &ctx, InputFile *file, uint8_t oldFlag,
+ uint8_t newFlag) {
if (compareMipsFpAbi(newFlag, oldFlag) >= 0)
return newFlag;
if (compareMipsFpAbi(oldFlag, newFlag) < 0)
- ErrAlways(ctx) << fileName << ": floating point ABI '"
- << getMipsFpAbiName(newFlag)
- << "' is incompatible with target floating point ABI '"
- << getMipsFpAbiName(oldFlag) << "'";
+ Err(ctx) << file << ": floating point ABI '" << getMipsFpAbiName(newFlag)
+ << "' is incompatible with target floating point ABI '"
+ << getMipsFpAbiName(oldFlag) << "'";
return oldFlag;
}
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index a36d6b0dc6c848..21e8e9db311a58 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -156,14 +156,13 @@ uint32_t RISCV::calcEFlags() const {
target |= EF_RISCV_RVC;
if ((eflags & EF_RISCV_FLOAT_ABI) != (target & EF_RISCV_FLOAT_ABI))
- ErrAlways(ctx) << f
- << ": cannot link object files with
diff erent "
- "floating-point ABI from "
- << ctx.objectFiles[0];
+ Err(ctx) << f
+ << ": cannot link object files with
diff erent "
+ "floating-point ABI from "
+ << ctx.objectFiles[0];
if ((eflags & EF_RISCV_RVE) != (target & EF_RISCV_RVE))
- ErrAlways(ctx)
- << f << ": cannot link object files with
diff erent EF_RISCV_RVE";
+ Err(ctx) << f << ": cannot link object files with
diff erent EF_RISCV_RVE";
}
return target;
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index ab8dcda847a736..a275d15a6e5744 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -120,23 +120,20 @@ MipsAbiFlagsSection<ELFT>::create(Ctx &ctx) {
sec->markDead();
create = true;
- std::string filename = toStr(ctx, sec->file);
const size_t size = sec->content().size();
// Older version of BFD (such as the default FreeBSD linker) concatenate
// .MIPS.abiflags instead of merging. To allow for this case (or potential
// zero padding) we ignore everything after the first Elf_Mips_ABIFlags
if (size < sizeof(Elf_Mips_ABIFlags)) {
- ErrAlways(ctx) << filename
- << ": invalid size of .MIPS.abiflags section: got "
- << Twine(size) << " instead of "
- << Twine(sizeof(Elf_Mips_ABIFlags));
+ Err(ctx) << sec->file << ": invalid size of .MIPS.abiflags section: got "
+ << size << " instead of " << sizeof(Elf_Mips_ABIFlags);
return nullptr;
}
auto *s =
reinterpret_cast<const Elf_Mips_ABIFlags *>(sec->content().data());
if (s->version != 0) {
- ErrAlways(ctx) << filename << ": unexpected .MIPS.abiflags version "
- << Twine(s->version);
+ Err(ctx) << sec->file << ": unexpected .MIPS.abiflags version "
+ << s->version;
return nullptr;
}
@@ -152,7 +149,7 @@ MipsAbiFlagsSection<ELFT>::create(Ctx &ctx) {
flags.flags1 |= s->flags1;
flags.flags2 |= s->flags2;
flags.fp_abi =
- elf::getMipsFpAbiFlag(ctx, flags.fp_abi, s->fp_abi, filename);
+ elf::getMipsFpAbiFlag(ctx, sec->file, flags.fp_abi, s->fp_abi);
};
if (create)
@@ -197,12 +194,10 @@ MipsOptionsSection<ELFT>::create(Ctx &ctx) {
for (InputSectionBase *sec : sections) {
sec->markDead();
- std::string filename = toStr(ctx, sec->file);
ArrayRef<uint8_t> d = sec->content();
-
while (!d.empty()) {
if (d.size() < sizeof(Elf_Mips_Options)) {
- ErrAlways(ctx) << filename << ": invalid size of .MIPS.options section";
+ Err(ctx) << sec->file << ": invalid size of .MIPS.options section";
break;
}
@@ -213,8 +208,10 @@ MipsOptionsSection<ELFT>::create(Ctx &ctx) {
break;
}
- if (!opt->size)
- Fatal(ctx) << filename << ": zero option descriptor size";
+ if (!opt->size) {
+ Err(ctx) << sec->file << ": zero option descriptor size";
+ break;
+ }
d = d.slice(opt->size);
}
};
@@ -256,7 +253,7 @@ MipsReginfoSection<ELFT>::create(Ctx &ctx) {
sec->markDead();
if (sec->content().size() != sizeof(Elf_Mips_RegInfo)) {
- ErrAlways(ctx) << sec->file << ": invalid size of .reginfo section";
+ Err(ctx) << sec->file << ": invalid size of .reginfo section";
return nullptr;
}
@@ -4395,7 +4392,7 @@ static uint8_t getAbiVersion(Ctx &ctx) {
uint8_t ver = ctx.objectFiles[0]->abiVersion;
for (InputFile *file : ArrayRef(ctx.objectFiles).slice(1))
if (file->abiVersion != ver)
- ErrAlways(ctx) << "incompatible ABI version: " << file;
+ Err(ctx) << "incompatible ABI version: " << file;
return ver;
}
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index ce42d3624a8f5b..a772a9d3bb50fd 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -211,8 +211,8 @@ static inline std::string getErrorLoc(Ctx &ctx, const uint8_t *loc) {
void processArmCmseSymbols(Ctx &);
template <class ELFT> uint32_t calcMipsEFlags(Ctx &);
-uint8_t getMipsFpAbiFlag(Ctx &, uint8_t oldFlag, uint8_t newFlag,
- llvm::StringRef fileName);
+uint8_t getMipsFpAbiFlag(Ctx &, InputFile *file, uint8_t oldFlag,
+ uint8_t newFlag);
bool isMipsN32Abi(Ctx &, const InputFile &f);
bool isMicroMips(Ctx &);
bool isMipsR6(Ctx &);
More information about the llvm-commits
mailing list