Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,14 @@ std::optional<StringRef> LinkerDriver::findLibIfNew(StringRef filename) {
return path;
}

void LinkerDriver::setMachine(MachineTypes machine) {
assert(ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN);
assert(machine != IMAGE_FILE_MACHINE_UNKNOWN);

ctx.config.machine = machine;
addWinSysRootLibSearchPaths();
}

void LinkerDriver::detectWinSysRoot(const opt::InputArgList &Args) {
IntrusiveRefCntPtr<vfs::FileSystem> VFS = vfs::getRealFileSystem();

Expand Down Expand Up @@ -1887,10 +1895,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
{
llvm::TimeTraceScope timeScope2("Machine arg");
if (auto *arg = args.getLastArg(OPT_machine)) {
config->machine = getMachineType(arg->getValue());
if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN)
MachineTypes machine = getMachineType(arg->getValue());
if (machine == IMAGE_FILE_MACHINE_UNKNOWN)
Fatal(ctx) << "unknown /machine argument: " << arg->getValue();
addWinSysRootLibSearchPaths();
setMachine(machine);
}
}

Expand Down Expand Up @@ -2298,8 +2306,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
// not we assume x64.
if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN) {
Warn(ctx) << "/machine is not specified. x64 is assumed";
config->machine = AMD64;
addWinSysRootLibSearchPaths();
setMachine(AMD64);
}
config->wordsize = config->is64() ? 8 : 4;

Expand Down
8 changes: 5 additions & 3 deletions lld/COFF/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ class LinkerDriver {

void linkerMain(llvm::ArrayRef<const char *> args);

// Adds various search paths based on the sysroot. Must only be called once
// config->machine has been set.
void addWinSysRootLibSearchPaths();
void setMachine(llvm::COFF::MachineTypes machine);

void addClangLibSearchPaths(const std::string &argv0);

Expand Down Expand Up @@ -116,6 +114,10 @@ class LinkerDriver {
// Determines the location of the sysroot based on `args`, environment, etc.
void detectWinSysRoot(const llvm::opt::InputArgList &args);

// Adds various search paths based on the sysroot. Must only be called once
// config->machine has been set.
void addWinSysRootLibSearchPaths();

// Symbol names are mangled by prepending "_" on x86.
StringRef mangle(StringRef sym);

Expand Down
3 changes: 1 addition & 2 deletions lld/COFF/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ void SymbolTable::addFile(InputFile *file) {
if (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN &&
mt != IMAGE_FILE_MACHINE_UNKNOWN) {
ctx.config.machineInferred = true;
ctx.config.machine = mt;
ctx.driver.addWinSysRootLibSearchPaths();
ctx.driver.setMachine(mt);
}

ctx.driver.parseDirectives(file);
Expand Down
Loading