[llvm] f92c172 - Make llvm-tli-checker support static libraries
Paul Robinson via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 8 11:10:42 PDT 2022
Author: Paul Robinson
Date: 2022-09-08T11:10:26-07:00
New Revision: f92c1726deb729d96b9e527e2f4f329f1da09fdf
URL: https://github.com/llvm/llvm-project/commit/f92c1726deb729d96b9e527e2f4f329f1da09fdf
DIFF: https://github.com/llvm/llvm-project/commit/f92c1726deb729d96b9e527e2f4f329f1da09fdf.diff
LOG: Make llvm-tli-checker support static libraries
The original implementation assumed dynamic libraries and so looked
only at the dynamic symbol table. Use the regular symbol table for
ET_REL files.
Differential Revision: https://reviews.llvm.org/D133448
Added:
Modified:
llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
index d21c2c05ff290..06e3794ded09e 100644
--- a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
+++ b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
@@ -1,12 +1,12 @@
# REQUIRES: x86-registered-target
#
-## This produces the object that matches expectations for PS4/PS5.
-# RUN: yaml2obj %s -DZDAPV=_ZdaPv -o=%t1
+## This produces a static object that matches expectations for PS4/PS5.
+# RUN: yaml2obj %s -DTYPE=ET_REL -DLABEL=Symbols -DZDAPV=_ZdaPv -o=%t1
# RUN: llvm-tli-checker --triple=x86_64-scei-ps4 %t1 | FileCheck %s
# RUN: llvm-tli-checker --triple=x86_64-sie-ps5 %t1 | FileCheck %s
#
-## This produces an object that has _ZdaPvj instead of _ZdaPv.
-# RUN: yaml2obj %s -DZDAPV=_ZdaPvj -o=%t2
+## This produces a dynamic object that has _ZdaPvj instead of _ZdaPv.
+# RUN: yaml2obj %s -DTYPE=ET_DYN -DLABEL=DynamicSymbols -DZDAPV=_ZdaPvj -o=%t2
# RUN: llvm-tli-checker --triple x86_64-scei-ps4 %t2 | \
# RUN: FileCheck %s --check-prefixes=WRONG_SUMMARY,WRONG_DETAIL \
# RUN: --implicit-check-not="==" --implicit-check-not="<<" --implicit-check-not=">>"
diff --git a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
index a9ff5a204ff22..17a4000cb1d10 100644
--- a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -155,6 +155,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 +164,19 @@ class SDKNameMap : public StringMap<bool> {
};
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 +187,12 @@ void SDKNameMap::populateFromObject(ObjectFile *O) {
}
const auto *ELF = cast<ELFObjectFileBase>(O);
- for (const 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);
}
}
More information about the llvm-commits
mailing list