-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[readobj][Arm][AArch64] Refactor Build Attributes parsing under ELFAtributeParser and add support for AArch64 Build Attributes #128727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f3a8056
[readobj][Arm][AArch64] Refactor build attribute parsing under ELFAtt…
sivan-shani 16feaaf
Remove '-o -' from llvm-mc arguments since it is the default.
sivan-shani 17ed192
Provide default implementations for ELFAttributeParser virtual functions
sivan-shani e89d817
Delete tests_ra.sh
sivan-shani ae9dd16
Delete tests.sh
sivan-shani d2efc8c
Overload getAttributeValue to accept unsigned only
sivan-shani e7d4b9f
Reduce SubSectionVec capacity from 64 to 8 subsections
sivan-shani 7dc6275
Rename (const StringRef &s, const unsigned i) --> (const StringRef &B…
sivan-shani 22b6cb4
Delete tests.sh
sivan-shani f6bb422
Delete tests_ra.sh
sivan-shani 36f22d2
Remove const qualifier from returnTagsNamesMap()
sivan-shani 797ad11
- Add new line at end of file (NFC)
sivan-shani 7a59990
Improve unclear and unnecessarily long code
sivan-shani 60b7ceb
Assign values that are left unassigned
sivan-shani 71d4052
test: specify linux to ensure elf in order to solve windows failure
sivan-shani 299e2c6
upstream test failure: give input file explicitly to llvm-mc
sivan-shani 99cf9b3
Fix usage of out-of-scope variable.
sivan-shani 310e995
Add implementaion of overloaded versions of getAttributeValue, getAtt…
sivan-shani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//=== - AArch64AttributeParser.h-AArch64 Attribute Information Printer - ===// | ||
// | ||
// 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 | ||
// | ||
//===--------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_SUPPORT_AARCH64ATTRIBUTEPARSER_H | ||
#define LLVM_SUPPORT_AARCH64ATTRIBUTEPARSER_H | ||
|
||
#include "llvm/Support/ELFAttrParserExtended.h" | ||
#include "llvm/Support/ELFAttributes.h" | ||
|
||
namespace llvm { | ||
|
||
class AArch64AttributeParser : public ELFExtendedAttrParser { | ||
static const std::vector<SubsectionAndTagToTagName> returnTagsNamesMap(); | ||
|
||
public: | ||
AArch64AttributeParser(ScopedPrinter *Sw) | ||
: ELFExtendedAttrParser(Sw, returnTagsNamesMap()) {} | ||
AArch64AttributeParser() | ||
: ELFExtendedAttrParser(nullptr, returnTagsNamesMap()) {} | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_SUPPORT_AARCH64ATTRIBUTEPARSER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//===- ELF AttributeParser.h - ELF Attribute Parser -------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_SUPPORT_ELFCOMPACTATTRPARSER_H | ||
#define LLVM_SUPPORT_ELFCOMPACTATTRPARSER_H | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/Support/DataExtractor.h" | ||
#include "llvm/Support/ELFAttributeParser.h" | ||
#include "llvm/Support/ELFAttributes.h" | ||
#include "llvm/Support/Error.h" | ||
|
||
#include <optional> | ||
#include <unordered_map> | ||
|
||
namespace llvm { | ||
class StringRef; | ||
class ScopedPrinter; | ||
|
||
class ELFCompactAttrParser : public ELFAttributeParser { | ||
StringRef vendor; | ||
std::unordered_map<unsigned, unsigned> attributes; | ||
std::unordered_map<unsigned, StringRef> attributesStr; | ||
|
||
virtual Error handler(uint64_t tag, bool &handled) = 0; | ||
|
||
protected: | ||
ScopedPrinter *sw; | ||
TagNameMap tagToStringMap; | ||
DataExtractor de{ArrayRef<uint8_t>{}, true, 0}; | ||
DataExtractor::Cursor cursor{0}; | ||
|
||
void printAttribute(unsigned tag, unsigned value, StringRef valueDesc); | ||
|
||
Error parseStringAttribute(const char *name, unsigned tag, | ||
ArrayRef<const char *> strings); | ||
Error parseAttributeList(uint32_t length); | ||
void parseIndexList(SmallVectorImpl<uint8_t> &indexList); | ||
Error parseSubsection(uint32_t length); | ||
|
||
void setAttributeString(unsigned tag, StringRef value) { | ||
attributesStr.emplace(tag, value); | ||
} | ||
|
||
public: | ||
virtual ~ELFCompactAttrParser() { static_cast<void>(!cursor.takeError()); } | ||
Error integerAttribute(unsigned tag); | ||
Error stringAttribute(unsigned tag); | ||
|
||
ELFCompactAttrParser(ScopedPrinter *sw, TagNameMap tagNameMap, | ||
StringRef vendor) | ||
: vendor(vendor), sw(sw), tagToStringMap(tagNameMap) {} | ||
ELFCompactAttrParser(TagNameMap tagNameMap, StringRef vendor) | ||
: vendor(vendor), sw(nullptr), tagToStringMap(tagNameMap) {} | ||
|
||
Error parse(ArrayRef<uint8_t> section, llvm::endianness endian) override; | ||
|
||
std::optional<unsigned> | ||
getAttributeValue(StringRef buildAttributeSubsectionName, | ||
unsigned tag) const override { | ||
auto I = attributes.find(tag); | ||
if (I == attributes.end()) | ||
return std::nullopt; | ||
return I->second; | ||
} | ||
std::optional<StringRef> | ||
getAttributeString(StringRef buildAttributeSubsectionName, | ||
unsigned tag) const override { | ||
auto I = attributesStr.find(tag); | ||
if (I == attributesStr.end()) | ||
return std::nullopt; | ||
return I->second; | ||
} | ||
}; | ||
|
||
} // namespace llvm | ||
#endif // LLVM_SUPPORT_ELFCOMPACTATTRPARSER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//===- ELF AttributeParser.h - ELF Attribute Parser -------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_SUPPORT_ELFEXTENDEDATTRPARSER_H | ||
#define LLVM_SUPPORT_ELFEXTENDEDATTRPARSER_H | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/Support/DataExtractor.h" | ||
#include "llvm/Support/ELFAttributeParser.h" | ||
#include "llvm/Support/ELFAttributes.h" | ||
#include "llvm/Support/Error.h" | ||
#include <optional> | ||
#include <vector> | ||
|
||
namespace llvm { | ||
class StringRef; | ||
class ScopedPrinter; | ||
|
||
class ELFExtendedAttrParser : public ELFAttributeParser { | ||
protected: | ||
ScopedPrinter *Sw; | ||
DataExtractor De{ArrayRef<uint8_t>{}, true, 0}; | ||
DataExtractor::Cursor Cursor{0}; | ||
|
||
// Data structure for holding Extended ELF Build Attribute subsection | ||
SmallVector<BuildAttributeSubSection, 64> SubSectionVec; | ||
sivan-shani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Maps SubsectionName + Tag to tags names. Required for printing comments. | ||
const std::vector<SubsectionAndTagToTagName> TagsNamesMap; | ||
StringRef getTagName(const StringRef &s, const unsigned i); | ||
sivan-shani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public: | ||
Error parse(ArrayRef<uint8_t> Section, llvm::endianness Endian) override; | ||
|
||
std::optional<unsigned> getAttributeValue(StringRef BuildAttrSubsectionName, | ||
unsigned Tag) const override; | ||
std::optional<StringRef> getAttributeString(StringRef BuildAttrSubsectionName, | ||
unsigned Tag) const override; | ||
|
||
ELFExtendedAttrParser(ScopedPrinter *Sw, | ||
std::vector<SubsectionAndTagToTagName> TagsNamesMap) | ||
: Sw(Sw), TagsNamesMap(TagsNamesMap) {} | ||
ELFExtendedAttrParser(std::vector<SubsectionAndTagToTagName> TagsNamesMap) | ||
: Sw(nullptr), TagsNamesMap(TagsNamesMap) {} | ||
}; | ||
} // namespace llvm | ||
#endif // LLVM_SUPPORT_ELFEXTENDEDATTRPARSER_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.