File tree Expand file tree Collapse file tree 3 files changed +49
-10
lines changed Expand file tree Collapse file tree 3 files changed +49
-10
lines changed Original file line number Diff line number Diff line change @@ -137,9 +137,6 @@ void LinkerDriver::enqueuePath(StringRef Path) {
137
137
fatal (MBOrErr.second , " could not open " + PathStr);
138
138
Driver->addBuffer (std::move (MBOrErr.first ));
139
139
});
140
-
141
- if (Config->OutputFile == " " )
142
- Config->OutputFile = getOutputPath (Path);
143
140
}
144
141
145
142
void LinkerDriver::addArchiveBuffer (MemoryBufferRef MB, StringRef SymName,
@@ -887,6 +884,12 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
887
884
}
888
885
}
889
886
887
+ // Set default image name if neither /out or /def set it.
888
+ if (Config->OutputFile .empty ()) {
889
+ Config->OutputFile =
890
+ getOutputPath ((*Args.filtered_begin (OPT_INPUT))->getValue ());
891
+ }
892
+
890
893
// Set default image base if /base is not given.
891
894
if (Config->ImageBase == uint64_t (-1 ))
892
895
Config->ImageBase = getDefaultImageBase ();
Original file line number Diff line number Diff line change @@ -163,17 +163,25 @@ class Parser {
163
163
case KwHeapsize:
164
164
parseNumbers (&Config->HeapReserve , &Config->HeapCommit );
165
165
return ;
166
- case KwLibrary:
167
- parseName (&Config->OutputFile , &Config->ImageBase );
168
- if (!StringRef (Config->OutputFile ).endswith_lower (" .dll" ))
169
- Config->OutputFile += " .dll" ;
170
- return ;
171
166
case KwStacksize:
172
167
parseNumbers (&Config->StackReserve , &Config->StackCommit );
173
168
return ;
174
- case KwName:
175
- parseName (&Config->OutputFile , &Config->ImageBase );
169
+ case KwLibrary:
170
+ case KwName: {
171
+ bool IsDll = Tok.K == KwLibrary; // Check before parseName.
172
+ std::string Name;
173
+ parseName (&Name, &Config->ImageBase );
174
+
175
+ // Append the appropriate file extension if not already present.
176
+ StringRef Ext = IsDll ? " .dll" : " .exe" ;
177
+ if (!StringRef (Name).endswith_lower (Ext))
178
+ Name += Ext;
179
+
180
+ // Set the output file, but don't override /out if it was already passed.
181
+ if (Config->OutputFile .empty ())
182
+ Config->OutputFile = Name;
176
183
return ;
184
+ }
177
185
case KwVersion:
178
186
parseVersion (&Config->MajorImageVersion , &Config->MinorImageVersion );
179
187
return ;
Original file line number Diff line number Diff line change
1
+ # REQUIRES: winres
2
+
3
+ # RUN: rm -rf %t
4
+ # RUN: mkdir -p %t
5
+ # RUN: cd %t
6
+ # RUN: yaml2obj < %p/Inputs/ret42.yaml > in.obj
7
+
8
+ # RUN: lld-link /entry:main in.obj
9
+ # RUN: lld-link /entry:main /dll in.obj
10
+
11
+ # RUN: echo -e "NAME foo\n" > fooexe.def
12
+ # RUN: echo -e "LIBRARY foo\n" > foodll.def
13
+ # RUN: lld-link /entry:main /def:fooexe.def in.obj
14
+ # RUN: lld-link /entry:main /def:foodll.def /dll in.obj
15
+
16
+ # RUN: lld-link /entry:main /out:bar.exe /def:fooexe.def in.obj
17
+ # RUN: lld-link /entry:main /out:bar.dll /def:foodll.def /dll in.obj
18
+
19
+ # RUN: llvm-readobj in.exe | FileCheck %s
20
+ # RUN: llvm-readobj in.dll | FileCheck %s
21
+
22
+ # RUN: llvm-readobj foo.exe | FileCheck %s
23
+ # RUN: llvm-readobj foo.dll | FileCheck %s
24
+
25
+ # RUN: llvm-readobj bar.exe | FileCheck %s
26
+ # RUN: llvm-readobj bar.dll | FileCheck %s
27
+
28
+ CHECK: File:
You can’t perform that action at this time.
0 commit comments