Skip to content

Commit c4dc5ed

Browse files
committed
[ELF] Avoid some toStr and ErrAlways
1 parent c790d6f commit c4dc5ed

File tree

6 files changed

+53
-63
lines changed

6 files changed

+53
-63
lines changed

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
7373
// features in the same category are either ANY, ANY and ON, or ANY and OFF).
7474
for (InputFile *f : ArrayRef(ctx.objectFiles).slice(1)) {
7575
if (retMach != (getEFlags(f) & EF_AMDGPU_MACH)) {
76-
ErrAlways(ctx) << "incompatible mach: " << f;
76+
Err(ctx) << "incompatible mach: " << f;
7777
return 0;
7878
}
7979

@@ -82,7 +82,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
8282
(getEFlags(f) & EF_AMDGPU_FEATURE_XNACK_V4)
8383
!= EF_AMDGPU_FEATURE_XNACK_ANY_V4)) {
8484
if (retXnack != (getEFlags(f) & EF_AMDGPU_FEATURE_XNACK_V4)) {
85-
ErrAlways(ctx) << "incompatible xnack: " << f;
85+
Err(ctx) << "incompatible xnack: " << f;
8686
return 0;
8787
}
8888
} else {
@@ -95,7 +95,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
9595
(getEFlags(f) & EF_AMDGPU_FEATURE_SRAMECC_V4) !=
9696
EF_AMDGPU_FEATURE_SRAMECC_ANY_V4)) {
9797
if (retSramEcc != (getEFlags(f) & EF_AMDGPU_FEATURE_SRAMECC_V4)) {
98-
ErrAlways(ctx) << "incompatible sramecc: " << f;
98+
Err(ctx) << "incompatible sramecc: " << f;
9999
return 0;
100100
}
101101
} else {
@@ -143,7 +143,7 @@ uint32_t AMDGPU::calcEFlags() const {
143143
case ELFABIVERSION_AMDGPU_HSA_V6:
144144
return calcEFlagsV6();
145145
default:
146-
ErrAlways(ctx) << "unknown abi version: " << abiVersion;
146+
Err(ctx) << "unknown abi version: " << abiVersion;
147147
return 0;
148148
}
149149
}

lld/ELF/Arch/ARM.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,22 +1219,20 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
12191219
sym->stOther = eSym.st_other;
12201220

12211221
if (eSym.st_shndx != SHN_ABS) {
1222-
ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
1223-
<< "' in import library '" << this << "' is not absolute";
1222+
Err(ctx) << "CMSE symbol '" << sym->getName() << "' in import library '"
1223+
<< this << "' is not absolute";
12241224
continue;
12251225
}
12261226

12271227
if (!(eSym.st_value & 1) || (eSym.getType() != STT_FUNC)) {
1228-
ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
1229-
<< "' in import library '" << this
1230-
<< "' is not a Thumb function definition";
1228+
Err(ctx) << "CMSE symbol '" << sym->getName() << "' in import library '"
1229+
<< this << "' is not a Thumb function definition";
12311230
continue;
12321231
}
12331232

12341233
if (ctx.symtab->cmseImportLib.count(sym->getName())) {
1235-
ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
1236-
<< "' is multiply defined in import library '" << this
1237-
<< "'";
1234+
Err(ctx) << "CMSE symbol '" << sym->getName()
1235+
<< "' is multiply defined in import library '" << this << "'";
12381236
continue;
12391237
}
12401238

@@ -1289,8 +1287,7 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
12891287
// If input object build attributes do not support CMSE, error and disable
12901288
// further scanning for <sym>, __acle_se_<sym> pairs.
12911289
if (!ctx.arg.armCMSESupport) {
1292-
ErrAlways(ctx)
1293-
<< "CMSE is only supported by ARMv8-M architecture or later";
1290+
Err(ctx) << "CMSE is only supported by ARMv8-M architecture or later";
12941291
ctx.arg.cmseImplib = false;
12951292
break;
12961293
}
@@ -1300,17 +1297,16 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
13001297
StringRef name = acleSeSym->getName().substr(std::strlen(ACLESESYM_PREFIX));
13011298
Symbol *sym = ctx.symtab->find(name);
13021299
if (!sym) {
1303-
ErrAlways(ctx)
1304-
<< acleSeSym->file << ": cmse special symbol '"
1305-
<< acleSeSym->getName()
1306-
<< "' detected, but no associated entry function definition '" << name
1307-
<< "' with external linkage found";
1300+
Err(ctx) << acleSeSym->file << ": cmse special symbol '"
1301+
<< acleSeSym->getName()
1302+
<< "' detected, but no associated entry function definition '"
1303+
<< name << "' with external linkage found";
13081304
continue;
13091305
}
13101306

13111307
std::string errMsg = checkCmseSymAttributes(ctx, acleSeSym, sym);
13121308
if (!errMsg.empty()) {
1313-
ErrAlways(ctx) << errMsg;
1309+
Err(ctx) << errMsg;
13141310
continue;
13151311
}
13161312

