[lld] 1bab88d - [ELF] Move some operations from link to setConfigs. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 16:44:30 PDT 2024
Author: Fangrui Song
Date: 2024-03-19T16:44:25-07:00
New Revision: 1bab88df075d87dd66e8a54d88d16f8540452b8f
URL: https://github.com/llvm/llvm-project/commit/1bab88df075d87dd66e8a54d88d16f8540452b8f
DIFF: https://github.com/llvm/llvm-project/commit/1bab88df075d87dd66e8a54d88d16f8540452b8f.diff
LOG: [ELF] Move some operations from link to setConfigs. NFC
Added:
Modified:
lld/ELF/Driver.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index e7160a47bd2142..40d3f2caa133eb 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1800,6 +1800,37 @@ static void setConfigs(opt::InputArgList &args) {
args.hasFlag(OPT_toc_optimize, OPT_no_toc_optimize, m == EM_PPC64);
config->pcRelOptimize =
args.hasFlag(OPT_pcrel_optimize, OPT_no_pcrel_optimize, m == EM_PPC64);
+
+ if (!args.hasArg(OPT_hash_style)) {
+ if (config->emachine == EM_MIPS)
+ config->sysvHash = true;
+ else
+ config->sysvHash = config->gnuHash = true;
+ }
+
+ // Set default entry point and output file if not specified by command line or
+ // linker scripts.
+ config->warnMissingEntry =
+ (!config->entry.empty() || (!config->shared && !config->relocatable));
+ if (config->entry.empty() && !config->relocatable)
+ config->entry = config->emachine == EM_MIPS ? "__start" : "_start";
+ if (config->outputFile.empty())
+ config->outputFile = "a.out";
+
+ // Fail early if the output file or map file is not writable. If a user has a
+ // long link, e.g. due to a large LTO link, they do not wish to run it and
+ // find that it failed because there was a mistake in their command-line.
+ {
+ llvm::TimeTraceScope timeScope("Create output files");
+ if (auto e = tryCreateFile(config->outputFile))
+ error("cannot open output file " + config->outputFile + ": " +
+ e.message());
+ if (auto e = tryCreateFile(config->mapFile))
+ error("cannot open map file " + config->mapFile + ": " + e.message());
+ if (auto e = tryCreateFile(config->whyExtract))
+ error("cannot open --why-extract= file " + config->whyExtract + ": " +
+ e.message());
+ }
}
static bool isFormatBinary(StringRef s) {
@@ -2682,43 +2713,6 @@ static void postParseObjectFile(ELFFileBase *file) {
// all linker scripts have already been parsed.
void LinkerDriver::link(opt::InputArgList &args) {
llvm::TimeTraceScope timeScope("Link", StringRef("LinkerDriver::Link"));
- // If a --hash-style option was not given, set to a default value,
- // which varies depending on the target.
- if (!args.hasArg(OPT_hash_style)) {
- if (config->emachine == EM_MIPS)
- config->sysvHash = true;
- else
- config->sysvHash = config->gnuHash = true;
- }
-
- // Default output filename is "a.out" by the Unix tradition.
- if (config->outputFile.empty())
- config->outputFile = "a.out";
-
- // Fail early if the output file or map file is not writable. If a user has a
- // long link, e.g. due to a large LTO link, they do not wish to run it and
- // find that it failed because there was a mistake in their command-line.
- {
- llvm::TimeTraceScope timeScope("Create output files");
- if (auto e = tryCreateFile(config->outputFile))
- error("cannot open output file " + config->outputFile + ": " +
- e.message());
- if (auto e = tryCreateFile(config->mapFile))
- error("cannot open map file " + config->mapFile + ": " + e.message());
- if (auto e = tryCreateFile(config->whyExtract))
- error("cannot open --why-extract= file " + config->whyExtract + ": " +
- e.message());
- }
- if (errorCount())
- return;
-
- // Use default entry point name if no name was given via the command
- // line nor linker scripts. For some reason, MIPS entry point name is
- //
diff erent from others.
- config->warnMissingEntry =
- (!config->entry.empty() || (!config->shared && !config->relocatable));
- if (config->entry.empty() && !config->relocatable)
- config->entry = (config->emachine == EM_MIPS) ? "__start" : "_start";
// Handle --trace-symbol.
for (auto *arg : args.filtered(OPT_trace_symbol))
More information about the llvm-commits
mailing list