<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 26, 2015 at 2:08 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">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=nm8yYFCvY6T4fBGwvJlJKypGmFjwiY6IcWkt8P5Ign4&s=r2vswq3ecSih5seNV2g18GrKLqyg7y7hZxy5FPdrk3Y&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></span><div><br>Should we fix yaml2obj?</div></div></div></div></blockquote><div><br></div><div>Yes we should fix it if it can't handle valid objects, but I think we probably start considering checking in object files (as opposed to checking in yaml files) is the right thing, as IIRC Rafael said before. Object files are the input for the linker, so in order to get a precise control over the input, it's better to use object files themselves.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><div><div class="h5"><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=nm8yYFCvY6T4fBGwvJlJKypGmFjwiY6IcWkt8P5Ign4&s=FWqH6lrsv4BIAIIzFDzBysqCu1e44RJJZ1EU3RMuTm4&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=nm8yYFCvY6T4fBGwvJlJKypGmFjwiY6IcWkt8P5Ign4&s=abVSyiw2dvEwfgW3QPePDhBHZDrYyxZdjtzP8WAlWWI&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=nm8yYFCvY6T4fBGwvJlJKypGmFjwiY6IcWkt8P5Ign4&s=mMAHzxi4jojRJPdLeaObNFp1S8NTPlGpY6BUbz-zHI4&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=nm8yYFCvY6T4fBGwvJlJKypGmFjwiY6IcWkt8P5Ign4&s=ZKn31z8Tw14hzsGV0zQUG0qg5YHdfSRjiPuvZifBzSE&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" target="_blank">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></div></div><br></div></div>
</blockquote></div><br></div></div>