@@ -1496,8 +1492,8 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
14961492
Expected<std::unique_ptr<FileOutputBuffer>> bufferOrErr =
14971493
FileOutputBuffer::create(ctx.arg.cmseOutputLib, fileSize, flags);
14981494
if (!bufferOrErr) {
1499-
ErrAlways(ctx) << "failed to open " << ctx.arg.cmseOutputLib << ": "
1500-
<< bufferOrErr.takeError();
1495+
Err(ctx) << "failed to open " << ctx.arg.cmseOutputLib << ": "
1496+
<< bufferOrErr.takeError();
15011497
return;
15021498
}
15031499

lld/ELF/Arch/MipsArchTree.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,23 @@ static void checkFlags(Ctx &ctx, ArrayRef<FileFlags> files) {
7272

7373
for (const FileFlags &f : files) {
7474
if (ctx.arg.is64 && f.flags & EF_MIPS_MICROMIPS)
75-
ErrAlways(ctx) << f.file << ": microMIPS 64-bit is not supported";
75+
Err(ctx) << f.file << ": microMIPS 64-bit is not supported";
7676

7777
uint32_t abi2 = f.flags & (EF_MIPS_ABI | EF_MIPS_ABI2);
7878
if (abi != abi2)
79-
ErrAlways(ctx) << f.file << ": ABI '" << getAbiName(abi2)
80-
<< "' is incompatible with target ABI '" << getAbiName(abi)
81-
<< "'";
79+
Err(ctx) << f.file << ": ABI '" << getAbiName(abi2)
80+
<< "' is incompatible with target ABI '" << getAbiName(abi)
81+
<< "'";
8282

8383
bool nan2 = f.flags & EF_MIPS_NAN2008;
8484
if (nan != nan2)
85-
ErrAlways(ctx) << f.file << ": -mnan=" << getNanName(nan2)
86-
<< " is incompatible with target -mnan="
87-
<< getNanName(nan);
85+
Err(ctx) << f.file << ": -mnan=" << getNanName(nan2)
86+
<< " is incompatible with target -mnan=" << getNanName(nan);
8887

8988
bool fp2 = f.flags & EF_MIPS_FP64;
9089
if (fp != fp2)
91-
ErrAlways(ctx) << f.file << ": -mfp" << getFpName(fp2)
92-
<< " is incompatible with target -mfp" << getFpName(fp);
90+
Err(ctx) << f.file << ": -mfp" << getFpName(fp2)
91+
<< " is incompatible with target -mfp" << getFpName(fp);
9392
}
9493
}
9594

@@ -284,9 +283,9 @@ static uint32_t getArchFlags(Ctx &ctx, ArrayRef<FileFlags> files) {
284283
if (isArchMatched(newFlags, ret))
285284
continue;
286285
if (!isArchMatched(ret, newFlags)) {
287-
ErrAlways(ctx) << "incompatible target ISA:\n>>> " << files[0].file
288-
<< ": " << getFullArchName(ret) << "\n>>> " << f.file
289-
<< ": " << getFullArchName(newFlags);
286+
Err(ctx) << "incompatible target ISA:\n>>> " << files[0].file << ": "
287+
<< getFullArchName(ret) << "\n>>> " << f.file << ": "
288+
<< getFullArchName(newFlags);
290289
return 0;
291290
}
292291
ret = newFlags;
@@ -350,15 +349,14 @@ static StringRef getMipsFpAbiName(uint8_t fpAbi) {
350349
}
351350
}
352351

