Skip to content

[Driver] Infer target-specific dylib names #12443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,7 @@ static StringRef getOutputFilename(Compilation &C,
const JobAction *JA,
const OutputInfo &OI,
const TypeToPathMap *OutputMap,
const llvm::Triple &Triple,
const llvm::opt::DerivedArgList &Args,
bool AtTopLevel,
StringRef BaseInput,
Expand Down Expand Up @@ -1814,10 +1815,17 @@ static StringRef getOutputFilename(Compilation &C,
BaseName = llvm::sys::path::stem(BaseInput);
if (auto link = dyn_cast<LinkJobAction>(JA)) {
if (link->getKind() == LinkKind::DynamicLibrary) {
// FIXME: This should be target-specific.
Buffer = "lib";
if (Triple.isOSWindows())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive by food for thought: Why not hoist this into LLVM? How does clang do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, absolutely, I felt the same! I didn't look where the best place for this to live would be, though. I'll check what Clang does and comment back here.

Buffer = "";
else
Buffer = "lib";
Buffer.append(BaseName);
Buffer.append(LTDL_SHLIB_EXT);
if (Triple.isOSDarwin())
Buffer.append(".dylib");
else if (Triple.isOSWindows())
Buffer.append(".dll");
else
Buffer.append(".so");
return Buffer.str();
}
}
Expand Down Expand Up @@ -2030,9 +2038,9 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
const TypeToPathMap *OMForInput = nullptr;
if (OFM)
OMForInput = OFM->getOutputMapForInput(Input);
OutputFile = getOutputFilename(C, JA, OI, OMForInput, C.getArgs(),
AtTopLevel, Input, InputJobs,

OutputFile = getOutputFilename(C, JA, OI, OMForInput, TC.getTriple(),
C.getArgs(), AtTopLevel, Input, InputJobs,
Diags, Buf);
Output->addPrimaryOutput(OutputFile, Input);
};
Expand All @@ -2048,9 +2056,9 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
}
} else {
// The common case: there is a single output file.
OutputFile = getOutputFilename(C, JA, OI, OutputMap, C.getArgs(),
AtTopLevel, BaseInput, InputJobs,
Diags, Buf);
OutputFile = getOutputFilename(C, JA, OI, OutputMap, TC.getTriple(),
C.getArgs(), AtTopLevel, BaseInput,
InputJobs, Diags, Buf);
Output->addPrimaryOutput(OutputFile, BaseInput);
}

Expand Down
20 changes: 14 additions & 6 deletions test/Driver/linker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@
// 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
// 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

// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -module-name LINKER | %FileCheck -check-prefix INFERRED_NAME %s
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -o libLINKER.dylib | %FileCheck -check-prefix INFERRED_NAME %s
// 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
// 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
// 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

// Here we specify an output file name using '-o'. For ease of writing these
// tests, we happen to specify the same file name as is inferred in the
// INFERRED_NAMED_DARWIN tests above: 'libLINKER.dylib'.
// 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

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

Expand Down Expand Up @@ -285,10 +291,12 @@
// FILELIST: -o linker


// INFERRED_NAME: bin/swift
// INFERRED_NAME: -module-name LINKER
// INFERRED_NAME: bin/ld{{"? }}
// INFERRED_NAME: -o libLINKER.{{dylib|so}}
// INFERRED_NAME_DARWIN: bin/swift
// INFERRED_NAME_DARWIN: -module-name LINKER
// INFERRED_NAME_DARWIN: bin/ld{{"? }}
// INFERRED_NAME_DARWIN: -o libLINKER.dylib
// INFERRED_NAME_LINUX: -o libLINKER.so
// INFERRED_NAME_WINDOWS: -o LINKER.dll


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