<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 24, 2015 at 9:19 AM, Simon Atanasyan <span dir="ltr"><<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: atanasyan<br>
Date: Sun May 24 11:19:27 2015<br>
New Revision: 238115<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D238115-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=zMj7QUOeetKmNc1YT1nJRS620K4hvPHvU3DMJn8EoB8&s=ZTaUN0aQYOUlFjeUUzPAZDzA5kHWgIeLgDwZ32npU-k&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=238115&view=rev</a><br>
Log:<br>
[ELF] Fix lld when no unique sections is used<br>
<br>
Original patch of Shankar Easwaran with additional test case.<br>
The yaml2obj does not allow to create an object file with non-unique<br>
sections names </blockquote><div><br>Should we fix yaml2obj?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">so the fix uses a binary input object file in the test<br>
case.<br>
<br>
Added:<br>
    lld/trunk/test/elf/Inputs/no-unique-section-names.x86-64<br>
    lld/trunk/test/elf/no-unique-section-names.test<br>
Modified:<br>
    lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp<br>
    lld/trunk/lib/ReaderWriter/ELF/ELFFile.h<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_lib_ReaderWriter_ELF_ELFFile.cpp-3Frev-3D238115-26r1-3D238114-26r2-3D238115-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=zMj7QUOeetKmNc1YT1nJRS620K4hvPHvU3DMJn8EoB8&s=4n-ipp7i3bPg5ZJl3356qN8Tpx0KUVUbuOb8iMtFCV4&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp?rev=238115&r1=238114&r2=238115&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp Sun May 24 11:19:27 2015<br>
@@ -143,7 +143,7 @@ std::error_code ELFFile<ELFT>::createAto<br>
       auto rai(_objFile->begin_rela(&section));<br>
       auto rae(_objFile->end_rela(&section));<br>
