[lld] r189136 - [lld] handle typeZeroFill atoms in ELF/Native/YAML

Shankar Easwaran shankare at codeaurora.org
Fri Aug 23 13:03:22 PDT 2013


Author: shankare
Date: Fri Aug 23 15:03:21 2013
New Revision: 189136

URL: http://llvm.org/viewvc/llvm-project?rev=189136&view=rev
Log:
[lld] handle typeZeroFill atoms in ELF/Native/YAML

BSS atoms dont take any file space in the Input file. They are associated
with a contentType(typeZeroFill). Similiar zero fill types also exist which
have the same meaning in terms of occupying file space in the Input.

These atoms have to be handled seperately when writing to the
lld's intermediate file or the lld test infrastructure.

Also adds a test.

Added:
    lld/trunk/test/elf/X86_64/Inputs/largebss.c
    lld/trunk/test/elf/X86_64/Inputs/largebss.o
    lld/trunk/test/elf/X86_64/largebss.test
Modified:
    lld/trunk/include/lld/Core/DefinedAtom.h
    lld/trunk/lib/ReaderWriter/ELF/File.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
    lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
    lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp
    lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
    lld/trunk/test/elf/quickdata.test

Modified: lld/trunk/include/lld/Core/DefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/DefinedAtom.h?rev=189136&r1=189135&r2=189136&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/DefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/DefinedAtom.h Fri Aug 23 15:03:21 2013
@@ -306,6 +306,14 @@ public:
   /// Utility for deriving permissions from content type
   static ContentPermissions permissions(ContentType type);
 
+  /// Utility function to check if the atom occupies file space
+  virtual bool occupiesDiskSpace() const {
+    ContentType atomContentType = contentType();
+    return !(atomContentType == DefinedAtom::typeZeroFill ||
+             atomContentType == DefinedAtom::typeZeroFillFast ||
+             atomContentType == DefinedAtom::typeTLVInitialZeroFill);
+  }
+
 protected:
   // DefinedAtom is an abstract base class. Only subclasses can access
   // constructor.

Modified: lld/trunk/lib/ReaderWriter/ELF/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/File.h?rev=189136&r1=189135&r2=189136&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/File.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/File.h Fri Aug 23 15:03:21 2013
@@ -344,8 +344,11 @@ public:
       if (!sectionName)
         return error_code(sectionName);
 
-      auto sectionContents = section ? _objFile->getSectionContents(section)
-                                     : ArrayRef<uint8_t>();
+      auto sectionContents =
+          (section && section->sh_type != llvm::ELF::SHT_NOBITS)
+              ? _objFile->getSectionContents(section)
+              : ArrayRef<uint8_t>();
+
       if (!sectionContents)
         return error_code(sectionContents);
 

Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h?rev=189136&r1=189135&r2=189136&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h Fri Aug 23 15:03:21 2013
@@ -46,7 +46,9 @@ public:
       return DefinedAtom::typeZeroFillFast;
 
     default:
-      if (section->sh_flags & llvm::ELF::SHF_HEX_GPREL)
+      if (section->sh_type == llvm::ELF::SHT_NOBITS)
+        return DefinedAtom::typeZeroFillFast;
+      else if (section->sh_flags & llvm::ELF::SHF_HEX_GPREL)
         return DefinedAtom::typeDataFast;
       else
         llvm_unreachable("unknown symbol type");

Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=189136&r1=189135&r2=189136&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Fri Aug 23 15:03:21 2013
@@ -359,8 +359,7 @@ void AtomSection<ELFT>::write(ELFWriter
                     llvm::dbgs() << "Writing atom: " << ai->_atom->name()
                                  << " | " << ai->_fileOffset << "\n");
     const DefinedAtom *definedAtom = cast<DefinedAtom>(ai->_atom);
-    if ((definedAtom->contentType() == DefinedAtom::typeZeroFill) ||
-        (definedAtom->contentType() == DefinedAtom::typeZeroFillFast))
+    if (!definedAtom->occupiesDiskSpace())
       return;
     // Copy raw content of atom to file buffer.
     llvm::ArrayRef<uint8_t> content = definedAtom->rawContent();

