[lld] 0a9810d - [LLD][COFF] Factor out LinkerDriver::setMachine (NFC) (#119297)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 15 09:41:30 PST 2024
Author: Jacek Caban
Date: 2024-12-15T18:41:26+01:00
New Revision: 0a9810d32599e515236940ce15631cfa8586d403
URL: https://github.com/llvm/llvm-project/commit/0a9810d32599e515236940ce15631cfa8586d403
DIFF: https://github.com/llvm/llvm-project/commit/0a9810d32599e515236940ce15631cfa8586d403.diff
LOG: [LLD][COFF] Factor out LinkerDriver::setMachine (NFC) (#119297)
Added:
Modified:
lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/SymbolTable.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index b47b3ffec0a908..5a3db548463181 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -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();
@@ -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);
}
}
@@ -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;
diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h
index 3889feb7511c0a..e94a961953581f 100644
--- a/lld/COFF/Driver.h
+++ b/lld/COFF/Driver.h
@@ -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);
@@ -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);
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 942e7ceda1ebe3..d6cf10756e2963 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -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);
More information about the llvm-commits
mailing list