[PATCH] D31152: [COFF] Don't let /def override /out filename
Reid Kleckner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 20 17:25:10 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL298327: [COFF] Don't let /def override /out filename (authored by rnk).
Changed prior to commit:
https://reviews.llvm.org/D31152?vs=92385&id=92407#toc
Repository:
rL LLVM
https://reviews.llvm.org/D31152
Files:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/ModuleDef.cpp
lld/trunk/test/COFF/def-name.test
Index: lld/trunk/test/COFF/def-name.test
===================================================================
--- lld/trunk/test/COFF/def-name.test
+++ lld/trunk/test/COFF/def-name.test
@@ -0,0 +1,28 @@
+# REQUIRES: winres
+
+# RUN: rm -rf %t
+# RUN: mkdir -p %t
+# RUN: cd %t
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > in.obj
+
+# RUN: lld-link /entry:main in.obj
+# RUN: lld-link /entry:main /dll in.obj
+
+# RUN: echo -e "NAME foo\n" > fooexe.def
+# RUN: echo -e "LIBRARY foo\n" > foodll.def
+# RUN: lld-link /entry:main /def:fooexe.def in.obj
+# RUN: lld-link /entry:main /def:foodll.def /dll in.obj
+
+# RUN: lld-link /entry:main /out:bar.exe /def:fooexe.def in.obj
+# RUN: lld-link /entry:main /out:bar.dll /def:foodll.def /dll in.obj
+
+# RUN: llvm-readobj in.exe | FileCheck %s
+# RUN: llvm-readobj in.dll | FileCheck %s
+
+# RUN: llvm-readobj foo.exe | FileCheck %s
+# RUN: llvm-readobj foo.dll | FileCheck %s
+
+# RUN: llvm-readobj bar.exe | FileCheck %s
+# RUN: llvm-readobj bar.dll | FileCheck %s
+
+CHECK: File:
Index: lld/trunk/COFF/ModuleDef.cpp
===================================================================
--- lld/trunk/COFF/ModuleDef.cpp
+++ lld/trunk/COFF/ModuleDef.cpp
@@ -163,17 +163,25 @@
case KwHeapsize:
parseNumbers(&Config->HeapReserve, &Config->HeapCommit);
return;
- case KwLibrary:
- parseName(&Config->OutputFile, &Config->ImageBase);
- if (!StringRef(Config->OutputFile).endswith_lower(".dll"))
- Config->OutputFile += ".dll";
- return;
case KwStacksize:
parseNumbers(&Config->StackReserve, &Config->StackCommit);
return;
- case KwName:
- parseName(&Config->OutputFile, &Config->ImageBase);
+ case KwLibrary:
+ case KwName: {
+ bool IsDll = Tok.K == KwLibrary; // Check before parseName.
+ std::string Name;
+ parseName(&Name, &Config->ImageBase);
+
+ // Append the appropriate file extension if not already present.
+ StringRef Ext = IsDll ? ".dll" : ".exe";
+ if (!StringRef(Name).endswith_lower(Ext))
+ Name += Ext;
+
+ // Set the output file, but don't override /out if it was already passed.
+ if (Config->OutputFile.empty())
+ Config->OutputFile = Name;
return;
+ }
case KwVersion:
parseVersion(&Config->MajorImageVersion, &Config->MinorImageVersion);
return;
Index: lld/trunk/COFF/Driver.cpp
===================================================================
--- lld/trunk/COFF/Driver.cpp
+++ lld/trunk/COFF/Driver.cpp
@@ -137,9 +137,6 @@
fatal(MBOrErr.second, "could not open " + PathStr);
Driver->addBuffer(std::move(MBOrErr.first));
});
-
- if (Config->OutputFile == "")
- Config->OutputFile = getOutputPath(Path);
}
void LinkerDriver::addArchiveBuffer(MemoryBufferRef MB, StringRef SymName,
@@ -887,6 +884,12 @@
}
}
+ // Set default image name if neither /out or /def set it.
+ if (Config->OutputFile.empty()) {
+ Config->OutputFile =
+ getOutputPath((*Args.filtered_begin(OPT_INPUT))->getValue());
+ }
+
// Set default image base if /base is not given.
if (Config->ImageBase == uint64_t(-1))
Config->ImageBase = getDefaultImageBase();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31152.92407.patch
Type: text/x-patch
Size: 3200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170321/f4b37aa4/attachment.bin>
More information about the llvm-commits
mailing list