[ELF][Hexagon]add typeZeroFillFast

llvm-svn: 175983
diff --git a/lld/lib/ReaderWriter/ELF/Atoms.h b/lld/lib/ReaderWriter/ELF/Atoms.h
index 9251426..702131a 100644
--- a/lld/lib/ReaderWriter/ELF/Atoms.h
+++ b/lld/lib/ReaderWriter/ELF/Atoms.h
@@ -383,6 +383,16 @@
 
   virtual ContentPermissions permissions() const {
     uint64_t flags = _section->sh_flags;
+    // Treat target defined symbols
+    if ((_symbol->st_shndx > llvm::ELF::SHN_LOPROC &&
+         _symbol->st_shndx < llvm::ELF::SHN_HIPROC)) {
+      if (!_targetAtomHandler) {
+        const ELFTargetInfo &eti = (_owningFile.getTargetInfo());
+        TargetHandler<ELFT> &TargetHandler = eti.getTargetHandler<ELFT>();
+        _targetAtomHandler = &TargetHandler.targetAtomHandler();
+      }
+      return (_targetAtomHandler->contentPermissions(this));
+    }
     switch (_section->sh_type) {
     // permRW_L is for sections modified by the runtime
     // loader.
diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h
index 95cd8cf..96373e3 100644
--- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h
+++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h
@@ -306,6 +306,7 @@
         .Default(ORDER_DATA);
 
   case DefinedAtom::typeZeroFill:
+  case DefinedAtom::typeZeroFillFast:
     return ORDER_BSS;
 
   case DefinedAtom::typeGOT:
@@ -331,7 +332,8 @@
 StringRef DefaultLayout<ELFT>::getSectionName(
     StringRef name, const int32_t contentType,
     const int32_t contentPermissions) {
-  if (contentType == DefinedAtom::typeZeroFill)
+  if ((contentType == DefinedAtom::typeZeroFill) || 
+      (contentType == DefinedAtom::typeZeroFillFast)) 
     return ".bss";
   if (name.startswith(".text"))
     return ".text";
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
index b1169cd..3efd940 100644
--- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
+++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
@@ -44,7 +44,7 @@
     case llvm::ELF::SHN_HEXAGON_SCOMMON_2:
     case llvm::ELF::SHN_HEXAGON_SCOMMON_4:
     case llvm::ELF::SHN_HEXAGON_SCOMMON_8:
-      return DefinedAtom::typeZeroFill;
+      return DefinedAtom::typeZeroFillFast;
 
     default:
       if (section->sh_flags & llvm::ELF::SHF_HEX_GPREL)
@@ -93,7 +93,8 @@
   /// \brief Return the section order for a input section
   virtual Layout::SectionOrder getSectionOrder(
       StringRef name, int32_t contentType, int32_t contentPermissions) {
-    if (contentType == DefinedAtom::typeDataFast)
+    if ((contentType == DefinedAtom::typeDataFast) ||
+       (contentType == DefinedAtom::typeZeroFillFast))
       return ORDER_SDATA;
 
     return DefaultLayout<HexagonELFType>::getSectionOrder(name, contentType,
@@ -103,7 +104,8 @@
   /// \brief This maps the input sections to the output section names
   virtual StringRef getSectionName(StringRef name, const int32_t contentType,
                                    const int32_t contentPermissions) {
-    if (contentType == DefinedAtom::typeDataFast)
+    if ((contentType == DefinedAtom::typeDataFast) ||
+       (contentType == DefinedAtom::typeZeroFillFast))
       return ".sdata";
     return DefaultLayout<HexagonELFType>::getSectionName(name, contentType,
                                                          contentPermissions);
@@ -114,7 +116,8 @@
   createSection(StringRef name, int32_t contentType,
                 DefinedAtom::ContentPermissions contentPermissions,
                 Layout::SectionOrder sectionOrder) {
-    if (contentType == DefinedAtom::typeDataFast)
+    if ((contentType == DefinedAtom::typeDataFast) ||
+       (contentType == DefinedAtom::typeZeroFillFast))
       return _sdataSection;
     return DefaultLayout<HexagonELFType>::createSection(
         name, contentType, contentPermissions, sectionOrder);
diff --git a/lld/lib/ReaderWriter/ELF/SectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h
index 00dcbd1..24d6f94 100644
--- a/lld/lib/ReaderWriter/ELF/SectionChunks.h
+++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h
@@ -128,8 +128,10 @@
     case DefinedAtom::typeTLVInitialData:
       this->_type = SHT_PROGBITS;
       break;
-    case DefinedAtom::typeZeroFill:
+    
     case DefinedAtom::typeTLVInitialZeroFill:
+    case DefinedAtom::typeZeroFillFast:
+    case DefinedAtom::typeZeroFill:
       this->_type = SHT_NOBITS;
       break;
     }
@@ -194,7 +196,8 @@
 
   /// \brief Does the Atom occupy any disk space
   bool occupiesNoDiskSpace() const {
-    return _contentType == DefinedAtom::typeZeroFill;
+    return ((_contentType == DefinedAtom::typeZeroFill) ||
+            (_contentType == DefinedAtom::typeZeroFillFast));
   }
 
   /// \brief The permission of the section is the most permissive permission
@@ -262,13 +265,13 @@
   case Atom::definitionRegular:
     switch(definedAtom->contentType()) {
     case DefinedAtom::typeCode:
-    case DefinedAtom::typeData:
     case DefinedAtom::typeConstant:
+    case DefinedAtom::typeData:
+    case DefinedAtom::typeDataFast:
     case DefinedAtom::typeGOT:
     case DefinedAtom::typeStub:
     case DefinedAtom::typeResolver:
     case DefinedAtom::typeTLVInitialData:
-    case DefinedAtom::typeDataFast:
       _atoms.push_back(new (_alloc) AtomLayout(atom, fOffset, 0));
       this->_fsize = fOffset + definedAtom->size();
       this->_msize = mOffset + definedAtom->size();
@@ -277,8 +280,9 @@
                                    << "Adding atom: " << atom->name() << "@"
                                    << fOffset << "\n");
       break;
-    case DefinedAtom::typeZeroFill:
     case DefinedAtom::typeTLVInitialZeroFill:
+    case DefinedAtom::typeZeroFill:
+    case DefinedAtom::typeZeroFillFast:
       _atoms.push_back(new (_alloc) AtomLayout(atom, mOffset, 0));
       this->_msize = mOffset + definedAtom->size();
       break;
@@ -303,18 +307,18 @@
 ///        and printing purposes
 template <class ELFT> StringRef Section<ELFT>::segmentKindToStr() const {
   switch(_segmentType) {
+  case llvm::ELF::PT_DYNAMIC:
+    return "DYNAMIC";
   case llvm::ELF::PT_INTERP:
     return "INTERP";
   case llvm::ELF::PT_LOAD:
     return "LOAD";
   case llvm::ELF::PT_GNU_EH_FRAME:
     return "EH_FRAME";
-  case llvm::ELF::PT_NOTE:
-    return "NOTE";
-  case llvm::ELF::PT_DYNAMIC:
-    return "DYNAMIC";
   case llvm::ELF::PT_GNU_RELRO:
     return "RELRO";
+  case llvm::ELF::PT_NOTE:
+    return "NOTE";
   case llvm::ELF::PT_NULL:
     return "NULL";
   default:
@@ -332,7 +336,8 @@
                     llvm::dbgs() << "Writing atom: " << ai->_atom->name()
                                  << " | " << ai->_fileOffset << "\n");
     const DefinedAtom *definedAtom = cast<DefinedAtom>(ai->_atom);
-    if (definedAtom->contentType() == DefinedAtom::typeZeroFill)
+    if ((definedAtom->contentType() == DefinedAtom::typeZeroFill) ||
+        (definedAtom->contentType() == DefinedAtom::typeZeroFillFast))
       continue;
     // Copy raw content of atom to file buffer.
     llvm::ArrayRef<uint8_t> content = definedAtom->rawContent();
@@ -640,6 +645,7 @@
       type = llvm::ELF::STT_OBJECT;
       break;
     case DefinedAtom::typeZeroFill:
+    case DefinedAtom::typeZeroFillFast:
       type = llvm::ELF::STT_OBJECT;
       symbol.st_value = addr;
       break;
diff --git a/lld/lib/ReaderWriter/ELF/Writer.cpp b/lld/lib/ReaderWriter/ELF/Writer.cpp
index 13048b7..b5d3b4d 100644
--- a/lld/lib/ReaderWriter/ELF/Writer.cpp
+++ b/lld/lib/ReaderWriter/ELF/Writer.cpp
@@ -89,8 +89,9 @@
 
 template <class ELFT>
 void ExecutableWriter<ELFT>::buildChunks(const File &file) {
-  for (const DefinedAtom *definedAtom : file.defined())
+  for (const DefinedAtom *definedAtom : file.defined()) {
     _layout->addAtom(definedAtom);
+  }
   for (const AbsoluteAtom *absoluteAtom : file.absolute())
     _layout->addAtom(absoluteAtom);
 }
diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp
index 13f1a17..6fc6b7f 100644
--- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp
+++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp
@@ -822,7 +822,8 @@
 }
 
 inline ArrayRef<uint8_t> NativeDefinedAtomV1::rawContent() const {
-  if ( this->contentType() == DefinedAtom::typeZeroFill )
+  if (( this->contentType() == DefinedAtom::typeZeroFill ) ||
+      ( this->contentType() == DefinedAtom::typeZeroFillFast)) 
     return ArrayRef<uint8_t>();
   const uint8_t* p = _file->content(_ivarData->contentOffset,
                                     _ivarData->contentSize);
diff --git a/lld/lib/ReaderWriter/Native/WriterNative.cpp b/lld/lib/ReaderWriter/Native/WriterNative.cpp
index 9b6587f..38fe8f1 100644
--- a/lld/lib/ReaderWriter/Native/WriterNative.cpp
+++ b/lld/lib/ReaderWriter/Native/WriterNative.cpp
@@ -370,7 +370,8 @@
 
   // append atom cotent to content pool and return offset
   uint32_t getContentOffset(const class DefinedAtom& atom) {
-    if ( atom.contentType() == DefinedAtom::typeZeroFill )
+    if ((atom.contentType() == DefinedAtom::typeZeroFill ) ||
+        (atom.contentType() == DefinedAtom::typeZeroFillFast))
       return 0;
     uint32_t result = _contentPool.size();
     ArrayRef<uint8_t> cont = atom.rawContent();
diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
index c916f61..57efd24 100644
--- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
+++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
@@ -399,6 +399,7 @@
     io.enumCase(value, "data", lld::DefinedAtom::typeData);
     io.enumCase(value, "quick-data", lld::DefinedAtom::typeDataFast);
     io.enumCase(value, "zero-fill", lld::DefinedAtom::typeZeroFill);
+    io.enumCase(value, "zero-fill-quick", lld::DefinedAtom::typeZeroFillFast);
     io.enumCase(value, "const-data", lld::DefinedAtom::typeConstData);
     io.enumCase(value, "got",                 
                           lld::DefinedAtom::typeGOT);