[llvm] [llvm-nm] Drop STT_FILE/STT_SECTION from --special-syms (PR #192129)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 11:40:15 PDT 2026


================
@@ -1825,17 +1825,20 @@ static bool getSymbolNamesFromObject(SymbolicFile &Obj,
         return false;
       }
 
-      // Don't drop format specifc symbols for ARM and AArch64 ELF targets, they
-      // are used to repesent mapping symbols and needed to honor the
-      // --special-syms option.
-      auto *ELFObj = dyn_cast<ELFObjectFileBase>(&Obj);
-      bool HasMappingSymbol =
-          ELFObj && llvm::is_contained({ELF::EM_ARM, ELF::EM_AARCH64,
-                                        ELF::EM_CSKY, ELF::EM_RISCV},
-                                       ELFObj->getEMachine());
-      if (!HasMappingSymbol && !DebugSyms &&
-          (*SymFlagsOrErr & SymbolRef::SF_FormatSpecific))
-        continue;
+      // Drop format-specific symbols (STT_FILE, STT_SECTION, etc.) but
+      // retain mapping symbols (STT_NOTYPE such as $d, $x) on ARM, AArch64,
+      // CSKY, and RISC-V targets to honor the --special-syms option.
+      if (!DebugSyms && (*SymFlagsOrErr & SymbolRef::SF_FormatSpecific)) {
+        auto *ELFObj = dyn_cast<ELFObjectFileBase>(&Obj);
+        bool IsMappingSymbol =
+            ELFObj &&
+            llvm::is_contained(
+                {ELF::EM_ARM, ELF::EM_AARCH64, ELF::EM_CSKY, ELF::EM_RISCV},
+                ELFObj->getEMachine()) &&
+            ELFSymbolRef(Sym).getELFType() == ELF::STT_NOTYPE;
+        if (!IsMappingSymbol)
+          continue;
----------------
lenary wrote:

This is not the correct way to identify mapping symbols. Mapping symbols have specific name formats (at least, on ARM, AArch64 and RISC-V -- I don't know the CSKY specifics).

In particular, `STT_NOTYPE` symbols often appear in hand-written assembly, where the user has forgotten a `.type <sym>,...` annotation.

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


More information about the llvm-commits mailing list