Skip to content

Commit 7a11be2

Browse files
committed
[LLD][COFF] Factor out LinkerDriver::setMachine (NFC)
1 parent 845a443 commit 7a11be2

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

lld/COFF/Driver.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,14 @@ std::optional<StringRef> LinkerDriver::findLibIfNew(StringRef filename) {
591591
return path;
592592
}
593593

594+
void LinkerDriver::setMachine(MachineTypes machine) {
595+
assert(ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN);
596+
assert(machine != IMAGE_FILE_MACHINE_UNKNOWN);
597+
598+
ctx.config.machine = machine;
599+
addWinSysRootLibSearchPaths();
600+
}
601+
594602
void LinkerDriver::detectWinSysRoot(const opt::InputArgList &Args) {
595603
IntrusiveRefCntPtr<vfs::FileSystem> VFS = vfs::getRealFileSystem();
596604

@@ -1887,10 +1895,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
18871895
{
18881896
llvm::TimeTraceScope timeScope2("Machine arg");
18891897
if (auto *arg = args.getLastArg(OPT_machine)) {
1890-
config->machine = getMachineType(arg->getValue());
1891-
if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN)
1898+
MachineTypes machine = getMachineType(arg->getValue());
1899+
if (machine == IMAGE_FILE_MACHINE_UNKNOWN)
18921900
Fatal(ctx) << "unknown /machine argument: " << arg->getValue();
1893-
addWinSysRootLibSearchPaths();
1901+
setMachine(machine);
18941902
}
18951903
}
18961904

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

lld/COFF/Driver.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ class LinkerDriver {
8080

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

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

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

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

117+
// Adds various search paths based on the sysroot. Must only be called once
118+
// config->machine has been set.
119+
void addWinSysRootLibSearchPaths();
120+
119121
// Symbol names are mangled by prepending "_" on x86.
120122
StringRef mangle(StringRef sym);
121123

lld/COFF/SymbolTable.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ void SymbolTable::addFile(InputFile *file) {
9595
if (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN &&
9696
mt != IMAGE_FILE_MACHINE_UNKNOWN) {
9797
ctx.config.machineInferred = true;
98-
ctx.config.machine = mt;
99-
ctx.driver.addWinSysRootLibSearchPaths();
98+
ctx.driver.setMachine(mt);
10099
}
101100

102101
ctx.driver.parseDirectives(file);

0 commit comments

Comments
 (0)