[llvm-commits] [llvm] r142316 - in /llvm/trunk: include/llvm/Object/COFF.h include/llvm/Object/MachO.h include/llvm/Object/ObjectFile.h include/llvm/Support/MachO.h lib/Object/COFFObjectFile.cpp lib/Object/ELFObjectFile.cpp lib/Object/MachOObjectFile.cpp

Michael J. Spencer bigcheesegs at gmail.com
Mon Oct 17 16:54:23 PDT 2011


Author: mspencer
Date: Mon Oct 17 18:54:22 2011
New Revision: 142316

URL: http://llvm.org/viewvc/llvm-project?rev=142316&view=rev
Log:
Object: Add isSymbolWeak.

Modified:
    llvm/trunk/include/llvm/Object/COFF.h
    llvm/trunk/include/llvm/Object/MachO.h
    llvm/trunk/include/llvm/Object/ObjectFile.h
    llvm/trunk/include/llvm/Support/MachO.h
    llvm/trunk/lib/Object/COFFObjectFile.cpp
    llvm/trunk/lib/Object/ELFObjectFile.cpp
    llvm/trunk/lib/Object/MachOObjectFile.cpp

Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=142316&r1=142315&r2=142316&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Mon Oct 17 18:54:22 2011
@@ -106,6 +106,7 @@
   virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
   virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
   virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const;
+  virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const;
   virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
 
   virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;

Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=142316&r1=142315&r2=142316&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Mon Oct 17 18:54:22 2011
@@ -54,6 +54,7 @@
   virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
   virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
   virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const;
+  virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const;
   virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
 
   virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;

Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=142316&r1=142315&r2=142316&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Mon Oct 17 18:54:22 2011
@@ -121,6 +121,9 @@
   /// such as library functions
   error_code isGlobal(bool &Result) const;
 
+  /// Returns true for weak symbols.
+  error_code isWeak(bool &Result) const;
+
   DataRefImpl getRawDataRefImpl() const;
 };
 typedef content_iterator<SymbolRef> symbol_iterator;
@@ -234,7 +237,7 @@
   virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const = 0;
   virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const = 0;
   virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const = 0;
-
+  virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const = 0;
 
   // Same as above for SectionRef.
   friend class SectionRef;
@@ -345,6 +348,10 @@
   return OwningObject->isSymbolGlobal(SymbolPimpl, Result);
 }
 
+inline error_code SymbolRef::isWeak(bool &Result) const {
+  return OwningObject->isSymbolWeak(SymbolPimpl, Result);
+}
+
 inline error_code SymbolRef::getType(SymbolRef::Type &Result) const {
   return OwningObject->getSymbolType(SymbolPimpl, Result);
 }

Modified: llvm/trunk/include/llvm/Support/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MachO.h?rev=142316&r1=142315&r2=142316&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MachO.h (original)
+++ llvm/trunk/include/llvm/Support/MachO.h Mon Oct 17 18:54:22 2011
@@ -240,6 +240,9 @@
       NListSectionNoSection     = 0u, // NO_SECT
       NListSectionMaxSection    = 0xffu, // MAX_SECT
 
+      NListDescWeakRef          = 0x40u,
+      NListDescWeakDef          = 0x80u,
+
       // Constant values for the "n_type" field in llvm::MachO::nlist and
       // llvm::MachO::nlist_64 when "(n_type & NlistMaskStab) != 0"
       StabGlobalSymbol          = 0x20u,  // N_GSYM	

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=142316&r1=142315&r2=142316&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Mon Oct 17 18:54:22 2011
@@ -168,6 +168,13 @@
   return object_error::success;
 }
 
+error_code COFFObjectFile::isSymbolWeak(DataRefImpl Symb,
+                                          bool &Result) const {
+  const coff_symbol *symb = toSymb(Symb);
+  Result = (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL);
+  return object_error::success;
+}
+
 error_code COFFObjectFile::getSymbolSize(DataRefImpl Symb,
                                          uint64_t &Result) const {
   // FIXME: Return the correct size. This requires looking at all the symbols

Modified: llvm/trunk/lib/Object/ELFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFObjectFile.cpp?rev=142316&r1=142315&r2=142316&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ELFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ELFObjectFile.cpp Mon Oct 17 18:54:22 2011
@@ -331,6 +331,7 @@
   virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
   virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
   virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const;
+  virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const;
   virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
 
   virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;
@@ -643,6 +644,17 @@
 
 template<support::endianness target_endianness, bool is64Bits>
 error_code ELFObjectFile<target_endianness, is64Bits>
+                        ::isSymbolWeak(DataRefImpl Symb,
+                                       bool &Result) const {
+  validateSymbol(Symb);
+  const Elf_Sym  *symb = getSymbol(Symb);
+
+  Result = symb->getBinding() == ELF::STB_WEAK;
+  return object_error::success;
+}
+
+template<support::endianness target_endianness, bool is64Bits>
+error_code ELFObjectFile<target_endianness, is64Bits>
                         ::isSymbolInternal(DataRefImpl Symb,
                                            bool &Result) const {
   validateSymbol(Symb);

Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=142316&r1=142315&r2=142316&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Mon Oct 17 18:54:22 2011
@@ -228,6 +228,20 @@
   return object_error::success;
 }
 
+error_code MachOObjectFile::isSymbolWeak(DataRefImpl Symb, bool &Res) const {
+
+  if (MachOObj->is64Bit()) {
+    InMemoryStruct<macho::Symbol64TableEntry> Entry;
+    getSymbol64TableEntry(Symb, Entry);
+    Res = Entry->Flags & (MachO::NListDescWeakRef | MachO::NListDescWeakDef);
+  } else {
+    InMemoryStruct<macho::SymbolTableEntry> Entry;
+    getSymbolTableEntry(Symb, Entry);
+    Res = Entry->Flags & (MachO::NListDescWeakRef | MachO::NListDescWeakDef);
+  }
+  return object_error::success;
+}
+
 error_code MachOObjectFile::getSymbolType(DataRefImpl Symb,
                                           SymbolRef::Type &Res) const {
   uint8_t n_type;





More information about the llvm-commits mailing list