[llvm] r241512 - llvm-nm: treat weak undefined as undefined.

Rafael Espindola rafael.espindola at gmail.com
Mon Jul 6 14:36:24 PDT 2015


Author: rafael
Date: Mon Jul  6 16:36:23 2015
New Revision: 241512

URL: http://llvm.org/viewvc/llvm-project?rev=241512&view=rev
Log:
llvm-nm: treat weak undefined as undefined.

This matches the behavior of gnu ld.

Added:
    llvm/trunk/test/Object/X86/nm-coff.s
Modified:
    llvm/trunk/test/Object/coff-archive.test
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp

Added: llvm/trunk/test/Object/X86/nm-coff.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/X86/nm-coff.s?rev=241512&view=auto
==============================================================================
--- llvm/trunk/test/Object/X86/nm-coff.s (added)
+++ llvm/trunk/test/Object/X86/nm-coff.s Mon Jul  6 16:36:23 2015
@@ -0,0 +1,9 @@
+// RUN: llvm-mc %s -o %t -filetype=obj -triple=x86_64-pc-win32
+// RUN: llvm-nm --undefined-only %t | FileCheck %s
+// CHECK: w foo
+
+g:
+	movl	foo(%rip), %eax
+	retq
+
+	.weak	foo

Modified: llvm/trunk/test/Object/coff-archive.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/coff-archive.test?rev=241512&r1=241511&r2=241512&view=diff
==============================================================================
--- llvm/trunk/test/Object/coff-archive.test (original)
+++ llvm/trunk/test/Object/coff-archive.test Mon Jul  6 16:36:23 2015
@@ -71,6 +71,8 @@ CHECKIDX: Debug\mymath.obj:
 CHECKIDX:          U ??2 at YAPAXI@Z
 CHECKIDX:          U ??3 at YAXPAX@Z
 CHECKIDX:          U ??_7type_info@@6B@
+CHECKIDX:          w ??_Einvalid_argument at std@@UAEPAXI at Z
+CHECKIDX:          w ??_Elogic_error at std@@UAEPAXI at Z
 CHECKIDX:          U ??_Ginvalid_argument at std@@UAEPAXI at Z
 CHECKIDX:          U ??_Glogic_error at std@@UAEPAXI at Z
 CHECKIDX:          U ?what at exception@std@@UBEPBDXZ
@@ -222,5 +224,3 @@ CHECKIDX: 00000004 R ??_7logic_error at std
 CHECKIDX: 00000008 r __ehfuncinfo$?Divide at MyMathFuncs@MathFuncs@@SANNN at Z
 CHECKIDX: 0000000e t __ehhandler$?Divide at MyMathFuncs@MathFuncs@@SANNN at Z
 CHECKIDX: 00ab9d1b a @comp.id
-CHECKIDX:          w ??_Einvalid_argument at std@@UAEPAXI at Z
-CHECKIDX:          w ??_Elogic_error at std@@UAEPAXI at Z

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=241512&r1=241511&r2=241512&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Mon Jul  6 16:36:23 2015
@@ -180,14 +180,16 @@ struct NMSymbol {
   uint64_t Size;
   char TypeChar;
   StringRef Name;
-  DataRefImpl Symb;
+  BasicSymbolRef Sym;
 };
 }
 
 static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
-  if (A.TypeChar == 'U' && B.TypeChar != 'U')
+  bool AUndefined = A.Sym.getFlags() & SymbolRef::SF_Undefined;
+  bool BUndefined = B.Sym.getFlags() & SymbolRef::SF_Undefined;
+  if (AUndefined && !BUndefined)
     return true;
-  if (A.TypeChar != 'U' && B.TypeChar == 'U')
+  if (!AUndefined && BUndefined)
     return false;
   if (A.Address < B.Address)
     return true;
