[llvm] b3af96d - [llvm-nm] Display defined weak STT_GNU_IFUNC symbols as 'i'

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 28 09:51:14 PST 2021


Author: Fangrui Song
Date: 2021-01-28T09:46:05-08:00
New Revision: b3af96d07b8bcdbc716b04629a1ad1d3d5f6ee5f

URL: https://github.com/llvm/llvm-project/commit/b3af96d07b8bcdbc716b04629a1ad1d3d5f6ee5f
DIFF: https://github.com/llvm/llvm-project/commit/b3af96d07b8bcdbc716b04629a1ad1d3d5f6ee5f.diff

LOG: [llvm-nm] Display defined weak STT_GNU_IFUNC symbols as 'i'

This patch makes the behavior match GNU nm.
Note: undefined STT_GNU_IFUNC symbols use 'U'.

Differential Revision: https://reviews.llvm.org/D95461

Added: 
    

Modified: 
    llvm/test/tools/llvm-nm/ifunc.test
    llvm/tools/llvm-nm/llvm-nm.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-nm/ifunc.test b/llvm/test/tools/llvm-nm/ifunc.test
index fdc3ced971ad..035c925da04a 100644
--- a/llvm/test/tools/llvm-nm/ifunc.test
+++ b/llvm/test/tools/llvm-nm/ifunc.test
@@ -5,6 +5,9 @@
 
 # CHECK:      i ifunc_local
 # CHECK-NEXT: i ifunc_global
+# CHECK-NEXT: i ifunc_weak
+# CHECK-NEXT: U ifunc_undef
+# CHECK-NEXT: w ifunc_undef_weak
 
 !ELF
 FileHeader:
@@ -25,3 +28,13 @@ Symbols:
     Type:    STT_GNU_IFUNC
     Binding: STB_GLOBAL
     Section: .text
+  - Name:    ifunc_weak
+    Type:    STT_GNU_IFUNC
+    Binding: STB_WEAK
+    Section: .text
+  - Name:    ifunc_undef
+    Type:    STT_GNU_IFUNC
+    Binding: STB_GLOBAL
+  - Name:    ifunc_undef_weak
+    Type:    STT_GNU_IFUNC
+    Binding: STB_WEAK

diff  --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index c678108807c5..19a7886239ca 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -1142,13 +1142,16 @@ static char getNMSectionTagAndName(SymbolicFile &Obj, basic_symbol_iterator I,
     }
   }
 
-  if ((Symflags & object::SymbolRef::SF_Weak) && !isa<MachOObjectFile>(Obj)) {
-    char Ret = isObject(Obj, I) ? 'v' : 'w';
-    return (!(Symflags & object::SymbolRef::SF_Undefined)) ? toupper(Ret) : Ret;
+  if (Symflags & object::SymbolRef::SF_Undefined) {
+    if (isa<MachOObjectFile>(Obj) || !(Symflags & object::SymbolRef::SF_Weak))
+      return 'U';
+    return isObject(Obj, I) ? 'v' : 'w';
   }
-
-  if (Symflags & object::SymbolRef::SF_Undefined)
-    return 'U';
+  if (ELFObjectFileBase *ELF = dyn_cast<ELFObjectFileBase>(&Obj))
+    if (ELFSymbolRef(*I).getELFType() == ELF::STT_GNU_IFUNC)
+      return 'i';
+  if (!isa<MachOObjectFile>(Obj) && (Symflags & object::SymbolRef::SF_Weak))
+    return isObject(Obj, I) ? 'V' : 'W';
 
   if (Symflags & object::SymbolRef::SF_Common)
     return 'C';
@@ -1169,8 +1172,6 @@ static char getNMSectionTagAndName(SymbolicFile &Obj, basic_symbol_iterator I,
   else if (TapiFile *Tapi = dyn_cast<TapiFile>(&Obj))
     Ret = getSymbolNMTypeChar(*Tapi, I);
   else if (ELFObjectFileBase *ELF = dyn_cast<ELFObjectFileBase>(&Obj)) {
-    if (ELFSymbolRef(*I).getELFType() == ELF::STT_GNU_IFUNC)
-      return 'i';
     Ret = getSymbolNMTypeChar(*ELF, I);
     if (ELFSymbolRef(*I).getBinding() == ELF::STB_GNU_UNIQUE)
       return Ret;


        


More information about the llvm-commits mailing list