Skip to content

Commit 963c7fc

Browse files
authored
Merge pull request swiftlang#30465 from xiaobai/dont-autolink-shared-objects
[Driver] Don't pass ELF shared objects to swift-autolink-extract
2 parents 4c7bc26 + 8953af5 commit 963c7fc

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/Driver/Driver.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,11 +2107,21 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
21072107
// On ELF platforms there's no built in autolinking mechanism, so we
21082108
// pull the info we need from the .o files directly and pass them as an
21092109
// argument input file to the linker.
2110+
const auto &Triple = TC.getTriple();
21102111
SmallVector<const Action *, 2> AutolinkExtractInputs;
21112112
for (const Action *A : AllLinkerInputs)
2112-
if (A->getType() == file_types::TY_Object)
2113+
if (A->getType() == file_types::TY_Object) {
2114+
// Shared objects on ELF platforms don't have a swift1_autolink_entries
2115+
// section in them because the section in the .o files is marked as
2116+
// SHF_EXCLUDE.
2117+
if (auto *IA = dyn_cast<InputAction>(A)) {
2118+
StringRef ObjectName = IA->getInputArg().getValue();
2119+
if (Triple.getObjectFormat() == llvm::Triple::ELF &&
2120+
ObjectName.endswith(".so"))
2121+
continue;
2122+
}
21132123
AutolinkExtractInputs.push_back(A);
2114-
const auto &Triple = TC.getTriple();
2124+
}
21152125
const bool AutolinkExtractRequired =
21162126
(Triple.getObjectFormat() == llvm::Triple::ELF && !Triple.isPS4()) ||
21172127
Triple.getObjectFormat() == llvm::Triple::Wasm ||

test/Driver/Inputs/libEmpty.so

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Just an empty file that looks like an ELF shared object */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swiftc_driver -### %s %S/Inputs/libEmpty.so | %FileCheck %s
2+
3+
// REQUIRES: autolink-extract
4+
5+
// CHECK-NOT: swift-autolink-extract {{.+}}.o {{.+}}Inputs/libEmpty.so -o {{.+}}.autolink

0 commit comments

Comments
 (0)