[PATCH] handle typeZeroFill atoms in ELF/Native/YAML
Shankar Kalpathi Easwaran
shankarke at gmail.com
Thu Aug 22 17:58:42 PDT 2013
updated with Nick's comments.
Will rename the TLV contentType in the next patch.
Hi kledzik, Bigcheese,
http://llvm-reviews.chandlerc.com/D1469
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1469?vs=3654&id=3688#toc
Files:
include/lld/Core/DefinedAtom.h
lib/ReaderWriter/ELF/File.h
lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
lib/ReaderWriter/ELF/SectionChunks.h
lib/ReaderWriter/Native/ReaderNative.cpp
lib/ReaderWriter/Native/WriterNative.cpp
lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
test/elf/X86_64/Inputs/largebss.c
test/elf/X86_64/Inputs/largebss.o
test/elf/X86_64/largebss.test
test/elf/quickdata.test
Index: include/lld/Core/DefinedAtom.h
===================================================================
--- include/lld/Core/DefinedAtom.h
+++ include/lld/Core/DefinedAtom.h
@@ -306,6 +306,14 @@
/// 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.
Index: lib/ReaderWriter/ELF/File.h
===================================================================
--- lib/ReaderWriter/ELF/File.h
+++ lib/ReaderWriter/ELF/File.h
@@ -344,8 +344,11 @@
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);
Index: lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
===================================================================
--- lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
+++ lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
@@ -46,7 +46,9 @@
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");
Index: lib/ReaderWriter/ELF/SectionChunks.h
===================================================================
--- lib/ReaderWriter/ELF/SectionChunks.h
+++ lib/ReaderWriter/ELF/SectionChunks.h
@@ -359,8 +359,7 @@
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();
Index: lib/ReaderWriter/Native/ReaderNative.cpp
===================================================================
--- lib/ReaderWriter/Native/ReaderNative.cpp
+++ lib/ReaderWriter/Native/ReaderNative.cpp
@@ -816,12 +816,11 @@
}
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 {
Index: lib/ReaderWriter/Native/WriterNative.cpp
===================================================================
--- lib/ReaderWriter/Native/WriterNative.cpp
+++ lib/ReaderWriter/Native/WriterNative.cpp
@@ -370,8 +370,7 @@
// 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();
Index: lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
===================================================================
--- lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
+++ lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
@@ -887,6 +887,8 @@
_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 @@
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; }
Index: test/elf/X86_64/Inputs/largebss.c
===================================================================
--- /dev/null
+++ test/elf/X86_64/Inputs/largebss.c
@@ -0,0 +1,3 @@
+int largebss[1000] = { 0 };
+int largecommon[1000];
+__thread int largetbss[1000] = { 0 };
Index: test/elf/X86_64/largebss.test
===================================================================
--- /dev/null
+++ test/elf/X86_64/largebss.test
@@ -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
Index: test/elf/quickdata.test
===================================================================
--- test/elf/quickdata.test
+++ test/elf/quickdata.test
@@ -11,4 +11,4 @@
hexagon: type: quick-data
hexagon: - name: bss1
hexagon: scope: global
-hexagon: type: quick-data
+hexagon: type: zero-fill-quick
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1469.2.patch
Type: text/x-patch
Size: 7101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130822/63ddfb9a/attachment.bin>
More information about the llvm-commits
mailing list