From 562daa81485e8f5b733215d03294aa209f1f1094 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 18 Jun 2015 21:50:38 +0000 Subject: [PATCH] COFF: Unknown options in .drectve section is an error. We skip unknown options in the command line with a warning message being printed out, but we shouldn't do that for .drectve section. The section is not visible to the user. We should handle unknown options as an error. llvm-svn: 240067 --- lld/COFF/Driver.cpp | 54 +++++++++++++++++++++++++--------------------- lld/test/COFF/baserel.test | 16 -------------- 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 9c2e53e..cdc3793 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -9,6 +9,7 @@ #include "Config.h" #include "Driver.h" +#include "Error.h" #include "InputFiles.h" #include "SymbolTable.h" #include "Writer.h" @@ -91,32 +92,35 @@ LinkerDriver::parseDirectives(StringRef S, return EC; std::unique_ptr Args = std::move(ArgsOrErr.get()); - // Handle /export - for (auto *Arg : Args->filtered(OPT_export)) { - ErrorOr E = parseExport(Arg->getValue()); - if (auto EC = E.getError()) - return EC; - Config->Exports.push_back(E.get()); - } - - // Handle /alternatename - for (auto *Arg : Args->filtered(OPT_alternatename)) - if (auto EC = parseAlternateName(Arg->getValue())) - return EC; - - // Handle /failifmismatch - for (auto *Arg : Args->filtered(OPT_failifmismatch)) - if (auto EC = checkFailIfMismatch(Arg->getValue())) - return EC; - - // Handle /defaultlib - for (auto *Arg : Args->filtered(OPT_defaultlib)) { - if (Optional Path = findLib(Arg->getValue())) { - ErrorOr MBOrErr = openFile(*Path); - if (auto EC = MBOrErr.getError()) + for (auto *Arg : *Args) { + switch (Arg->getOption().getID()) { + case OPT_alternatename: + if (auto EC = parseAlternateName(Arg->getValue())) + return EC; + break; + case OPT_defaultlib: + if (Optional Path = findLib(Arg->getValue())) { + ErrorOr MBOrErr = openFile(*Path); + if (auto EC = MBOrErr.getError()) + return EC; + std::unique_ptr File = createFile(MBOrErr.get()); + Res->push_back(std::move(File)); + } + break; + case OPT_export: { + ErrorOr E = parseExport(Arg->getValue()); + if (auto EC = E.getError()) + return EC; + Config->Exports.push_back(E.get()); + break; + } + case OPT_failifmismatch: + if (auto EC = checkFailIfMismatch(Arg->getValue())) return EC; - std::unique_ptr File = createFile(MBOrErr.get()); - Res->push_back(std::move(File)); + break; + default: + llvm::errs() << Arg->getSpelling() << " is not allowed in .drectve\n"; + return make_error_code(LLDError::InvalidOption); } } return std::error_code(); diff --git a/lld/test/COFF/baserel.test b/lld/test/COFF/baserel.test index 5822717..ae6bb32 100644 --- a/lld/test/COFF/baserel.test +++ b/lld/test/COFF/baserel.test @@ -127,10 +127,6 @@ sections: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] Alignment: 4 SectionData: 48656C6C6F0048656C6C6F20576F726C6400 - - Name: .drectve - Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] - Alignment: 2147483648 - SectionData: 2F454E5452593A6D61696E20 symbols: - Name: "@comp.id" Value: 10394907 @@ -204,18 +200,6 @@ symbols: SimpleType: IMAGE_SYM_TYPE_NULL ComplexType: IMAGE_SYM_DTYPE_NULL StorageClass: IMAGE_SYM_CLASS_STATIC - - Name: .drectve - Value: 0 - SectionNumber: 3 - SimpleType: IMAGE_SYM_TYPE_NULL - ComplexType: IMAGE_SYM_DTYPE_NULL - StorageClass: IMAGE_SYM_CLASS_STATIC - SectionDefinition: - Length: 12 - NumberOfRelocations: 0 - NumberOfLinenumbers: 0 - CheckSum: 0 - Number: 0 - Name: abs_symbol Value: 0xDEADBEEF SectionNumber: -1 -- 2.7.4