<br>
-      _relocationAddendReferences[*sectionName] = make_range(rai, rae);<br>
+      _relocationAddendReferences[sHdr] = make_range(rai, rae);<br>
       totalRelocs += std::distance(rai, rae);<br>
     } else if (section.sh_type == llvm::ELF::SHT_REL) {<br>
       auto sHdr = _objFile->getSection(section.sh_info);<br>
@@ -155,7 +155,7 @@ std::error_code ELFFile<ELFT>::createAto<br>
       auto ri(_objFile->begin_rel(&section));<br>
       auto re(_objFile->end_rel(&section));<br>
<br>
-      _relocationReferences[*sectionName] = make_range(ri, re);<br>
+      _relocationReferences[sHdr] = make_range(ri, re);<br>
       totalRelocs += std::distance(ri, re);<br>
     } else {<br>
       _sectionSymbols[&section];<br>
@@ -554,12 +554,12 @@ ELFDefinedAtom<ELFT> *ELFFile<ELFT>::cre<br>
   unsigned int referenceStart = _references.size();<br>
<br>
   // Add Rela (those with r_addend) references:<br>
-  auto rari = _relocationAddendReferences.find(sectionName);<br>
+  auto rari = _relocationAddendReferences.find(section);<br>
   if (rari != _relocationAddendReferences.end())<br>
     createRelocationReferences(symbol, symContent, rari->second);<br>
<br>
   // Add Rel references.<br>
-  auto rri = _relocationReferences.find(sectionName);<br>
+  auto rri = _relocationReferences.find(section);<br>
   if (rri != _relocationReferences.end())<br>
     createRelocationReferences(symbol, symContent, secContent, rri->second);<br>
<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_lib_ReaderWriter_ELF_ELFFile.h-3Frev-3D238115-26r1-3D238114-26r2-3D238115-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=zMj7QUOeetKmNc1YT1nJRS620K4hvPHvU3DMJn8EoB8&s=aNcAuVdjXL2v0iJVGTPMnDBasasf8FO7xVE3zBgE6IE&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=238115&r1=238114&r2=238115&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Sun May 24 11:19:27 2015<br>
@@ -345,10 +345,10 @@ protected:<br>
   /// list of relocations references.  In ELF, if a section named, ".text" has<br>
   /// relocations will also have a section named ".rel.text" or ".rela.text"<br>
   /// which will hold the entries.<br>
-  std::unordered_map<StringRef, range<Elf_Rela_Iter>><br>
+  std::unordered_map<const Elf_Shdr *, range<Elf_Rela_Iter>><br>
   _relocationAddendReferences;<br>
   MergedSectionMapT _mergedSectionMap;<br>
-  std::unordered_map<StringRef, range<Elf_Rel_Iter>> _relocationReferences;<br>
+  std::unordered_map<const Elf_Shdr *, range<Elf_Rel_Iter>> _relocationReferences;<br>
   std::vector<ELFReference<ELFT> *> _references;<br>
   llvm::DenseMap<const Elf_Sym *, Atom *> _symbolToAtomMapping;<br>
   llvm::DenseMap<const ELFReference<ELFT> *, const Elf_Sym *><br>
<br>
Added: lld/trunk/test/elf/Inputs/no-unique-section-names.x86-64<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_test_elf_Inputs_no-2Dunique-2Dsection-2Dnames.x86-2D64-3Frev-3D238115-26view-3Dauto&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=zMj7QUOeetKmNc1YT1nJRS620K4hvPHvU3DMJn8EoB8&s=a7CZwRWoe7Cel2VPvaNaXv7ANwnN2y802ctU9CcVVG4&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/no-unique-section-names.x86-64?rev=238115&view=auto</a><br>
==============================================================================<br>
Binary files lld/trunk/test/elf/Inputs/no-unique-section-names.x86-64 (added) and lld/trunk/test/elf/Inputs/no-unique-section-names.x86-64 Sun May 24 11:19:27 2015 differ<br>
<br>
Added: lld/trunk/test/elf/no-unique-section-names.test<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_test_elf_no-2Dunique-2Dsection-2Dnames.test-3Frev-3D238115-26view-3Dauto&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=zMj7QUOeetKmNc1YT1nJRS620K4hvPHvU3DMJn8EoB8&s=KG4I0BJVDpptG25Eyta8SmeU2zzvTyHVGVed2iJGwag&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/no-unique-section-names.test?rev=238115&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/elf/no-unique-section-names.test (added)<br>
+++ lld/trunk/test/elf/no-unique-section-names.test Sun May 24 11:19:27 2015<br>
@@ -0,0 +1,19 @@<br>
+# Check handling object files with non-unique named sections.<br>
+<br>
+RUN: lld -flavor gnu -target x86_64-linux -shared -o %t \<br>
+RUN:     %p/Inputs/no-unique-section-names.x86-64<br>
+RUN: llvm-objdump -s %p/Inputs/no-unique-section-names.x86-64 %t \<br>
+RUN:   | FileCheck %s<br>
+<br>
+CHECK:      Contents of section .group:<br>
+CHECK-NEXT:  0000 01000000 08000000<br>
+CHECK-NEXT: Contents of section .text:<br>
+CHECK-NEXT:  0000 [[A1:[0-9a-f]+]] [[A2:[0-9a-f]+]] [[A3:[0-9a-f]+]]<br>
+CHECK-NEXT: Contents of section .group:<br>
+CHECK-NEXT:  0000 01000000 0a000000<br>
+CHECK-NEXT: Contents of section .text:<br>
+CHECK-NEXT:  0000 [[B1:[0-9a-f]+]] [[B2:[0-9a-f]+]] [[B3:[0-9a-f]+]]<br>
+<br>
+CHECK:      Contents of section .text:<br>
+CHECK:       {{[0-9a-f]+}} [[A1]] [[A2]] [[A3]]<br>
+CHECK-NEXT:  {{[0-9a-f]+}} [[B1]] [[B2]] [[B3]]<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>