OSDN Git Service

Common symbols don't have a value.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 7 Jul 2015 15:05:09 +0000 (15:05 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 7 Jul 2015 15:05:09 +0000 (15:05 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241593 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/MachOObjectFile.cpp
tools/dsymutil/DebugMap.cpp
tools/dsymutil/MachODebugMapParser.cpp

index 54e4624..3c82d7b 100644 (file)
@@ -369,11 +369,10 @@ std::error_code MachOObjectFile::getIndirectName(DataRefImpl Symb,
 }
 
 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 {
index e5cc87b..46b269d 100644 (file)
@@ -216,7 +216,11 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
     // 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;
index bec9591..76fc761 100644 (file)
@@ -197,10 +197,14 @@ void MachODebugMapParser::loadCurrentObjectFileSymbols() {
   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;