#include "llvm/ADT/StringRef.h"
#include "llvm/Object/COFF.h"
#include <cstdint>
+#include <map>
#include <set>
#include <string>
std::set<StringRef> NoDefaultLibs;
bool NoDefaultLibAll = false;
+ // Used by /failifmismatch option.
+ std::map<StringRef, StringRef> MustMatch;
+
uint64_t ImageBase = 0x140000000;
uint64_t StackReserve = 1024 * 1024;
uint64_t StackCommit = 4096;
return EC;
std::unique_ptr<llvm::opt::InputArgList> Args = std::move(ArgsOrErr.get());
+ // Handle /failifmismatch
+ if (auto EC = checkFailIfMismatch(Args.get()))
+ return EC;
+
+ // Handle /defaultlib
for (auto *Arg : Args->filtered(OPT_defaultlib)) {
if (Optional<StringRef> Path = findLib(Arg->getValue())) {
auto FileOrErr = openFile(*Path);
}
}
+ // Handle /failifmismatch
+ if (auto EC = checkFailIfMismatch(Args.get())) {
+ llvm::errs() << "/failifmismatch: " << EC.message() << "\n";
+ return false;
+ }
+
// Create a list of input files. Files can be given as arguments
// for /defaultlib option.
std::vector<StringRef> Inputs;
std::error_code parseSubsystem(StringRef Arg, WindowsSubsystem *Sys,
uint32_t *Major, uint32_t *Minor);
+// Parses a string in the form of "key=value" and check
+// if value matches previous values for the key.
+// This feature used in the directive section to reject
+// incompatible objects.
+std::error_code checkFailIfMismatch(llvm::opt::InputArgList *Args);
+
// Create enum with OPT_xxx values for each option in Options.td
enum {
OPT_INVALID = 0,
//
//===----------------------------------------------------------------------===//
+#include "Config.h"
#include "Driver.h"
#include "Error.h"
#include "Memory.h"
return std::error_code();
}
+// Parses a string in the form of "key=value" and check
+// if value matches previous values for the same key.
+std::error_code checkFailIfMismatch(llvm::opt::InputArgList *Args) {
+ for (auto *Arg : Args->filtered(OPT_failifmismatch)) {
+ StringRef K, V;
+ std::tie(K, V) = StringRef(Arg->getValue()).split('=');
+ if (K.empty() || V.empty()) {
+ llvm::errs() << "/failifmismatch: invalid argument: "
+ << Arg->getValue() << "\n";
+ return make_error_code(LLDError::InvalidOption);
+ }
+ StringRef Existing = Config->MustMatch[K];
+ if (!Existing.empty() && V != Existing) {
+ llvm::errs() << "/failifmismatch: mismatch detected: "
+ << Existing << " and " << V
+ << " for key " << K << "\n";
+ return make_error_code(LLDError::InvalidOption);
+ }
+ Config->MustMatch[K] = V;
+ }
+ return std::error_code();
+}
+
// Create OptTable
// Create prefix string literals used in Options.td
--- /dev/null
+# RUN: lld -flavor link2 /entry:main /subsystem:console /out:%t.exe \
+# RUN: %p/Inputs/ret42.obj
+
+# RUN: lld -flavor link2 /entry:main /subsystem:console /out:%t.exe \
+# RUN: %p/Inputs/ret42.obj /failifmismatch:k1=v1 /failifmismatch:k2=v1
+
+# RUN: lld -flavor link2 /entry:main /subsystem:console /out:%t.exe \
+# RUN: %p/Inputs/ret42.obj /failifmismatch:k1=v1 /failifmismatch:k1=v1
+
+# RUN: not lld -flavor link2 /entry:main /subsystem:console /out:%t.exe \
+# RUN: %p/Inputs/ret42.obj /failifmismatch:k1=v1 /failifmismatch:k1=v2