[llvm] [llvm-nm] Introduce synthetic flag (PR #138232)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 15 23:50:06 PDT 2025


================
@@ -1783,6 +1785,55 @@ getDynamicSyms(SymbolicFile &Obj) {
   return E->getDynamicSymbolIterators();
 }
 
+// Returns false if there is error found or true otherwise.
+static bool getPltSyms(SymbolicFile &Obj, std::vector<NMSymbol> &SymbolList) {
+  const auto *ELFObj = dyn_cast<ELFObjectFileBase>(&Obj);
+  if (!ELFObj)
+    return true;
+
+  std::string Err;
+  Triple TT;
+  TT.setArch(ELFObj->getArch());
+  TT.setOS(ELFObj->getOS());
+  const Target *TheTarget = TargetRegistry::lookupTarget(TT, Err);
+  if (!TheTarget) {
+    error("unable to find target for " + Obj.getFileName() + ": " + Err);
+    return false;
+  }
+
+  std::unique_ptr<const MCSubtargetInfo> STI;
+  STI.reset(TheTarget->createMCSubtargetInfo(
+      TT.getTriple(), ELFObj->tryGetCPUName().value_or("").str(), ""));
+  if (!STI) {
+    error("unable to create subtarget info for " + Obj.getFileName());
+    return false;
+  }
+
+  for (auto Plt : ELFObj->getPltEntries(*STI)) {
+    if (Plt.Symbol) {
+      SymbolRef Symbol(*Plt.Symbol, ELFObj);
+      if (Expected<StringRef> NameOrErr = Symbol.getName()) {
+        if (!NameOrErr->empty()) {
----------------
jh7370 wrote:

I think it's a little unfortunate that we're just ignoring such symbols. Perhaps it should be a warning too, or you could actually use it as an empty string (so you'd get `@plt` simply as the name). The latter feels most appropriate to me without thinking too hard about it at the moment.

https://github.com/llvm/llvm-project/pull/138232


More information about the llvm-commits mailing list