[lld] r298084 - [ELF] - Revert r298078 and 298082

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 06:21:23 PDT 2017


Author: grimar
Date: Fri Mar 17 08:21:22 2017
New Revision: 298084

URL: http://llvm.org/viewvc/llvm-project?rev=298084&view=rev
Log:
[ELF] - Revert r298078 and 298082

It segfaults.

Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=298084&r1=298083&r2=298084&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Mar 17 08:21:22 2017
@@ -63,22 +63,33 @@ template <class ELFT> static std::vector
 
 // Find all common symbols and allocate space for them.
 template <class ELFT> InputSection *elf::createCommonSection() {
+  auto *Ret = make<InputSection>(SHF_ALLOC | SHF_WRITE, SHT_NOBITS, 1,
+                                 ArrayRef<uint8_t>(), "COMMON");
+  Ret->Live = true;
+
   if (!Config->DefineCommon)
-    return nullptr;
+    return Ret;
 
   // Sort the common symbols by alignment as an heuristic to pack them better.
   std::vector<DefinedCommon *> Syms = getCommonSymbols<ELFT>();
-  if (Syms.empty())
-    return nullptr;
-
   std::stable_sort(Syms.begin(), Syms.end(),
                    [](const DefinedCommon *A, const DefinedCommon *B) {
                      return A->Alignment > B->Alignment;
                    });
-  BssSection *Ret = make<BssSection>("COMMON");
-  for (DefinedCommon *Sym : Syms)
-    Sym->Offset = Ret->reserveSpace(Sym->Alignment, Sym->Size);
 
+  // Assign offsets to symbols.
+  size_t Size = 0;
+  uint32_t Alignment = 1;
+  for (DefinedCommon *Sym : Syms) {
+    Alignment = std::max(Alignment, Sym->Alignment);
+    Size = alignTo(Size, Sym->Alignment);
+
+    // Compute symbol offset relative to beginning of input section.
+    Sym->Offset = Size;
+    Size += Sym->Size;
+  }
+  Ret->Alignment = Alignment;
+  Ret->Data = makeArrayRef<uint8_t>(nullptr, Size);
   return Ret;
 }
 
@@ -369,8 +380,7 @@ BssSection::BssSection(StringRef Name)
     : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_NOBITS, 0, Name) {}
 
 size_t BssSection::reserveSpace(uint32_t Alignment, size_t Size) {
-  if (OutSec)
-    OutSec->updateAlignment(Alignment);
+  OutSec->updateAlignment(Alignment);
   this->Size = alignTo(this->Size, Alignment) + Size;
   this->Alignment = std::max<uint32_t>(this->Alignment, Alignment);
   return this->Size - Size;

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=298084&r1=298083&r2=298084&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Fri Mar 17 08:21:22 2017
@@ -153,10 +153,9 @@ private:
   uint8_t *HashBuf;
 };
 
-// BssSection is used to reserve space for copy relocations and common symbols.
-// We create three instances of this class for .bss, .bss.rel.ro and "COMMON".
-// .bss is used for writable symbols, .bss.rel.ro is used for read-only symbols
-// and latter used for common symbols.
+// BssSection is used to reserve space for copy relocations. We create two
+// instances of this class for .bss and .bss.rel.ro. .bss is used for writable
+// symbols, and .bss.rel.ro is used for read-only symbols.
 class BssSection final : public SyntheticSection {
 public:
   BssSection(StringRef Name);

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=298084&r1=298083&r2=298084&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Mar 17 08:21:22 2017
@@ -358,8 +358,11 @@ template <class ELFT> void Writer<ELFT>:
     Add(In<ELFT>::BuildId);
   }
 
-  if (auto *Sec = createCommonSection<ELFT>())
-    Add(Sec);
+  InputSection *Common = createCommonSection<ELFT>();
+  if (!Common->Data.empty()) {
+    In<ELFT>::Common = Common;
+    Add(Common);
+  }
 
   In<ELFT>::Bss = make<BssSection>(".bss");
   Add(In<ELFT>::Bss);




More information about the llvm-commits mailing list