[PATCH] [lld] add calls to nativereader/nativewriter
Shankar Kalpathi Easwaran
shankarke at gmail.com
Wed Oct 16 12:31:48 PDT 2013
Hi Bigcheese, kledzik, rui314,
This adds functionality in the Driver to create native files in DEBUG mode. This is to make sure that no hidden data is being passed from the reader to the writer(Everything should be passed with Atoms).
This discovered few bugs on COFF
a) The fallback atom was not created properly in the native file.
Other bugs, which need to be fixed after this change :
lld :: pecoff/drectve.test
lld :: pecoff/dynamic.test
lld :: pecoff/importlib.test
<-------------------debugging snip----------------------------------->
I was looking at the failure on why these tests failed and it looks like the fileoffset calculated is very huge.
#1 0x00000000004a4952 in lld::pecoff::(anonymous namespace)::DataDirectoryChunk::write (this=0xa81890, fileBuffer=0x7ffff7ff8000 "MZ") at lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp:446
446 std::memcpy(fileBuffer + layout->_fileOffset, content.data(), content.size());
(gdb) print layout->_fileOffset
$1 = 18446744073709541048
http://llvm-reviews.chandlerc.com/D1955
Files:
lib/Driver/Driver.cpp
lib/ReaderWriter/Native/WriterNative.cpp
test/elf/X86_64/dontignorezerosize-sections.test
test/elf/X86_64/largebss.test
test/elf/X86_64/weak-override.test
test/elf/X86_64/weak-zero-sized.test
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -115,9 +115,36 @@
pm.runOnFile(merged);
passTask.end();
+ lld::File *resultFile = &merged;
+
+#ifndef NDEBUG
+ std::unique_ptr<Writer> _nativeWriter =
+ createWriterNative(context);
+ SmallString<128> tmpNativeFile;
+ // Separate the directory from the filename
+ StringRef outFile = llvm::sys::path::filename(context.outputPath());
+ if (error_code ec =
+ llvm::sys::fs::createTemporaryFile(outFile, "native", tmpNativeFile)) {
+ diagnostics << "Failed to write native file ''" << tmpNativeFile.str()
+ << "': " << ec.message() << "\n";
+ return false;
+ }
+ _nativeWriter->writeFile(merged, tmpNativeFile.str());
+ llvm::OwningPtr<llvm::MemoryBuffer> buff;
+ if (error_code ec = llvm::MemoryBuffer::getFileOrSTDIN(tmpNativeFile.str(), buff)) {
+ diagnostics << "Failed to create memory buffer for ''" << tmpNativeFile.str()
+ << "': " << ec.message() << "\n";
+ return false;
+ }
+ std::vector<std::unique_ptr<lld::File>> nativeFile;
+ std::unique_ptr<MemoryBuffer> mb(buff.take());
+ context.getNativeReader().parseFile(mb, nativeFile);
+ resultFile = nativeFile[0].get();
+#endif
+
// Give linked atoms to Writer to generate output file.
ScopedTask writeTask(getDefaultDomain(), "Write");
- if (error_code ec = context.writeFile(merged)) {
+ if (error_code ec = context.writeFile(*resultFile)) {
diagnostics << "Failed to write file '" << context.outputPath()
<< "': " << ec.message() << "\n";
return false;
Index: lib/ReaderWriter/Native/WriterNative.cpp
===================================================================
--- lib/ReaderWriter/Native/WriterNative.cpp
+++ lib/ReaderWriter/Native/WriterNative.cpp
@@ -153,6 +153,9 @@
NativeUndefinedAtomIvarsV1 ivar;
ivar.nameOffset = getNameOffset(atom);
ivar.flags = (atom.canBeNull() & 0x03);
+ ivar.fallbackNameOffset = 0;
+ if (atom.fallback())
+ ivar.fallbackNameOffset = getNameOffset(*atom.fallback());
_undefinedAtomIvars.push_back(ivar);
}
Index: test/elf/X86_64/dontignorezerosize-sections.test
===================================================================
--- test/elf/X86_64/dontignorezerosize-sections.test
+++ test/elf/X86_64/dontignorezerosize-sections.test
@@ -3,9 +3,7 @@
RUN: --noinhibit-exec --output-filetype=yaml -o %t
RUN: FileCheck %s < %t
-CHECK: section-name: .data
CHECK: references:
CHECK: - kind: R_X86_64_16
CHECK: offset: 0
CHECK: target: L000
-CHECK: section-name: .text
Index: test/elf/X86_64/largebss.test
===================================================================
--- test/elf/X86_64/largebss.test
+++ test/elf/X86_64/largebss.test
@@ -10,14 +10,11 @@
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: thread-zero-fill
CHECK: size: 4000
-CHECK: section-name: .tbss
Index: test/elf/X86_64/weak-override.test
===================================================================
--- test/elf/X86_64/weak-override.test
+++ test/elf/X86_64/weak-override.test
@@ -41,7 +41,6 @@
WEAKATOMSORDER: offset: 0
WEAKATOMSORDER: target: [[CONSTSTRA]]
WEAKATOMSORDER: - ref-name: {{[0-9A-Z]+}}
-WEAKATOMSORDER: section-name: .text
WEAKATOMSORDER: references:
WEAKATOMSORDER: - kind: layout-after
WEAKATOMSORDER: offset: 0
Index: test/elf/X86_64/weak-zero-sized.test
===================================================================
--- test/elf/X86_64/weak-zero-sized.test
+++ test/elf/X86_64/weak-zero-sized.test
@@ -10,24 +10,21 @@
WEAKATOMSORDER: - ref-name: [[TARGETA:[-a-zA-Z0-9_]+]]
WEAKATOMSORDER: alignment: 2^2
-WEAKATOMSORDER: section-name: .text
WEAKATOMSORDER: - kind: layout-after
WEAKATOMSORDER: offset: 0
WEAKATOMSORDER: target: [[TARGETB:[-a-zA-Z0-9_]+]]
WEAKATOMSORDER: - name: _start
WEAKATOMSORDER: scope: global
WEAKATOMSORDER: merge: as-weak
WEAKATOMSORDER: alignment: 2^2
-WEAKATOMSORDER: section-name: .text
WEAKATOMSORDER: references:
WEAKATOMSORDER: - kind: layout-after
WEAKATOMSORDER: offset: 0
WEAKATOMSORDER: target: [[TARGETB]]
WEAKATOMSORDER: - ref-name: [[TARGETB]]
WEAKATOMSORDER: scope: global
WEAKATOMSORDER: content: [ C3 ]
WEAKATOMSORDER: alignment: 2^2
-WEAKATOMSORDER: section-name: .text
WEAKATOMSORDER: references:
WEAKATOMSORDER: - kind: layout-before
WEAKATOMSORDER: offset: 0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1955.1.patch
Type: text/x-patch
Size: 5264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131016/ed4ae2f3/attachment.bin>
More information about the llvm-commits
mailing list