[PATCH] handle typeZeroFill atoms in ELF/Native/YAML
Shankar Kalpathi Easwaran
shankarke at gmail.com
Wed Aug 21 23:54:46 PDT 2013
Hi kledzik, Bigcheese,
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 haev to be handled seperately when the atoms are considered when
writing to the lld's intermediate representation or the lld test infrastructure.
Also adds a test.
http://llvm-reviews.chandlerc.com/D1469
Files:
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: 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
@@ -360,7 +360,8 @@
<< " | " << ai->_fileOffset << "\n");
const DefinedAtom *definedAtom = cast<DefinedAtom>(ai->_atom);
if ((definedAtom->contentType() == DefinedAtom::typeZeroFill) ||
- (definedAtom->contentType() == DefinedAtom::typeZeroFillFast))
+ (definedAtom->contentType() == DefinedAtom::typeZeroFillFast) ||
+ (definedAtom->contentType() == DefinedAtom::typeTLVInitialZeroFill))
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,13 @@
}
inline ArrayRef<uint8_t> NativeDefinedAtomV1::rawContent() const {
- if (( this->contentType() == DefinedAtom::typeZeroFill ) ||
- ( this->contentType() == DefinedAtom::typeZeroFillFast))
+ if ((this->contentType() == DefinedAtom::typeZeroFill) ||
+ (this->contentType() == DefinedAtom::typeZeroFillFast) ||
+ (this->contentType() == DefinedAtom::typeTLVInitialZeroFill))
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,9 @@
// 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.contentType() == DefinedAtom::typeZeroFill) ||
+ (atom.contentType() == DefinedAtom::typeZeroFillFast) ||
+ (atom.contentType() == DefinedAtom::typeTLVInitialZeroFill))
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,10 @@
_sectionName(atom->customSectionName()) {
for ( const lld::Reference *r : *atom )
_references.push_back(r);
+ if ((this->contentType() == DefinedAtom::typeZeroFill) ||
+ (this->contentType() == DefinedAtom::typeZeroFillFast) ||
+ (this->contentType() == DefinedAtom::typeTLVInitialZeroFill))
+ return;
ArrayRef<uint8_t> cont = atom->rawContent();
_content.reserve(cont.size());
for (uint8_t x : cont)
@@ -933,8 +937,12 @@
virtual ContentPermissions permissions() const { return _permissions; }
virtual bool isAlias() const { return false; }
ArrayRef<uint8_t> rawContent() const {
+ if ((this->contentType() == DefinedAtom::typeZeroFill) ||
+ (this->contentType() == DefinedAtom::typeZeroFillFast) ||
+ (this->contentType() == DefinedAtom::typeTLVInitialZeroFill))
+ 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.1.patch
Type: text/x-patch
Size: 7028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130821/04975ea1/attachment.bin>
More information about the llvm-commits
mailing list