[PECOFF] Report error if there's unknown flag in .drectve

Errors in .drectve section were silently ignored. This patch fixes the issue.

llvm-svn: 194110
This commit is contained in:
Rui Ueyama 2013-11-05 23:53:15 +00:00
parent 03cb49e159
commit 7e77a294dc
4 changed files with 48 additions and 7 deletions

View File

@ -862,8 +862,8 @@ WinLinkDriver::parse(int argc, const char *argv[], PECOFFLinkingContext &ctx,
// has already done. // has already done.
if (isReadingDirectiveSection) if (isReadingDirectiveSection)
for (auto &e : inputElements) for (auto &e : inputElements)
if (error_code ec = e->parse(ctx, diagnostics)) if (e->parse(ctx, diagnostics))
return ec; return false;
// Add the input files to the input graph. // Add the input files to the input graph.
if (!ctx.hasInputGraph()) if (!ctx.hasInputGraph())

View File

@ -767,7 +767,7 @@ private:
// //
// The section mainly contains /defaultlib (-l in Unix), but can contain any // The section mainly contains /defaultlib (-l in Unix), but can contain any
// options as long as they are valid. // options as long as they are valid.
void handleDirectiveSection(StringRef directives) const { error_code handleDirectiveSection(StringRef directives) const {
DEBUG({ DEBUG({
llvm::dbgs() << ".drectve: " << directives << "\n"; llvm::dbgs() << ".drectve: " << directives << "\n";
}); });
@ -790,13 +790,13 @@ private:
// Print error message if error. // Print error message if error.
if (parseFailed) { if (parseFailed) {
auto msg = llvm::errs() << "Failed to parse '" << directives << "'\n";
Twine("Failed to parse '") + directives + "': " + errorMessage + "\n"; return make_error_code(llvm::object::object_error::invalid_file_type);
llvm::report_fatal_error(msg);
} }
if (!errorMessage.empty()) { if (!errorMessage.empty()) {
llvm::errs() << "lld warning: " << errorMessage << "\n"; llvm::errs() << "lld warning: " << errorMessage << "\n";
} }
return error_code::success();
} }
// //
@ -919,7 +919,8 @@ private:
// Interpret .drectve section if the section has contents. // Interpret .drectve section if the section has contents.
StringRef directives = file->getLinkerDirectives(); StringRef directives = file->getLinkerDirectives();
if (!directives.empty()) if (!directives.empty())
handleDirectiveSection(directives); if (error_code ec = handleDirectiveSection(directives))
return ec;
result.push_back(std::move(file)); result.push_back(std::move(file));
return error_code::success(); return error_code::success();

View File

@ -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
...

View File

@ -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'