<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 13, 2015 at 10:04 AM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Thu Aug 13 12:04:50 2015<br>
New Revision: 244911<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=244911&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=244911&view=rev</a><br>
Log:<br>
Take name, type and flags in consideration when concatenating sections.<br>
<br>
This is mandated by the ELF spec.<br>
<br>
Modified:<br>
lld/trunk/ELF/Writer.cpp<br>
lld/trunk/test/elf2/string-table.s<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=244911&r1=244910&r2=244911&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=244911&r1=244910&r2=244911&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Thu Aug 13 12:04:50 2015<br>
@@ -63,6 +63,7 @@ private:<br>
template <class ELFT> class Writer {<br>
public:<br>
typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;<br>
+ typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;<br>
Writer(SymbolTable *T) : Symtab(T) {}<br>
void run();<br>
<br>
@@ -140,13 +141,44 @@ template <class ELFT> void OutputSection<br>
*SHdr = Header;<br>
}<br>
<br>
+namespace {<br>
+template <bool Is64Bits> struct SectionKey {<br>
+ typedef typename std::conditional<Is64Bits, uint64_t, uint32_t>::type uintX_t;<br>
+ StringRef Name;<br>
+ uint32_t sh_type;<br>
+ uintX_t sh_flags;<br>
+};<br>
+}<br>
+namespace llvm {<br>
+template <bool Is64Bits> struct DenseMapInfo<SectionKey<Is64Bits>> {<br>
+ static SectionKey<Is64Bits> getEmptyKey() {<br>
+ return SectionKey<Is64Bits>{DenseMapInfo<StringRef>::getEmptyKey(), 0, 0};<br>
+ }<br>
+ static SectionKey<Is64Bits> getTombstoneKey() {<br>
+ return SectionKey<Is64Bits>{DenseMapInfo<StringRef>::getTombstoneKey(), 0,<br>
+ 0};<br>
+ }<br>
+ static unsigned getHashValue(const SectionKey<Is64Bits> &Val) {<br>
+ return hash_combine(Val.Name, Val.sh_type, Val.sh_flags);<br>
+ }<br>
+ static bool isEqual(const SectionKey<Is64Bits> &LHS,<br>
+ const SectionKey<Is64Bits> &RHS) {<br>
+ return DenseMapInfo<StringRef>::isEqual(LHS.Name, RHS.Name) &&<br>
+ LHS.sh_type == RHS.sh_type && LHS.sh_flags == RHS.sh_flags;<br>
+ }<br>
+};<br>
+}<br>
+<br>
// Create output section objects and add them to OutputSections.<br>
template <class ELFT> void Writer<ELFT>::createSections() {<br>
- SmallDenseMap<StringRef, OutputSection<ELFT> *> Map;<br>
+ SmallDenseMap<SectionKey<ELFT::Is64Bits>, OutputSection<ELFT> *> Map;<br>
for (std::unique_ptr<ObjectFileBase> &FileB : Symtab->ObjectFiles) {<br>
auto &File = cast<ObjectFile<ELFT>>(*FileB);<br>
for (SectionChunk<ELFT> *C : File.getChunks()) {<br>
- OutputSection<ELFT> *&Sec = Map[C->getSectionName()];<br>
+ const Elf_Shdr *H = C->getSectionHdr();<br>
+ SectionKey<ELFT::Is64Bits> Key{C->getSectionName(), H->sh_type,<br>
+ H->sh_flags};<br>
+ OutputSection<ELFT> *&Sec = Map[Key];<br>
if (!Sec) {<br>
Sec = new (CAlloc.Allocate()) OutputSection<ELFT>(C->getSectionName());<br>
OutputSections.push_back(Sec);<br>
<br>
Modified: lld/trunk/test/elf2/string-table.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/string-table.s?rev=244911&r1=244910&r2=244911&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/string-table.s?rev=244911&r1=244910&r2=244911&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/string-table.s (original)<br>
+++ lld/trunk/test/elf2/string-table.s Thu Aug 13 12:04:50 2015<br>
@@ -6,28 +6,47 @@<br>
.global _start<br>
_start:<br>
<br>
-.section foobar<br>
+.section foobar,"",@progbits,unique,1<br>
+.section foobar,"T",@progbits,unique,2<br>
+.section foobar,"",@nobits,unique,3<br>
+.section foobar,"",@nobits,unique,4<br></blockquote><div><br></div><div>Is there a way to write this that is less arcane? Where is `unique` documented? What is the number at the end?</div><div><br></div><div>-- Sean Silva</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
.section bar, "a"<br>
<br>
// Both sections are in the output and that the alloc section is first:<br>
// CHECK: Name: bar<br>
-// CHECK-NEXT: Type: SHT_PROGBITS<br>
-// CHECK-NEXT: Flags [<br>
-// CHECK-NEXT: SHF_ALLOC<br>
-// CHECK-NEXT: ]<br>
-// CHECK-NEXT: Address: 0x1000<br>
+// CHECK-NEXT: Type: SHT_PROGBITS<br>
+// CHECK-NEXT: Flags [<br>
+// CHECK-NEXT: SHF_ALLOC<br>
+// CHECK-NEXT: ]<br>
+// CHECK-NEXT: Address: 0x1000<br>
<br>
// CHECK: Name: foobar<br>
-// CHECK-NEXT: Type: SHT_PROGBITS<br>
-// CHECK-NEXT: Flags [<br>
-// CHECK-NEXT: ]<br>
-// CHECK-NEXT: Address: 0x0<br>
+// CHECK-NEXT: Type: SHT_PROGBITS<br>
+// CHECK-NEXT: Flags [<br>
+// CHECK-NEXT: ]<br>
+// CHECK-NEXT: Address: 0x0<br>
+<br>
+// CHECK: Name: foobar<br>
+// CHECK-NEXT: Type: SHT_PROGBITS<br>
+// CHECK-NEXT: Flags [<br>
+// CHECK-NEXT: SHF_TLS<br>
+// CHECK-NEXT: ]<br>
+// CHECK-NEXT: Address: 0x0<br>
+<br>
+// CHECK: Name: foobar<br>
+// CHECK-NEXT: Type: SHT_NOBITS<br>
+// CHECK-NEXT: Flags [<br>
+// CHECK-NEXT: ]<br>
+// CHECK-NEXT: Address: 0x0<br>
+<br>
+// CHECK-NOT: Name: foobar<br>
<br>
// Test that the sting "bar" is merged into "foobar"<br>
<br>
// CHECK: Section {<br>
-// CHECK: Index: 6<br>
-// CHECK-NEXT: Name: .strtab<br>
+// CHECK: Index:<br>
+// CHECK: Name: .strtab<br>
// CHECK-NEXT: Type: SHT_STRTAB (0x3)<br>
// CHECK-NEXT: Flags [ (0x0)<br>
// CHECK-NEXT: ]<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>