[lld] r194110 - [PECOFF] Report error if there's unknown flag in .drectve
Rui Ueyama
ruiu at google.com
Tue Nov 5 15:53:16 PST 2013
Author: ruiu
Date: Tue Nov 5 17:53:15 2013
New Revision: 194110
URL: http://llvm.org/viewvc/llvm-project?rev=194110&view=rev
Log:
[PECOFF] Report error if there's unknown flag in .drectve
Errors in .drectve section were silently ignored. This patch fixes the issue.
Added:
lld/trunk/test/pecoff/Inputs/unknown-drectve.obj.yaml
lld/trunk/test/pecoff/unknown-drectve.test
Modified:
lld/trunk/lib/Driver/WinLinkDriver.cpp
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=194110&r1=194109&r2=194110&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Tue Nov 5 17:53:15 2013
@@ -862,8 +862,8 @@ WinLinkDriver::parse(int argc, const cha
// has already done.
if (isReadingDirectiveSection)
for (auto &e : inputElements)
- if (error_code ec = e->parse(ctx, diagnostics))
- return ec;
+ if (e->parse(ctx, diagnostics))
+ return false;
// Add the input files to the input graph.
if (!ctx.hasInputGraph())
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=194110&r1=194109&r2=194110&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Tue Nov 5 17:53:15 2013
@@ -767,7 +767,7 @@ private:
//
// The section mainly contains /defaultlib (-l in Unix), but can contain any
// options as long as they are valid.
- void handleDirectiveSection(StringRef directives) const {
+ error_code handleDirectiveSection(StringRef directives) const {
DEBUG({
llvm::dbgs() << ".drectve: " << directives << "\n";
});
@@ -790,13 +790,13 @@ private:
// Print error message if error.
if (parseFailed) {
- auto msg =
- Twine("Failed to parse '") + directives + "': " + errorMessage + "\n";
- llvm::report_fatal_error(msg);
+ llvm::errs() << "Failed to parse '" << directives << "'\n";
+ return make_error_code(llvm::object::object_error::invalid_file_type);
}
if (!errorMessage.empty()) {
llvm::errs() << "lld warning: " << errorMessage << "\n";
}
+ return error_code::success();
}
//
@@ -919,7 +919,8 @@ private:
// Interpret .drectve section if the section has contents.
StringRef directives = file->getLinkerDirectives();
if (!directives.empty())
- handleDirectiveSection(directives);
+ if (error_code ec = handleDirectiveSection(directives))
+ return ec;
result.push_back(std::move(file));
return error_code::success();
Added: lld/trunk/test/pecoff/Inputs/unknown-drectve.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/unknown-drectve.obj.yaml?rev=194110&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/unknown-drectve.obj.yaml (added)
+++ lld/trunk/test/pecoff/Inputs/unknown-drectve.obj.yaml Tue Nov 5 17:53:15 2013
@@ -0,0 +1,34 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 558BEC56FF15000000008B0D000000008B3103F0FF150000000003C65E5DC3
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+
+ # /nosuchoption:foobar
+ SectionData: 2f6e6f737563686f7074696f6e3a666f6f62617200
+
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ NumberOfAuxSymbols: 1
+ AuxiliaryData: 1F000000030000008C7450D6000000000000
+ - Name: .drectve
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ NumberOfAuxSymbols: 1
+ AuxiliaryData: 0D0000000000000000000000000000000000
+...
Added: lld/trunk/test/pecoff/unknown-drectve.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/unknown-drectve.test?rev=194110&view=auto
==============================================================================
--- lld/trunk/test/pecoff/unknown-drectve.test (added)
+++ lld/trunk/test/pecoff/unknown-drectve.test Tue Nov 5 17:53:15 2013
@@ -0,0 +1,6 @@
+# RUN: yaml2obj %p/Inputs/unknown-drectve.obj.yaml > %t.obj
+#
+# RUN: not lld -flavor link /out:%t.exe -- %t.obj >& %t.log
+# RUN: FileCheck -check-prefix=ERROR %s < %t.log
+
+ERROR: Failed to parse '/nosuchoption:foobar'
More information about the llvm-commits
mailing list