353-
uint8_t elf::getMipsFpAbiFlag(Ctx &ctx, uint8_t oldFlag, uint8_t newFlag,
354-
StringRef fileName) {
352+
uint8_t elf::getMipsFpAbiFlag(Ctx &ctx, InputFile *file, uint8_t oldFlag,
353+
uint8_t newFlag) {
355354
if (compareMipsFpAbi(newFlag, oldFlag) >= 0)
356355
return newFlag;
357356
if (compareMipsFpAbi(oldFlag, newFlag) < 0)
358-
ErrAlways(ctx) << fileName << ": floating point ABI '"
359-
<< getMipsFpAbiName(newFlag)
360-
<< "' is incompatible with target floating point ABI '"
361-
<< getMipsFpAbiName(oldFlag) << "'";
357+
Err(ctx) << file << ": floating point ABI '" << getMipsFpAbiName(newFlag)
358+
<< "' is incompatible with target floating point ABI '"
359+
<< getMipsFpAbiName(oldFlag) << "'";
362360
return oldFlag;
363361
}
364362

lld/ELF/Arch/RISCV.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,13 @@ uint32_t RISCV::calcEFlags() const {
156156
target |= EF_RISCV_RVC;
157157

158158
if ((eflags & EF_RISCV_FLOAT_ABI) != (target & EF_RISCV_FLOAT_ABI))
159-
ErrAlways(ctx) << f
160-
<< ": cannot link object files with different "
161-
"floating-point ABI from "
162-
<< ctx.objectFiles[0];
159+
Err(ctx) << f
160+
<< ": cannot link object files with different "
161+
"floating-point ABI from "
162+
<< ctx.objectFiles[0];
163163

164164
if ((eflags & EF_RISCV_RVE) != (target & EF_RISCV_RVE))
165-
ErrAlways(ctx)
166-
<< f << ": cannot link object files with different EF_RISCV_RVE";
165+
Err(ctx) << f << ": cannot link object files with different EF_RISCV_RVE";
167166
}
168167

169168
return target;

lld/ELF/SyntheticSections.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,20 @@ MipsAbiFlagsSection<ELFT>::create(Ctx &ctx) {
120120
sec->markDead();
121121
create = true;
122122

123-
std::string filename = toStr(ctx, sec->file);
124123
const size_t size = sec->content().size();
125124
// Older version of BFD (such as the default FreeBSD linker) concatenate
126125
// .MIPS.abiflags instead of merging. To allow for this case (or potential
127126
// zero padding) we ignore everything after the first Elf_Mips_ABIFlags
128127
if (size < sizeof(Elf_Mips_ABIFlags)) {
129-
ErrAlways(ctx) << filename
130-
<< ": invalid size of .MIPS.abiflags section: got "
131-
<< Twine(size) << " instead of "
132-
<< Twine(sizeof(Elf_Mips_ABIFlags));
128+
Err(ctx) << sec->file << ": invalid size of .MIPS.abiflags section: got "
129+
<< size << " instead of " << sizeof(Elf_Mips_ABIFlags);
133130
return nullptr;
134131
}
135132
auto *s =
136133
reinterpret_cast<const Elf_Mips_ABIFlags *>(sec->content().data());
137134
if (s->version != 0) {
138-
ErrAlways(ctx) << filename << ": unexpected .MIPS.abiflags version "
139-
<< Twine(s->version);
135+
Err(ctx) << sec->file << ": unexpected .MIPS.abiflags version "
136+
<< s->version;
140137
return nullptr;
141138
}
142139

@@ -152,7 +149,7 @@ MipsAbiFlagsSection<ELFT>::create(Ctx &ctx) {
152149
flags.flags1 |= s->flags1;
153150
flags.flags2 |= s->flags2;
154151
flags.fp_abi =
155-
elf::getMipsFpAbiFlag(ctx, flags.fp_abi, s->fp_abi, filename);
152+
elf::getMipsFpAbiFlag(ctx, sec->file, flags.fp_abi, s->fp_abi);
156153
};
157154

158155
if (create)
@@ -197,12 +194,10 @@ MipsOptionsSection<ELFT>::create(Ctx &ctx) {
197194
for (InputSectionBase *sec : sections) {
198195
sec->markDead();
199196

200-
std::string filename = toStr(ctx, sec->file);
201197
ArrayRef<uint8_t> d = sec->content();
202-
203198
while (!d.empty()) {
204199
if (d.size() < sizeof(Elf_Mips_Options)) {
205-
ErrAlways(ctx) << filename << ": invalid size of .MIPS.options section";
200+
Err(ctx) << sec->file << ": invalid size of .MIPS.options section";
206201
break;
207202
}
208203

@@ -213,8 +208,10 @@ MipsOptionsSection<ELFT>::create(Ctx &ctx) {
213208
break;
214209
}
215210

216-
if (!opt->size)
217-
Fatal(ctx) << filename << ": zero option descriptor size";
211+
if (!opt->size) {
212+
Err(ctx) << sec->file << ": zero option descriptor size";
213+
break;
214+
}
218215
d = d.slice(opt->size);
219216
}
220217
};
@@ -256,7 +253,7 @@ MipsReginfoSection<ELFT>::create(Ctx &ctx) {
256253
sec->markDead();
257254

258255
if (sec->content().size() != sizeof(Elf_Mips_RegInfo)) {
259-
ErrAlways(ctx) << sec->file << ": invalid size of .reginfo section";
256+
Err(ctx) << sec->file << ": invalid size of .reginfo section";
260257
return nullptr;
261258
}
262259

@@ -4395,7 +4392,7 @@ static uint8_t getAbiVersion(Ctx &ctx) {
43954392
uint8_t ver = ctx.objectFiles[0]->abiVersion;
43964393
for (InputFile *file : ArrayRef(ctx.objectFiles).slice(1))
43974394
if (file->abiVersion != ver)
4398-
ErrAlways(ctx) << "incompatible ABI version: " << file;
4395+
Err(ctx) << "incompatible ABI version: " << file;
43994396
return ver;
44004397
}
44014398

lld/ELF/Target.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ static inline std::string getErrorLoc(Ctx &ctx, const uint8_t *loc) {
211211
void processArmCmseSymbols(Ctx &);
212212

213213
template <class ELFT> uint32_t calcMipsEFlags(Ctx &);
214-
uint8_t getMipsFpAbiFlag(Ctx &, uint8_t oldFlag, uint8_t newFlag,
215-
llvm::StringRef fileName);
214+
uint8_t getMipsFpAbiFlag(Ctx &, InputFile *file, uint8_t oldFlag,
215+
uint8_t newFlag);
216216
bool isMipsN32Abi(Ctx &, const InputFile &f);
217217
bool isMicroMips(Ctx &);
218218
bool isMipsR6(Ctx &);

0 commit comments

Comments
 (0)