Modified: lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp?rev=189136&r1=189135&r2=189136&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp Fri Aug 23 15:03:21 2013
@@ -816,12 +816,11 @@ inline const NativeAtomAttributesV1& Nat
 }
 
 inline ArrayRef<uint8_t> NativeDefinedAtomV1::rawContent() const {
-  if (( this->contentType() == DefinedAtom::typeZeroFill ) ||
-      ( this->contentType() == DefinedAtom::typeZeroFillFast))
+  if (!occupiesDiskSpace())
     return ArrayRef<uint8_t>();
   const uint8_t* p = _file->content(_ivarData->contentOffset,
                                     _ivarData->contentSize);
-   return ArrayRef<uint8_t>(p, _ivarData->contentSize);
+  return ArrayRef<uint8_t>(p, _ivarData->contentSize);
 }
 
 inline StringRef NativeDefinedAtomV1::customSectionName() const {

Modified: lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp?rev=189136&r1=189135&r2=189136&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp Fri Aug 23 15:03:21 2013
@@ -370,8 +370,7 @@ private:
 
   // append atom cotent to content pool and return offset
   uint32_t getContentOffset(const DefinedAtom& atom) {
-    if ((atom.contentType() == DefinedAtom::typeZeroFill ) ||
-        (atom.contentType() == DefinedAtom::typeZeroFillFast))
+    if (!atom.occupiesDiskSpace())
       return 0;
     uint32_t result = _contentPool.size();
     ArrayRef<uint8_t> cont = atom.rawContent();

Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=189136&r1=189135&r2=189136&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Fri Aug 23 15:03:21 2013
@@ -887,6 +887,8 @@ struct MappingTraits<const lld::DefinedA
         _sectionName(atom->customSectionName()) {
           for ( const lld::Reference *r : *atom )
             _references.push_back(r);
+          if (!atom->occupiesDiskSpace())
+            return;
           ArrayRef<uint8_t> cont = atom->rawContent();
           _content.reserve(cont.size());
           for (uint8_t x : cont)
@@ -933,8 +935,10 @@ struct MappingTraits<const lld::DefinedA
     virtual ContentPermissions permissions() const   { return _permissions; }
     virtual bool               isAlias() const       { return false; }
     ArrayRef<uint8_t>          rawContent() const    {
+      if (!occupiesDiskSpace())
+        return ArrayRef<uint8_t>();
       return ArrayRef<uint8_t>(
-        reinterpret_cast<const uint8_t *>(_content.data()), _content.size());
+          reinterpret_cast<const uint8_t *>(_content.data()), _content.size());
     }
 
     virtual uint64_t           ordinal() const       { return _ordinal; }

Added: lld/trunk/test/elf/X86_64/Inputs/largebss.c
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/largebss.c?rev=189136&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/Inputs/largebss.c (added)
+++ lld/trunk/test/elf/X86_64/Inputs/largebss.c Fri Aug 23 15:03:21 2013
@@ -0,0 +1,3 @@
+int largebss[1000] = { 0 };
+int largecommon[1000];
+__thread int largetbss[1000] = { 0 };

Added: lld/trunk/test/elf/X86_64/Inputs/largebss.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/largebss.o?rev=189136&view=auto
==============================================================================
Binary files lld/trunk/test/elf/X86_64/Inputs/largebss.o (added) and lld/trunk/test/elf/X86_64/Inputs/largebss.o Fri Aug 23 15:03:21 2013 differ

Added: lld/trunk/test/elf/X86_64/largebss.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/largebss.test?rev=189136&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/largebss.test (added)
+++ lld/trunk/test/elf/X86_64/largebss.test Fri Aug 23 15:03:21 2013
@@ -0,0 +1,24 @@
+# This tests the functionality of handling BSS symbols
+# BSS symbols dont occupy file content and are associated with typeZeroFill
+# Any typeZeroFill content wouldnot have space reserved in the file to store
+# its content
+
+RUN: lld -flavor gnu -target x86_64 %p/Inputs/largebss.o -emit-yaml | FileCheck %s
+
+
+CHECK:  - name:            largecommon
+CHECK:    scope:           global
+CHECK:    type:            zero-fill
+CHECK:    size:            4000
+CHECK:    merge:           as-tentative
+CHECK:    section-name:    .bss
+CHECK:  - name:            largebss
+CHECK:    scope:           global
+CHECK:    type:            zero-fill
+CHECK:    size:            4000
+CHECK:    section-name:    .bss
+CHECK:  - name:            largetbss
+CHECK:    scope:           global
+CHECK:    type:            tlv-zero-fill
+CHECK:    size:            4000
+CHECK:    section-name:    .tbss

Modified: lld/trunk/test/elf/quickdata.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/quickdata.test?rev=189136&r1=189135&r2=189136&view=diff
==============================================================================
--- lld/trunk/test/elf/quickdata.test (original)
+++ lld/trunk/test/elf/quickdata.test Fri Aug 23 15:03:21 2013
@@ -11,4 +11,4 @@ hexagon:    scope:           global
 hexagon:    type:            quick-data
 hexagon:  - name:            bss1
 hexagon:    scope:           global
-hexagon:    type:            quick-data
+hexagon:    type:            zero-fill-quick





More information about the llvm-commits mailing list