diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index fd195e355cec6..89d3b1ac5f042 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -2107,11 +2107,21 @@ void Driver::buildActions(SmallVectorImpl &TopLevelActions, // On ELF platforms there's no built in autolinking mechanism, so we // pull the info we need from the .o files directly and pass them as an // argument input file to the linker. + const auto &Triple = TC.getTriple(); SmallVector AutolinkExtractInputs; for (const Action *A : AllLinkerInputs) - if (A->getType() == file_types::TY_Object) + if (A->getType() == file_types::TY_Object) { + // Shared objects on ELF platforms don't have a swift1_autolink_entries + // section in them because the section in the .o files is marked as + // SHF_EXCLUDE. + if (auto *IA = dyn_cast(A)) { + StringRef ObjectName = IA->getInputArg().getValue(); + if (Triple.getObjectFormat() == llvm::Triple::ELF && + ObjectName.endswith(".so")) + continue; + } AutolinkExtractInputs.push_back(A); - const auto &Triple = TC.getTriple(); + } const bool AutolinkExtractRequired = (Triple.getObjectFormat() == llvm::Triple::ELF && !Triple.isPS4()) || Triple.getObjectFormat() == llvm::Triple::Wasm || diff --git a/test/Driver/Inputs/libEmpty.so b/test/Driver/Inputs/libEmpty.so new file mode 100644 index 0000000000000..6e57625b984eb --- /dev/null +++ b/test/Driver/Inputs/libEmpty.so @@ -0,0 +1 @@ +/* Just an empty file that looks like an ELF shared object */ diff --git a/test/Driver/autolink-no-shared-objects-elf.swift b/test/Driver/autolink-no-shared-objects-elf.swift new file mode 100644 index 0000000000000..a703cc8f10a79 --- /dev/null +++ b/test/Driver/autolink-no-shared-objects-elf.swift @@ -0,0 +1,5 @@ +// RUN: %target-swiftc_driver -### %s %S/Inputs/libEmpty.so | %FileCheck %s + +// REQUIRES: autolink-extract + +// CHECK-NOT: swift-autolink-extract {{.+}}.o {{.+}}Inputs/libEmpty.so -o {{.+}}.autolink