Skip to content

Commit 93b6aa0

Browse files
committed
[Object] Move ELF specific ObjectFile::getBuildAttributes to ELFObjectFileBase
Change the return type from std::error_code to Error and make the function protected. llvm-svn: 360416
1 parent a2b780b commit 93b6aa0

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ELFObjectFileBase : public ObjectFile {
6464
virtual uint64_t getSectionOffset(DataRefImpl Sec) const = 0;
6565

6666
virtual Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
67+
virtual Error getBuildAttributes(ARMAttributeParser &Attributes) const = 0;
6768

6869
public:
6970
using elf_symbol_iterator_range = iterator_range<elf_symbol_iterator>;
@@ -352,6 +353,28 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
352353
(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_PROTECTED));
353354
}
354355

356+
Error getBuildAttributes(ARMAttributeParser &Attributes) const override {
357+
auto SectionsOrErr = EF.sections();
358+
if (!SectionsOrErr)
359+
return SectionsOrErr.takeError();
360+
361+
for (const Elf_Shdr &Sec : *SectionsOrErr) {
362+
if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES) {
363+
auto ErrorOrContents = EF.getSectionContents(&Sec);
364+
if (!ErrorOrContents)
365+
return ErrorOrContents.takeError();
366+
367+
auto Contents = ErrorOrContents.get();
368+
if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1)
369+
return Error::success();
370+
371+
Attributes.Parse(Contents, ELFT::TargetEndianness == support::little);
372+
break;
373+
}
374+
}
375+
return Error::success();
376+
}
377+
355378
// This flag is used for classof, to distinguish ELFObjectFile from
356379
// its subclass. If more subclasses will be created, this flag will
357380
// have to become an enum.
@@ -393,28 +416,6 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
393416

394417
unsigned getPlatformFlags() const override { return EF.getHeader()->e_flags; }
395418

396-
std::error_code getBuildAttributes(ARMAttributeParser &Attributes) const override {
397-
auto SectionsOrErr = EF.sections();
398-
if (!SectionsOrErr)
399-
return errorToErrorCode(SectionsOrErr.takeError());
400-
401-
for (const Elf_Shdr &Sec : *SectionsOrErr) {
402-
if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES) {
403-
auto ErrorOrContents = EF.getSectionContents(&Sec);
404-
if (!ErrorOrContents)
405-
return errorToErrorCode(ErrorOrContents.takeError());
406-
407-
auto Contents = ErrorOrContents.get();
408-
if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1)
409-
return std::error_code();
410-
411-
Attributes.Parse(Contents, ELFT::TargetEndianness == support::little);
412-
break;
413-
}
414-
}
415-
return std::error_code();
416-
}
417-
418419
const ELFFile<ELFT> *getELFFile() const { return &EF; }
419420

420421
bool isDyldType() const { return isDyldELFObject; }

llvm/include/llvm/Object/ObjectFile.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,6 @@ class ObjectFile : public SymbolicFile {
331331
/// Create a triple from the data in this object file.
332332
Triple makeTriple() const;
333333

334-
virtual std::error_code
335-
getBuildAttributes(ARMAttributeParser &Attributes) const {
336-
return std::error_code();
337-
}
338-
339334
/// Maps a debug section name to a standard DWARF section name.
340335
virtual StringRef mapDebugSectionName(StringRef Name) const { return Name; }
341336

llvm/lib/Object/ELFObjectFile.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ SubtargetFeatures ELFObjectFileBase::getMIPSFeatures() const {
148148
SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
149149
SubtargetFeatures Features;
150150
ARMAttributeParser Attributes;
151-
std::error_code EC = getBuildAttributes(Attributes);
152-
if (EC)
151+
if (Error E = getBuildAttributes(Attributes))
153152
return SubtargetFeatures();
154153

155154
// both ARMv7-M and R have to support thumb hardware div
@@ -279,8 +278,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
279278
return;
280279

281280
ARMAttributeParser Attributes;
282-
std::error_code EC = getBuildAttributes(Attributes);
283-
if (EC)
281+
if (Error E = getBuildAttributes(Attributes))
284282
return;
285283

286284
std::string Triple;

0 commit comments

Comments
 (0)