@@ -20,21 +20,19 @@ using namespace clang::driver::toolchains;
20
20
using namespace clang ;
21
21
using namespace llvm ::opt;
22
22
23
- // / DragonFly Tools
24
-
25
- // For now, DragonFly Assemble does just about the same as for
26
- // FreeBSD, but this may change soon.
27
23
void dragonfly::Assembler::ConstructJob (Compilation &C, const JobAction &JA,
28
24
const InputInfo &Output,
29
25
const InputInfoList &Inputs,
30
26
const ArgList &Args,
31
27
const char *LinkingOutput) const {
32
- claimNoWarnArgs (Args );
28
+ const auto &ToolChain = static_cast < const DragonFly &>( getToolChain () );
33
29
ArgStringList CmdArgs;
34
30
31
+ claimNoWarnArgs (Args);
32
+
35
33
// When building 32-bit code on DragonFly/pc64, we have to explicitly
36
34
// instruct as in the base system to assemble 32-bit code.
37
- if (getToolChain () .getArch () == llvm::Triple::x86)
35
+ if (ToolChain .getArch () == llvm::Triple::x86)
38
36
CmdArgs.push_back (" --32" );
39
37
40
38
Args.AddAllArgValues (CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
@@ -45,7 +43,7 @@ void dragonfly::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
45
43
for (const auto &II : Inputs)
46
44
CmdArgs.push_back (II.getFilename ());
47
45
48
- const char *Exec = Args.MakeArgString (getToolChain () .GetProgramPath (" as" ));
46
+ const char *Exec = Args.MakeArgString (ToolChain .GetProgramPath (" as" ));
49
47
C.addCommand (std::make_unique<Command>(JA, *this ,
50
48
ResponseFileSupport::AtFileCurCP (),
51
49
Exec, CmdArgs, Inputs, Output));
@@ -58,18 +56,23 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
58
56
const char *LinkingOutput) const {
59
57
const auto &ToolChain = static_cast <const DragonFly &>(getToolChain ());
60
58
const Driver &D = ToolChain.getDriver ();
59
+ const llvm::Triple::ArchType Arch = ToolChain.getArch ();
61
60
ArgStringList CmdArgs;
61
+ bool Static = Args.hasArg (options::OPT_static);
62
+ bool Shared = Args.hasArg (options::OPT_shared);
63
+ bool Profiling = Args.hasArg (options::OPT_pg);
64
+ bool Pie = Args.hasArg (options::OPT_pie);
62
65
63
66
if (!D.SysRoot .empty ())
64
67
CmdArgs.push_back (Args.MakeArgString (" --sysroot=" + D.SysRoot ));
65
68
66
69
CmdArgs.push_back (" --eh-frame-hdr" );
67
- if (Args. hasArg (options::OPT_static) ) {
70
+ if (Static ) {
68
71
CmdArgs.push_back (" -Bstatic" );
69
72
} else {
70
73
if (Args.hasArg (options::OPT_rdynamic))
71
74
CmdArgs.push_back (" -export-dynamic" );
72
- if (Args. hasArg (options::OPT_shared) )
75
+ if (Shared )
73
76
CmdArgs.push_back (" -shared" );
74
77
else if (!Args.hasArg (options::OPT_r)) {
75
78
CmdArgs.push_back (" -dynamic-linker" );
@@ -81,7 +84,7 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
81
84
82
85
// When building 32-bit code on DragonFly/pc64, we have to explicitly
83
86
// instruct ld in the base system to link 32-bit code.
84
- if (getToolChain (). getArch () == llvm::Triple::x86) {
87
+ if (Arch == llvm::Triple::x86) {
85
88
CmdArgs.push_back (" -m" );
86
89
CmdArgs.push_back (" elf_i386" );
87
90
}
@@ -94,67 +97,66 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
94
97
95
98
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nostartfiles,
96
99
options::OPT_r)) {
97
- if (!Args.hasArg (options::OPT_shared)) {
98
- if (Args.hasArg (options::OPT_pg))
99
- CmdArgs.push_back (
100
- Args.MakeArgString (getToolChain ().GetFilePath (" gcrt1.o" )));
100
+ const char *crt1 = nullptr ;
101
+ const char *crtbegin = nullptr ;
102
+ if (!Shared) {
103
+ if (Profiling)
104
+ crt1 = " gcrt1.o" ;
101
105
else {
102
- if (Args.hasArg (options::OPT_pie))
103
- CmdArgs.push_back (
104
- Args.MakeArgString (getToolChain ().GetFilePath (" Scrt1.o" )));
106
+ if (Pie)
107
+ crt1 = " Scrt1.o" ;
105
108
else
106
- CmdArgs.push_back (
107
- Args.MakeArgString (getToolChain ().GetFilePath (" crt1.o" )));
109
+ crt1 = " crt1.o" ;
108
110
}
109
111
}
110
- CmdArgs.push_back (Args.MakeArgString (getToolChain ().GetFilePath (" crti.o" )));
111
- if (Args.hasArg (options::OPT_shared) || Args.hasArg (options::OPT_pie))
112
- CmdArgs.push_back (
113
- Args.MakeArgString (getToolChain ().GetFilePath (" crtbeginS.o" )));
112
+
113
+ if (Shared || Pie)
114
+ crtbegin = " crtbeginS.o" ;
114
115
else
115
- CmdArgs.push_back (
116
- Args.MakeArgString (getToolChain ().GetFilePath (" crtbegin.o" )));
116
+ crtbegin = " crtbegin.o" ;
117
+
118
+ if (crt1)
119
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (crt1)));
120
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (" crti.o" )));
121
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (crtbegin)));
117
122
}
118
123
119
124
Args.addAllArgs (CmdArgs, {options::OPT_L, options::OPT_T_Group,
120
125
options::OPT_s, options::OPT_t, options::OPT_r});
121
126
ToolChain.AddFilePathLibArgs (Args, CmdArgs);
122
127
123
- AddLinkerInputs (getToolChain () , Inputs, Args, CmdArgs, JA);
128
+ AddLinkerInputs (ToolChain , Inputs, Args, CmdArgs, JA);
124
129
125
130
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nodefaultlibs,
126
131
options::OPT_r)) {
127
- if (!Args. hasArg (options::OPT_static) ) {
132
+ if (!Static ) {
128
133
CmdArgs.push_back (" -rpath" );
129
134
CmdArgs.push_back (" /usr/lib/gcc80" );
130
135
}
131
136
132
137
// Use the static OpenMP runtime with -static-openmp
133
- bool StaticOpenMP = Args.hasArg (options::OPT_static_openmp) &&
134
- !Args.hasArg (options::OPT_static);
138
+ bool StaticOpenMP = Args.hasArg (options::OPT_static_openmp) && !Static;
135
139
addOpenMPRuntime (CmdArgs, ToolChain, Args, StaticOpenMP);
136
140
137
141
if (D.CCCIsCXX ()) {
138
- if (getToolChain () .ShouldLinkCXXStdlib (Args))
139
- getToolChain () .AddCXXStdlibLibArgs (Args, CmdArgs);
142
+ if (ToolChain .ShouldLinkCXXStdlib (Args))
143
+ ToolChain .AddCXXStdlibLibArgs (Args, CmdArgs);
140
144
CmdArgs.push_back (" -lm" );
141
145
}
142
146
143
147
if (Args.hasArg (options::OPT_pthread))
144
148
CmdArgs.push_back (" -lpthread" );
145
149
146
- if (!Args.hasArg (options::OPT_nolibc)) {
150
+ if (!Args.hasArg (options::OPT_nolibc))
147
151
CmdArgs.push_back (" -lc" );
148
- }
149
152
150
- if (Args.hasArg (options::OPT_static) ||
151
- Args.hasArg (options::OPT_static_libgcc)) {
153
+ if (Static || Args.hasArg (options::OPT_static_libgcc)) {
152
154
CmdArgs.push_back (" -lgcc" );
153
155
CmdArgs.push_back (" -lgcc_eh" );
154
156
} else {
155
157
if (Args.hasArg (options::OPT_shared_libgcc)) {
156
158
CmdArgs.push_back (" -lgcc_pic" );
157
- if (!Args. hasArg (options::OPT_shared) )
159
+ if (!Shared )
158
160
CmdArgs.push_back (" -lgcc" );
159
161
} else {
160
162
CmdArgs.push_back (" -lgcc" );
@@ -167,18 +169,19 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
167
169
168
170
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nostartfiles,
169
171
options::OPT_r)) {
170
- if (Args. hasArg (options::OPT_shared) || Args. hasArg (options::OPT_pie))
171
- CmdArgs. push_back (
172
- Args. MakeArgString ( getToolChain (). GetFilePath ( " crtendS.o" ))) ;
172
+ const char *crtend = nullptr ;
173
+ if (Shared || Pie)
174
+ crtend = " crtendS.o" ;
173
175
else
174
- CmdArgs.push_back (
175
- Args.MakeArgString (getToolChain ().GetFilePath (" crtend.o" )));
176
- CmdArgs.push_back (Args.MakeArgString (getToolChain ().GetFilePath (" crtn.o" )));
176
+ crtend = " crtend.o" ;
177
+
178
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (crtend)));
179
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (" crtn.o" )));
177
180
}
178
181
179
- getToolChain () .addProfileRTLibs (Args, CmdArgs);
182
+ ToolChain .addProfileRTLibs (Args, CmdArgs);
180
183
181
- const char *Exec = Args.MakeArgString (getToolChain () .GetLinkerPath ());
184
+ const char *Exec = Args.MakeArgString (ToolChain .GetLinkerPath ());
182
185
C.addCommand (std::make_unique<Command>(JA, *this ,
183
186
ResponseFileSupport::AtFileCurCP (),
184
187
Exec, CmdArgs, Inputs, Output));
0 commit comments