@@ -249,11 +251,12 @@ static void darwinPrintSymbol(MachOObjec
   uint16_t NDesc;
   uint32_t NStrx;
   uint64_t NValue;
+  DataRefImpl SymDRI = I->Sym.getRawDataRefImpl();
   if (MachO->is64Bit()) {
     H_64 = MachO->MachOObjectFile::getHeader64();
     Filetype = H_64.filetype;
     Flags = H_64.flags;
-    STE_64 = MachO->getSymbol64TableEntry(I->Symb);
+    STE_64 = MachO->getSymbol64TableEntry(SymDRI);
     NType = STE_64.n_type;
     NSect = STE_64.n_sect;
     NDesc = STE_64.n_desc;
@@ -263,7 +266,7 @@ static void darwinPrintSymbol(MachOObjec
     H = MachO->MachOObjectFile::getHeader();
     Filetype = H.filetype;
     Flags = H.flags;
-    STE = MachO->getSymbolTableEntry(I->Symb);
+    STE = MachO->getSymbolTableEntry(SymDRI);
     NType = STE.n_type;
     NSect = STE.n_sect;
     NDesc = STE.n_desc;
@@ -331,7 +334,7 @@ static void darwinPrintSymbol(MachOObjec
     break;
   case MachO::N_SECT: {
     section_iterator Sec = MachO->section_end();
-    MachO->getSymbolSection(I->Symb, Sec);
+    MachO->getSymbolSection(I->Sym.getRawDataRefImpl(), Sec);
     DataRefImpl Ref = Sec->getRawDataRefImpl();
     StringRef SectionName;
     MachO->getSectionName(Ref, SectionName);
@@ -390,7 +393,7 @@ static void darwinPrintSymbol(MachOObjec
   if ((NType & MachO::N_TYPE) == MachO::N_INDR) {
     outs() << I->Name << " (for ";
     StringRef IndirectName;
-    if (MachO->getIndirectName(I->Symb, IndirectName))
+    if (MachO->getIndirectName(I->Sym.getRawDataRefImpl(), IndirectName))
       outs() << "?)";
     else
       outs() << IndirectName << ")";
@@ -473,13 +476,14 @@ static void darwinPrintStab(MachOObjectF
   uint8_t NType;
   uint8_t NSect;
   uint16_t NDesc;
+  DataRefImpl SymDRI = I->Sym.getRawDataRefImpl();
   if (MachO->is64Bit()) {
-    STE_64 = MachO->getSymbol64TableEntry(I->Symb);
+    STE_64 = MachO->getSymbol64TableEntry(SymDRI);
     NType = STE_64.n_type;
     NSect = STE_64.n_sect;
     NDesc = STE_64.n_desc;
   } else {
-    STE = MachO->getSymbolTableEntry(I->Symb);
+    STE = MachO->getSymbolTableEntry(SymDRI);
     NType = STE.n_type;
     NSect = STE.n_sect;
     NDesc = STE.n_desc;
@@ -537,9 +541,11 @@ static void sortAndPrintSymbolList(Symbo
 
   for (SymbolListT::iterator I = SymbolList.begin(), E = SymbolList.end();
        I != E; ++I) {
-    if ((I->TypeChar != 'U') && UndefinedOnly)
+    uint32_t SymFlags = I->Sym.getFlags();
+    bool Undefined = SymFlags & SymbolRef::SF_Undefined;
+    if (!Undefined && UndefinedOnly)
       continue;
-    if ((I->TypeChar == 'U') && DefinedOnly)
+    if (Undefined && DefinedOnly)
       continue;
     if (SizeSort && !PrintAddress)
       continue;
@@ -895,7 +901,7 @@ static void dumpSymbolNamesFromObject(Sy
     if (error(Sym.printName(OS)))
       break;
     OS << '\0';
-    S.Symb = Sym.getRawDataRefImpl();
+    S.Sym = Sym;
     SymbolList.push_back(S);
   }
 





More information about the llvm-commits mailing list