@@ -30,13 +30,12 @@ void netbsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
30
30
const InputInfoList &Inputs,
31
31
const ArgList &Args,
32
32
const char *LinkingOutput) const {
33
- const toolchains::NetBSD &ToolChain =
34
- static_cast <const toolchains::NetBSD &>(getToolChain ());
33
+ const auto &ToolChain = static_cast <const NetBSD &>(getToolChain ());
35
34
const Driver &D = ToolChain.getDriver ();
36
35
const llvm::Triple &Triple = ToolChain.getTriple ();
36
+ ArgStringList CmdArgs;
37
37
38
38
claimNoWarnArgs (Args);
39
- ArgStringList CmdArgs;
40
39
41
40
// GNU as needs different flags for creating the correct output format
42
41
// on architectures with different ABIs or optional feature sets.
@@ -118,27 +117,29 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
118
117
const InputInfoList &Inputs,
119
118
const ArgList &Args,
120
119
const char *LinkingOutput) const {
121
- const toolchains::NetBSD &ToolChain =
122
- static_cast <const toolchains::NetBSD &>(getToolChain ());
120
+ const auto &ToolChain = static_cast <const NetBSD &>(getToolChain ());
123
121
const Driver &D = ToolChain.getDriver ();
124
122
const llvm::Triple &Triple = ToolChain.getTriple ();
125
-
123
+ const llvm::Triple::ArchType Arch = ToolChain.getArch ();
124
+ const bool Static = Args.hasArg (options::OPT_static);
125
+ const bool Shared = Args.hasArg (options::OPT_shared);
126
+ const bool Pie = Args.hasArg (options::OPT_pie);
126
127
ArgStringList CmdArgs;
127
128
128
129
if (!D.SysRoot .empty ())
129
130
CmdArgs.push_back (Args.MakeArgString (" --sysroot=" + D.SysRoot ));
130
131
131
132
CmdArgs.push_back (" --eh-frame-hdr" );
132
- if (Args. hasArg (options::OPT_static) ) {
133
+ if (Static ) {
133
134
CmdArgs.push_back (" -Bstatic" );
134
- if (Args. hasArg (options::OPT_pie) ) {
135
+ if (Pie ) {
135
136
Args.AddAllArgs (CmdArgs, options::OPT_pie);
136
137
CmdArgs.push_back (" --no-dynamic-linker" );
137
138
}
138
139
} else {
139
140
if (Args.hasArg (options::OPT_rdynamic))
140
141
CmdArgs.push_back (" -export-dynamic" );
141
- if (Args. hasArg (options::OPT_shared) ) {
142
+ if (Shared ) {
142
143
CmdArgs.push_back (" -shared" );
143
144
} else if (!Args.hasArg (options::OPT_r)) {
144
145
Args.AddAllArgs (CmdArgs, options::OPT_pie);
@@ -149,7 +150,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
149
150
150
151
// Many NetBSD architectures support more than one ABI.
151
152
// Determine the correct emulation for ld.
152
- switch (ToolChain. getArch () ) {
153
+ switch (Arch ) {
153
154
case llvm::Triple::x86:
154
155
CmdArgs.push_back (" -m" );
155
156
CmdArgs.push_back (" elf_i386" );
@@ -193,13 +194,13 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
193
194
case llvm::Triple::mips64el:
194
195
if (mips::hasMipsAbiArg (Args, " 32" )) {
195
196
CmdArgs.push_back (" -m" );
196
- if (ToolChain. getArch () == llvm::Triple::mips64)
197
+ if (Arch == llvm::Triple::mips64)
197
198
CmdArgs.push_back (" elf32btsmip" );
198
199
else
199
200
CmdArgs.push_back (" elf32ltsmip" );
200
201
} else if (mips::hasMipsAbiArg (Args, " 64" )) {
201
202
CmdArgs.push_back (" -m" );
202
- if (ToolChain. getArch () == llvm::Triple::mips64)
203
+ if (Arch == llvm::Triple::mips64)
203
204
CmdArgs.push_back (" elf64btsmip" );
204
205
else
205
206
CmdArgs.push_back (" elf64ltsmip" );
@@ -251,19 +252,20 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
251
252
252
253
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nostartfiles,
253
254
options::OPT_r)) {
254
- if (!Args.hasArg (options::OPT_shared)) {
255
- CmdArgs.push_back (
256
- Args.MakeArgString (ToolChain.GetFilePath (" crt0.o" )));
257
- }
258
- CmdArgs.push_back (
259
- Args.MakeArgString (ToolChain.GetFilePath (" crti.o" )));
260
- if (Args.hasArg (options::OPT_shared) || Args.hasArg (options::OPT_pie)) {
261
- CmdArgs.push_back (
262
- Args.MakeArgString (ToolChain.GetFilePath (" crtbeginS.o" )));
263
- } else {
264
- CmdArgs.push_back (
265
- Args.MakeArgString (ToolChain.GetFilePath (" crtbegin.o" )));
266
- }
255
+ const char *crt0 = nullptr ;
256
+ const char *crtbegin = nullptr ;
257
+ if (!Shared)
258
+ crt0 = " crt0.o" ;
259
+
260
+ if (Shared || Pie)
261
+ crtbegin = " crtbeginS.o" ;
262
+ else
263
+ crtbegin = " crtbegin.o" ;
264
+
265
+ if (crt0)
266
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (crt0)));
267
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (" crti.o" )));
268
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (crtbegin)));
267
269
}
268
270
269
271
Args.addAllArgs (CmdArgs, {options::OPT_L, options::OPT_T_Group,
@@ -305,8 +307,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
305
307
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nodefaultlibs,
306
308
options::OPT_r)) {
307
309
// Use the static OpenMP runtime with -static-openmp
308
- bool StaticOpenMP = Args.hasArg (options::OPT_static_openmp) &&
309
- !Args.hasArg (options::OPT_static);
310
+ bool StaticOpenMP = Args.hasArg (options::OPT_static_openmp) && !Static;
310
311
addOpenMPRuntime (CmdArgs, ToolChain, Args, StaticOpenMP);
311
312
312
313
if (D.CCCIsCXX ()) {
@@ -323,7 +324,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
323
324
CmdArgs.push_back (" -lc" );
324
325
325
326
if (useLibgcc) {
326
- if (Args. hasArg (options::OPT_static) ) {
327
+ if (Static ) {
327
328
// libgcc_eh depends on libc, so resolve as much as possible,
328
329
// pull in any new requirements from libc and then get the rest
329
330
// of libgcc.
@@ -341,12 +342,13 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
341
342
342
343
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nostartfiles,
343
344
options::OPT_r)) {
344
- if (Args. hasArg (options::OPT_shared) || Args. hasArg (options::OPT_pie))
345
- CmdArgs. push_back (
346
- Args. MakeArgString (ToolChain. GetFilePath ( " crtendS.o" ))) ;
345
+ const char *crtend = nullptr ;
346
+ if (Shared || Pie)
347
+ crtend = " crtendS.o" ;
347
348
else
348
- CmdArgs.push_back (
349
- Args.MakeArgString (ToolChain.GetFilePath (" crtend.o" )));
349
+ crtend = " crtend.o" ;
350
+
351
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (crtend)));
350
352
CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (" crtn.o" )));
351
353
}
352
354
0 commit comments