[lld] r175039 - fix the mergeable string atom, when the target points to a symbol which is at a relative offset from the start of the .rodata section

Shankar Easwaran shankare at codeaurora.org
Tue Feb 12 22:35:34 PST 2013


Author: shankare
Date: Wed Feb 13 00:35:33 2013
New Revision: 175039

URL: http://llvm.org/viewvc/llvm-project?rev=175039&view=rev
Log:
fix the mergeable string atom, when the target points to a symbol which is at a relative offset from the start of the .rodata section

Modified:
    lld/trunk/lib/ReaderWriter/ELF/Atoms.h
    lld/trunk/lib/ReaderWriter/ELF/File.h

Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=175039&r1=175038&r2=175039&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Wed Feb 13 00:35:33 2013
@@ -461,6 +461,8 @@ public:
     return "";
   }
 
+  virtual uint64_t section() const { return _section->sh_name; }
+
   virtual uint64_t offset() const { return _offset; }
 
   virtual uint64_t ordinal() const { return _ordinal; }

Modified: lld/trunk/lib/ReaderWriter/ELF/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/File.h?rev=175039&r1=175038&r2=175039&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/File.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/File.h Wed Feb 13 00:35:33 2013
@@ -93,18 +93,22 @@ template <class ELFT> class ELFFile : pu
 
   /// \brief find a mergeAtom given a start offset
   struct FindByOffset {
+    const Elf_Shdr *_shdr;
     uint64_t _offset;
-    FindByOffset(uint64_t offset) : _offset(offset) {}
+    FindByOffset(const Elf_Shdr *shdr, uint64_t offset)
+        : _shdr(shdr), _offset(offset) {
+    }
     bool operator()(const ELFMergeAtom<ELFT> *a) {
       uint64_t off = a->offset();
-      return ((_offset >= off) && (_offset <= off + a->size()));
+      return (_shdr->sh_name == a->section()) &&
+             ((_offset >= off) && (_offset <= off + a->size()));
     }
   };
 
   /// \brief find a merge atom given a offset
-  MergeAtomsIter findMergeAtom(uint64_t offset) {
+  MergeAtomsIter findMergeAtom(const Elf_Shdr *shdr, uint64_t offset) {
     return std::find_if(_mergeAtoms.begin(), _mergeAtoms.end(),
-                        FindByOffset(offset));
+                        FindByOffset(shdr, offset));
   }
 
   typedef std::unordered_map<MergeSectionKey, DefinedAtom *, MergeSectionEq,
@@ -466,9 +470,12 @@ public:
             (sectionFlags == (llvm::ELF::SHF_MERGE | llvm::ELF::SHF_STRINGS))) {
           const MergeSectionKey ms(shdr, ri->addend());
           if (_mergedSectionMap.find(ms) == _mergedSectionMap.end()) {
-            MergeAtomsIter mai = findMergeAtom(ri->addend());
+            uint64_t addend = ri->addend();
+            if (Symbol->getType() != llvm::ELF::STT_SECTION)
+              addend = Symbol->st_value + ri->addend();
+            MergeAtomsIter mai = findMergeAtom(shdr, addend);
             if (mai != _mergeAtoms.end()) {
-              ri->setOffset(ri->addend() - ((*mai)->offset()));
+              ri->setOffset(addend - ((*mai)->offset()));
               ri->setAddend(0);
               ri->setTarget(*mai);
             } // check





More information about the llvm-commits mailing list