[llvm] r241593 - Common symbols don't have a value.

Rafael Espindola rafael.espindola at gmail.com
Tue Jul 7 08:05:09 PDT 2015


Author: rafael
Date: Tue Jul  7 10:05:09 2015
New Revision: 241593

URL: http://llvm.org/viewvc/llvm-project?rev=241593&view=rev
Log:
Common symbols don't have a value.

At least not in the interface exposed by ObjectFile. This matches what ELF and
COFF implement.

Adjust existing code that was expecting them to have values. No overall
functionality change intended.

Another option would be to change the interface and the ELF and COFF
implementations to say that the value of a common symbol is its size.

Modified:
    llvm/trunk/lib/Object/MachOObjectFile.cpp
    llvm/trunk/tools/dsymutil/DebugMap.cpp
    llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp

Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=241593&r1=241592&r2=241593&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Tue Jul  7 10:05:09 2015
@@ -369,11 +369,10 @@ std::error_code MachOObjectFile::getIndi
 }
 
 uint64_t MachOObjectFile::getSymbolValue(DataRefImpl Sym) const {
-  uint64_t NValue = getNValue(Sym);
   MachO::nlist_base Entry = getSymbolTableEntryBase(this, Sym);
-  if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF && NValue == 0)
+  if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF)
     return UnknownAddress;
-  return NValue;
+  return getNValue(Sym);
 }
 
 ErrorOr<uint64_t> MachOObjectFile::getSymbolAddress(DataRefImpl Sym) const {

Modified: llvm/trunk/tools/dsymutil/DebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.cpp?rev=241593&r1=241592&r2=241593&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.cpp (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.cpp Tue Jul  7 10:05:09 2015
@@ -216,7 +216,11 @@ MappingTraits<dsymutil::DebugMapObject>:
     // during the test, we can't hardcode the symbols addresses, so
     // look them up here and rewrite them.
     for (const auto &Sym : ErrOrObjectFile->symbols()) {
-      uint64_t Address = Sym.getValue();
+      uint64_t Address;
+      if (Sym.getFlags() & SymbolRef::SF_Common)
+        Address = Sym.getCommonSize();
+      else
+        Address = Sym.getValue();
       ErrorOr<StringRef> Name = Sym.getName();
       if (!Name)
         continue;

Modified: llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp?rev=241593&r1=241592&r2=241593&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp Tue Jul  7 10:05:09 2015
@@ -197,10 +197,14 @@ void MachODebugMapParser::loadCurrentObj
   CurrentObjectAddresses.clear();
 
   for (auto Sym : CurrentObjectHolder.Get().symbols()) {
-
-    uint64_t Addr = Sym.getValue();
-    if (Addr == UnknownAddress)
-      continue;
+    uint64_t Addr;
+    if (Sym.getFlags() & SymbolRef::SF_Common) {
+      Addr = Sym.getCommonSize();
+    } else {
+      Addr = Sym.getValue();
+      if (Addr == UnknownAddress)
+        continue;
+    }
     ErrorOr<StringRef> Name = Sym.getName();
     if (!Name)
       continue;





More information about the llvm-commits mailing list