aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp')
-rw-r--r--llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp43
1 files changed, 28 insertions, 15 deletions
diff --git a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
index 7deeaef40caf..179c42b60605 100644
--- a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -35,11 +35,14 @@ enum ID {
#undef OPTION
};
-#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
+#define PREFIX(NAME, VALUE) \
+ static constexpr StringLiteral NAME##_init[] = VALUE; \
+ static constexpr ArrayRef<StringLiteral> NAME(NAME##_init, \
+ std::size(NAME##_init) - 1);
#include "Opts.inc"
#undef PREFIX
-static const opt::OptTable::Info InfoTable[] = {
+static constexpr opt::OptTable::Info InfoTable[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
HELPTEXT, METAVAR, VALUES) \
{ \
@@ -51,9 +54,9 @@ static const opt::OptTable::Info InfoTable[] = {
#undef OPTION
};
-class TLICheckerOptTable : public opt::OptTable {
+class TLICheckerOptTable : public opt::GenericOptTable {
public:
- TLICheckerOptTable() : OptTable(InfoTable) {}
+ TLICheckerOptTable() : GenericOptTable(InfoTable) {}
};
} // end anonymous namespace
@@ -155,6 +158,7 @@ void TLINameList::dump() {
// Store all the exported symbol names we found in the input libraries.
// We use a map to get hashed lookup speed; the bool is meaningless.
class SDKNameMap : public StringMap<bool> {
+ void maybeInsertSymbol(const SymbolRef &S, const ObjectFile &O);
void populateFromObject(ObjectFile *O);
void populateFromArchive(Archive *A);
@@ -163,6 +167,19 @@ public:
};
static SDKNameMap SDKNames;
+// Insert defined global function symbols into the map if valid.
+void SDKNameMap::maybeInsertSymbol(const SymbolRef &S, const ObjectFile &O) {
+ SymbolRef::Type Type = unwrapIgnoreError(S.getType());
+ uint32_t Flags = unwrapIgnoreError(S.getFlags());
+ section_iterator Section = unwrapIgnoreError(S.getSection(),
+ /*Default=*/O.section_end());
+ if (Type == SymbolRef::ST_Function && (Flags & SymbolRef::SF_Global) &&
+ Section != O.section_end()) {
+ StringRef Name = unwrapIgnoreError(S.getName());
+ insert({ Name, true });
+ }
+}
+
// Given an ObjectFile, extract the global function symbols.
void SDKNameMap::populateFromObject(ObjectFile *O) {
// FIXME: Support other formats.
@@ -173,16 +190,12 @@ void SDKNameMap::populateFromObject(ObjectFile *O) {
}
const auto *ELF = cast<ELFObjectFileBase>(O);
- for (auto &S : ELF->getDynamicSymbolIterators()) {
- // We want only defined global function symbols.
- SymbolRef::Type Type = unwrapIgnoreError(S.getType());
- uint32_t Flags = unwrapIgnoreError(S.getFlags());
- section_iterator Section = unwrapIgnoreError(S.getSection(),
- /*Default=*/O->section_end());
- StringRef Name = unwrapIgnoreError(S.getName());
- if (Type == SymbolRef::ST_Function && (Flags & SymbolRef::SF_Global) &&
- Section != O->section_end())
- insert({Name, true});
+ if (ELF->getEType() == ELF::ET_REL) {
+ for (const auto &S : ELF->symbols())
+ maybeInsertSymbol(S, *O);
+ } else {
+ for (const auto &S : ELF->getDynamicSymbolIterators())
+ maybeInsertSymbol(S, *O);
}
}
@@ -191,7 +204,7 @@ void SDKNameMap::populateFromObject(ObjectFile *O) {
void SDKNameMap::populateFromArchive(Archive *A) {
Error Err = Error::success();
int Index = -1;
- for (auto &C : A->children(Err)) {
+ for (const auto &C : A->children(Err)) {
++Index;
Expected<std::unique_ptr<object::Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {