Skip to content

Commit b382fa1

Browse files
authored
Merge pull request #12443 from modocache/driver-inferred-dylib-name-fixme
2 parents b6a7449 + e2aa7a6 commit b382fa1

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

lib/Driver/Driver.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,7 @@ static StringRef getOutputFilename(Compilation &C,
17391739
const JobAction *JA,
17401740
const OutputInfo &OI,
17411741
const TypeToPathMap *OutputMap,
1742+
const llvm::Triple &Triple,
17421743
const llvm::opt::DerivedArgList &Args,
17431744
bool AtTopLevel,
17441745
StringRef BaseInput,
@@ -1827,10 +1828,17 @@ static StringRef getOutputFilename(Compilation &C,
18271828
BaseName = llvm::sys::path::stem(BaseInput);
18281829
if (auto link = dyn_cast<LinkJobAction>(JA)) {
18291830
if (link->getKind() == LinkKind::DynamicLibrary) {
1830-
// FIXME: This should be target-specific.
1831-
Buffer = "lib";
1831+
if (Triple.isOSWindows())
1832+
Buffer = "";
1833+
else
1834+
Buffer = "lib";
18321835
Buffer.append(BaseName);
1833-
Buffer.append(LTDL_SHLIB_EXT);
1836+
if (Triple.isOSDarwin())
1837+
Buffer.append(".dylib");
1838+
else if (Triple.isOSWindows())
1839+
Buffer.append(".dll");
1840+
else
1841+
Buffer.append(".so");
18341842
return Buffer.str();
18351843
}
18361844
}
@@ -2043,9 +2051,9 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
20432051
const TypeToPathMap *OMForInput = nullptr;
20442052
if (OFM)
20452053
OMForInput = OFM->getOutputMapForInput(Input);
2046-
2047-
OutputFile = getOutputFilename(C, JA, OI, OMForInput, C.getArgs(),
2048-
AtTopLevel, Input, InputJobs,
2054+
2055+
OutputFile = getOutputFilename(C, JA, OI, OMForInput, TC.getTriple(),
2056+
C.getArgs(), AtTopLevel, Input, InputJobs,
20492057
Diags, Buf);
20502058
Output->addPrimaryOutput(OutputFile, Input);
20512059
};
@@ -2061,9 +2069,9 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
20612069
}
20622070
} else {
20632071
// The common case: there is a single output file.
2064-
OutputFile = getOutputFilename(C, JA, OI, OutputMap, C.getArgs(),
2065-
AtTopLevel, BaseInput, InputJobs,
2066-
Diags, Buf);
2072+
OutputFile = getOutputFilename(C, JA, OI, OutputMap, TC.getTriple(),
2073+
C.getArgs(), AtTopLevel, BaseInput,
2074+
InputJobs, Diags, Buf);
20672075
Output->addPrimaryOutput(OutputFile, BaseInput);
20682076
}
20692077

test/Driver/linker.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@
5858
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 %s %t/a.o -o linker 2>&1 | %FileCheck -check-prefix COMPILE_AND_LINK %s
5959
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 %s %t/a.o -driver-use-filelists -o linker 2>&1 | %FileCheck -check-prefix FILELIST %s
6060

61-
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -module-name LINKER | %FileCheck -check-prefix INFERRED_NAME %s
62-
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -o libLINKER.dylib | %FileCheck -check-prefix INFERRED_NAME %s
61+
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -module-name LINKER | %FileCheck -check-prefix INFERRED_NAME_DARWIN %s
62+
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-unknown-linux-gnu -emit-library %s -module-name LINKER | %FileCheck -check-prefix INFERRED_NAME_LINUX %s
63+
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-unknown-windows-cygnus -emit-library %s -module-name LINKER | %FileCheck -check-prefix INFERRED_NAME_WINDOWS %s
64+
65+
// Here we specify an output file name using '-o'. For ease of writing these
66+
// tests, we happen to specify the same file name as is inferred in the
67+
// INFERRED_NAMED_DARWIN tests above: 'libLINKER.dylib'.
68+
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -o libLINKER.dylib | %FileCheck -check-prefix INFERRED_NAME_DARWIN %s
6369

6470
// There are more RUN lines further down in the file.
6571

@@ -297,10 +303,12 @@
297303
// FILELIST: -o linker
298304

299305

300-
// INFERRED_NAME: bin/swift
301-
// INFERRED_NAME: -module-name LINKER
302-
// INFERRED_NAME: bin/ld{{"? }}
303-
// INFERRED_NAME: -o libLINKER.{{dylib|so}}
306+
// INFERRED_NAME_DARWIN: bin/swift
307+
// INFERRED_NAME_DARWIN: -module-name LINKER
308+
// INFERRED_NAME_DARWIN: bin/ld{{"? }}
309+
// INFERRED_NAME_DARWIN: -o libLINKER.dylib
310+
// INFERRED_NAME_LINUX: -o libLINKER.so
311+
// INFERRED_NAME_WINDOWS: -o LINKER.dll
304312

305313

306314
// Test ld detection. We use hard links to make sure

0 commit comments

Comments
 (0)