Skip to content

Commit 3a5896f

Browse files
MaskRaychencha3
authored andcommitted
[ELF] Move some operations from link to setConfigs. NFC
1 parent d7cdc4e commit 3a5896f

File tree

1 file changed

+31
-37
lines changed

1 file changed

+31
-37
lines changed

lld/ELF/Driver.cpp

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,37 @@ static void setConfigs(opt::InputArgList &args) {
18001800
args.hasFlag(OPT_toc_optimize, OPT_no_toc_optimize, m == EM_PPC64);
18011801
config->pcRelOptimize =
18021802
args.hasFlag(OPT_pcrel_optimize, OPT_no_pcrel_optimize, m == EM_PPC64);
1803+
1804+
if (!args.hasArg(OPT_hash_style)) {
1805+
if (config->emachine == EM_MIPS)
1806+
config->sysvHash = true;
1807+
else
1808+
config->sysvHash = config->gnuHash = true;
1809+
}
1810+
1811+
// Set default entry point and output file if not specified by command line or
1812+
// linker scripts.
1813+
config->warnMissingEntry =
1814+
(!config->entry.empty() || (!config->shared && !config->relocatable));
1815+
if (config->entry.empty() && !config->relocatable)
1816+
config->entry = config->emachine == EM_MIPS ? "__start" : "_start";
1817+
if (config->outputFile.empty())
1818+
config->outputFile = "a.out";
1819+
1820+
// Fail early if the output file or map file is not writable. If a user has a
1821+
// long link, e.g. due to a large LTO link, they do not wish to run it and
1822+
// find that it failed because there was a mistake in their command-line.
1823+
{
1824+
llvm::TimeTraceScope timeScope("Create output files");
1825+
if (auto e = tryCreateFile(config->outputFile))
1826+
error("cannot open output file " + config->outputFile + ": " +
1827+
e.message());
1828+
if (auto e = tryCreateFile(config->mapFile))
1829+
error("cannot open map file " + config->mapFile + ": " + e.message());
1830+
if (auto e = tryCreateFile(config->whyExtract))
1831+
error("cannot open --why-extract= file " + config->whyExtract + ": " +
1832+
e.message());
1833+
}
18031834
}
18041835

18051836
static bool isFormatBinary(StringRef s) {
@@ -2682,43 +2713,6 @@ static void postParseObjectFile(ELFFileBase *file) {
26822713
// all linker scripts have already been parsed.
26832714
void LinkerDriver::link(opt::InputArgList &args) {
26842715
llvm::TimeTraceScope timeScope("Link", StringRef("LinkerDriver::Link"));
2685-
// If a --hash-style option was not given, set to a default value,
2686-
// which varies depending on the target.
2687-
if (!args.hasArg(OPT_hash_style)) {
2688-
if (config->emachine == EM_MIPS)
2689-
config->sysvHash = true;
2690-
else
2691-
config->sysvHash = config->gnuHash = true;
2692-
}
2693-
2694-
// Default output filename is "a.out" by the Unix tradition.
2695-
if (config->outputFile.empty())
2696-
config->outputFile = "a.out";
2697-
2698-
// Fail early if the output file or map file is not writable. If a user has a
2699-
// long link, e.g. due to a large LTO link, they do not wish to run it and
2700-
// find that it failed because there was a mistake in their command-line.
2701-
{
2702-
llvm::TimeTraceScope timeScope("Create output files");
2703-
if (auto e = tryCreateFile(config->outputFile))
2704-
error("cannot open output file " + config->outputFile + ": " +
2705-
e.message());
2706-
if (auto e = tryCreateFile(config->mapFile))
2707-
error("cannot open map file " + config->mapFile + ": " + e.message());
2708-
if (auto e = tryCreateFile(config->whyExtract))
2709-
error("cannot open --why-extract= file " + config->whyExtract + ": " +
2710-
e.message());
2711-
}
2712-
if (errorCount())
2713-
return;
2714-
2715-
// Use default entry point name if no name was given via the command
2716-
// line nor linker scripts. For some reason, MIPS entry point name is
2717-
// different from others.
2718-
config->warnMissingEntry =
2719-
(!config->entry.empty() || (!config->shared && !config->relocatable));
2720-
if (config->entry.empty() && !config->relocatable)
2721-
config->entry = (config->emachine == EM_MIPS) ? "__start" : "_start";
27222716

27232717
// Handle --trace-symbol.
27242718
for (auto *arg : args.filtered(OPT_trace_symbol))

0 commit comments

Comments
 (0)