mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
ELF: restructure image metadata registration
Restructure the ELF handling to be completely agnostic to the OS. Rather than usng the loader to query the section information, use the linker to construct linker tables and synthetic markers for the beginning and of the table. Save off the values of these pointers and pass them along through the constructor to the runtime for registration. This removes the need for the begin/end objects. Remove the special construction of the begin/end objects through the special assembly constructs, preferring to do this in C with a bit of inline assembly to ensure that the section is always allocated. Remove the special handling for the various targets, the empty object file can be linked on all the targets. The new object file has no requirements on the ordering. It needs to simply be injected into the link. Name the replacement file `swiftrt.o` mirroring `crt.o` from libc. Merge the constructor and the definition into a single object file. This approach is generally more portable, overall simpler to implement, and more robust. Thanks to Orlando Bassotto for help analyzing some of the odd behaviours when switching over.
This commit is contained in:
@@ -716,19 +716,6 @@ function(_add_swift_library_single target name)
|
|||||||
set(SWIFTLIB_SINGLE_API_NOTES "${module_name}")
|
set(SWIFTLIB_SINGLE_API_NOTES "${module_name}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# On platforms that use ELF binaries we add markers for metadata sections in
|
|
||||||
# the shared libraries using these object files. This wouldn't be necessary
|
|
||||||
# if the link was done by the swift binary: rdar://problem/19007002
|
|
||||||
if(SWIFTLIB_SINGLE_TARGET_LIBRARY AND
|
|
||||||
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
|
|
||||||
if("${libkind}" STREQUAL "SHARED")
|
|
||||||
set(arch_subdir "${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}")
|
|
||||||
|
|
||||||
set(SWIFT_SECTIONS_OBJECT_BEGIN "${arch_subdir}/swift_begin.o")
|
|
||||||
set(SWIFT_SECTIONS_OBJECT_END "${arch_subdir}/swift_end.o")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "WINDOWS")
|
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "WINDOWS")
|
||||||
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
|
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
|
||||||
swift_windows_generate_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY_FLAGS)
|
swift_windows_generate_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY_FLAGS)
|
||||||
@@ -828,12 +815,15 @@ function(_add_swift_library_single target name)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library("${target}" ${libkind}
|
add_library("${target}" ${libkind}
|
||||||
${SWIFT_SECTIONS_OBJECT_BEGIN}
|
|
||||||
${SWIFTLIB_SINGLE_SOURCES}
|
${SWIFTLIB_SINGLE_SOURCES}
|
||||||
${SWIFTLIB_SINGLE_EXTERNAL_SOURCES}
|
${SWIFTLIB_SINGLE_EXTERNAL_SOURCES}
|
||||||
${INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS}
|
${INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS}
|
||||||
${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES}
|
${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES})
|
||||||
${SWIFT_SECTIONS_OBJECT_END})
|
if("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" AND SWIFTLIB_TARGET_LIBRARY)
|
||||||
|
if("${libkind}" STREQUAL "SHARED")
|
||||||
|
target_sources(${target} PRIVATE $<TARGET_OBJECTS:swiftImageRegistrationObject-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${SWIFTLIB_SINGLE_ARCHITECTURE}>)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
_set_target_prefix_and_suffix("${target}" "${libkind}" "${SWIFTLIB_SINGLE_SDK}")
|
_set_target_prefix_and_suffix("${target}" "${libkind}" "${SWIFTLIB_SINGLE_SDK}")
|
||||||
|
|
||||||
if(SWIFTLIB_SINGLE_TARGET_LIBRARY)
|
if(SWIFTLIB_SINGLE_TARGET_LIBRARY)
|
||||||
@@ -872,17 +862,6 @@ function(_add_swift_library_single target name)
|
|||||||
set_property(TARGET "${target}" PROPERTY NO_SONAME ON)
|
set_property(TARGET "${target}" PROPERTY NO_SONAME ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# The section metadata objects are generated sources, and we need to tell CMake
|
|
||||||
# not to expect to find them prior to their generation.
|
|
||||||
if(SWIFTLIB_SINGLE_TARGET_LIBRARY AND
|
|
||||||
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
|
|
||||||
if("${libkind}" STREQUAL "SHARED")
|
|
||||||
set_source_files_properties(${SWIFT_SECTIONS_OBJECT_BEGIN} PROPERTIES GENERATED 1)
|
|
||||||
set_source_files_properties(${SWIFT_SECTIONS_OBJECT_END} PROPERTIES GENERATED 1)
|
|
||||||
add_dependencies("${target}" section_magic)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
llvm_update_compile_flags(${target})
|
llvm_update_compile_flags(${target})
|
||||||
|
|
||||||
set_output_directory(${target}
|
set_output_directory(${target}
|
||||||
|
|||||||
@@ -1530,26 +1530,6 @@ bool toolchains::GenericUnix::shouldProvideRPathToLinker() const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string toolchains::GenericUnix::getPreInputObjectPath(
|
|
||||||
StringRef RuntimeLibraryPath) const {
|
|
||||||
// On Linux and FreeBSD and Haiku (really, ELF binaries) we need to add objects
|
|
||||||
// to provide markers and size for the metadata sections.
|
|
||||||
SmallString<128> PreInputObjectPath = RuntimeLibraryPath;
|
|
||||||
llvm::sys::path::append(PreInputObjectPath,
|
|
||||||
swift::getMajorArchitectureName(getTriple()));
|
|
||||||
llvm::sys::path::append(PreInputObjectPath, "swift_begin.o");
|
|
||||||
return PreInputObjectPath.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string toolchains::GenericUnix::getPostInputObjectPath(
|
|
||||||
StringRef RuntimeLibraryPath) const {
|
|
||||||
SmallString<128> PostInputObjectPath = RuntimeLibraryPath;
|
|
||||||
llvm::sys::path::append(PostInputObjectPath,
|
|
||||||
swift::getMajorArchitectureName(getTriple()));
|
|
||||||
llvm::sys::path::append(PostInputObjectPath, "swift_end.o");
|
|
||||||
return PostInputObjectPath.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
ToolChain::InvocationInfo
|
ToolChain::InvocationInfo
|
||||||
toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
|
toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
|
||||||
const JobContext &context) const {
|
const JobContext &context) const {
|
||||||
@@ -1627,22 +1607,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
|
|||||||
}
|
}
|
||||||
|
|
||||||
SmallString<128> SharedRuntimeLibPath;
|
SmallString<128> SharedRuntimeLibPath;
|
||||||
SmallString<128> StaticRuntimeLibPath;
|
|
||||||
// Path to swift_begin.o and swift_end.o.
|
|
||||||
SmallString<128> ObjectLibPath;
|
|
||||||
getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, *this);
|
getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, *this);
|
||||||
|
|
||||||
// -static-stdlib uses the static lib path for libswiftCore but
|
SmallString<128> StaticRuntimeLibPath;
|
||||||
// the shared lib path for swift_begin.o and swift_end.o.
|
|
||||||
if (staticExecutable || staticStdlib) {
|
|
||||||
getRuntimeStaticLibraryPath(StaticRuntimeLibPath, context.Args, *this);
|
getRuntimeStaticLibraryPath(StaticRuntimeLibPath, context.Args, *this);
|
||||||
}
|
|
||||||
|
|
||||||
if (staticExecutable) {
|
|
||||||
ObjectLibPath = StaticRuntimeLibPath;
|
|
||||||
} else {
|
|
||||||
ObjectLibPath = SharedRuntimeLibPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the runtime library link path, which is platform-specific and found
|
// Add the runtime library link path, which is platform-specific and found
|
||||||
// relative to the compiler.
|
// relative to the compiler.
|
||||||
@@ -1655,10 +1623,12 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
|
|||||||
Arguments.push_back(context.Args.MakeArgString(SharedRuntimeLibPath));
|
Arguments.push_back(context.Args.MakeArgString(SharedRuntimeLibPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto PreInputObjectPath = getPreInputObjectPath(ObjectLibPath);
|
SmallString<128> swiftrtPath = SharedRuntimeLibPath;
|
||||||
if (!PreInputObjectPath.empty()) {
|
llvm::sys::path::append(swiftrtPath,
|
||||||
Arguments.push_back(context.Args.MakeArgString(PreInputObjectPath));
|
swift::getMajorArchitectureName(getTriple()));
|
||||||
}
|
llvm::sys::path::append(swiftrtPath, "swiftrt.o");
|
||||||
|
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
|
||||||
|
|
||||||
addPrimaryInputsOfType(Arguments, context.Inputs, types::TY_Object);
|
addPrimaryInputsOfType(Arguments, context.Inputs, types::TY_Object);
|
||||||
addInputsOfType(Arguments, context.InputActions, types::TY_Object);
|
addInputsOfType(Arguments, context.InputActions, types::TY_Object);
|
||||||
|
|
||||||
@@ -1753,13 +1723,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
|
|||||||
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
|
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);
|
||||||
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
|
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
|
||||||
|
|
||||||
// Just before the output option, allow GenericUnix toolchains to add
|
|
||||||
// additional inputs.
|
|
||||||
auto PostInputObjectPath = getPostInputObjectPath(ObjectLibPath);
|
|
||||||
if (!PostInputObjectPath.empty()) {
|
|
||||||
Arguments.push_back(context.Args.MakeArgString(PostInputObjectPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
// This should be the last option, for convenience in checking output.
|
// This should be the last option, for convenience in checking output.
|
||||||
Arguments.push_back("-o");
|
Arguments.push_back("-o");
|
||||||
Arguments.push_back(context.Output.getPrimaryOutputFilename().c_str());
|
Arguments.push_back(context.Output.getPrimaryOutputFilename().c_str());
|
||||||
@@ -1792,14 +1755,3 @@ std::string toolchains::Cygwin::getTargetForLinker() const {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string toolchains::Cygwin::getPreInputObjectPath(
|
|
||||||
StringRef RuntimeLibraryPath) const {
|
|
||||||
// Cygwin does not add "begin" and "end" objects.
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string toolchains::Cygwin::getPostInputObjectPath(
|
|
||||||
StringRef RuntimeLibraryPath) const {
|
|
||||||
// Cygwin does not add "begin" and "end" objects.
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -66,30 +66,6 @@ protected:
|
|||||||
/// default is to return true (and so specify an -rpath).
|
/// default is to return true (and so specify an -rpath).
|
||||||
virtual bool shouldProvideRPathToLinker() const;
|
virtual bool shouldProvideRPathToLinker() const;
|
||||||
|
|
||||||
/// Provides a path to an object that should be linked first. On platforms
|
|
||||||
/// that use ELF binaries, an object that provides markers and sizes for
|
|
||||||
/// metadata sections must be linked first. Platforms that do not need this
|
|
||||||
/// object may return an empty string; no additional objects are linked in
|
|
||||||
/// this case.
|
|
||||||
///
|
|
||||||
/// \param RuntimeLibraryPath A path to the Swift resource directory, which
|
|
||||||
/// on ARM architectures will contain metadata "begin" and "end"
|
|
||||||
/// objects.
|
|
||||||
virtual std::string
|
|
||||||
getPreInputObjectPath(StringRef RuntimeLibraryPath) const;
|
|
||||||
|
|
||||||
/// Provides a path to an object that should be linked last. On platforms
|
|
||||||
/// that use ELF binaries, an object that provides markers and sizes for
|
|
||||||
/// metadata sections must be linked last. Platforms that do not need this
|
|
||||||
/// object may return an empty string; no additional objects are linked in
|
|
||||||
/// this case.
|
|
||||||
///
|
|
||||||
/// \param RuntimeLibraryPath A path to the Swift resource directory, which
|
|
||||||
/// on ARM architectures will contain metadata "begin" and "end"
|
|
||||||
/// objects.
|
|
||||||
virtual std::string
|
|
||||||
getPostInputObjectPath(StringRef RuntimeLibraryPath) const;
|
|
||||||
|
|
||||||
InvocationInfo constructInvocation(const LinkJobAction &job,
|
InvocationInfo constructInvocation(const LinkJobAction &job,
|
||||||
const JobContext &context) const override;
|
const JobContext &context) const override;
|
||||||
|
|
||||||
@@ -117,11 +93,6 @@ protected:
|
|||||||
|
|
||||||
std::string getTargetForLinker() const override;
|
std::string getTargetForLinker() const override;
|
||||||
|
|
||||||
std::string getPreInputObjectPath(
|
|
||||||
StringRef RuntimeLibraryPath) const override;
|
|
||||||
|
|
||||||
std::string getPostInputObjectPath(
|
|
||||||
StringRef RuntimeLibraryPath) const override;
|
|
||||||
public:
|
public:
|
||||||
Cygwin(const Driver &D, const llvm::Triple &Triple) : GenericUnix(D, Triple) {}
|
Cygwin(const Driver &D, const llvm::Triple &Triple) : GenericUnix(D, Triple) {}
|
||||||
~Cygwin() = default;
|
~Cygwin() = default;
|
||||||
|
|||||||
@@ -2329,7 +2329,7 @@ llvm::Constant *IRGenModule::emitProtocolConformances() {
|
|||||||
sectionName = "__TEXT, __swift2_proto, regular, no_dead_strip";
|
sectionName = "__TEXT, __swift2_proto, regular, no_dead_strip";
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::ELF:
|
case llvm::Triple::ELF:
|
||||||
sectionName = ".swift2_protocol_conformances";
|
sectionName = "swift2_protocol_conformances";
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::COFF:
|
case llvm::Triple::COFF:
|
||||||
sectionName = ".sw2prtc";
|
sectionName = ".sw2prtc";
|
||||||
@@ -2352,7 +2352,7 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords() {
|
|||||||
sectionName = "__TEXT, __swift2_types, regular, no_dead_strip";
|
sectionName = "__TEXT, __swift2_types, regular, no_dead_strip";
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::ELF:
|
case llvm::Triple::ELF:
|
||||||
sectionName = ".swift2_type_metadata";
|
sectionName = "swift2_type_metadata";
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::COFF:
|
case llvm::Triple::COFF:
|
||||||
sectionName = ".sw2tymd";
|
sectionName = ".sw2tymd";
|
||||||
|
|||||||
@@ -769,7 +769,7 @@ static std::string getReflectionSectionName(IRGenModule &IGM,
|
|||||||
OS << ".sw3" << FourCC;
|
OS << ".sw3" << FourCC;
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::ELF:
|
case llvm::Triple::ELF:
|
||||||
OS << ".swift3_" << LongName;
|
OS << "swift3_" << LongName;
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::MachO:
|
case llvm::Triple::MachO:
|
||||||
assert(LongName.size() <= 7 &&
|
assert(LongName.size() <= 7 &&
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ add_swift_library(swiftCore ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB IS_STD
|
|||||||
# and the generated directory as dependencies.
|
# and the generated directory as dependencies.
|
||||||
FILE_DEPENDS
|
FILE_DEPENDS
|
||||||
copy_shim_headers "${SWIFTLIB_DIR}/shims"
|
copy_shim_headers "${SWIFTLIB_DIR}/shims"
|
||||||
section_magic
|
|
||||||
${GROUP_INFO_JSON_FILE}
|
${GROUP_INFO_JSON_FILE}
|
||||||
SWIFT_COMPILE_FLAGS ${swift_stdlib_compile_flags}
|
SWIFT_COMPILE_FLAGS ${swift_stdlib_compile_flags}
|
||||||
LINK_FLAGS ${swift_core_link_flags}
|
LINK_FLAGS ${swift_core_link_flags}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ if(SWIFT_RUNTIME_ENABLE_LEAK_CHECKER)
|
|||||||
set(swift_runtime_leaks_sources Leaks.mm)
|
set(swift_runtime_leaks_sources Leaks.mm)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(section_magic_compile_flags ${swift_runtime_compile_flags})
|
|
||||||
|
|
||||||
list(APPEND swift_runtime_compile_flags
|
list(APPEND swift_runtime_compile_flags
|
||||||
"-D__SWIFT_CURRENT_DYLIB=swiftCore")
|
"-D__SWIFT_CURRENT_DYLIB=swiftCore")
|
||||||
|
|
||||||
@@ -36,7 +34,6 @@ set(swift_runtime_sources
|
|||||||
Array.cpp
|
Array.cpp
|
||||||
Casting.cpp
|
Casting.cpp
|
||||||
CygwinPort.cpp
|
CygwinPort.cpp
|
||||||
HaikuPort.cpp
|
|
||||||
Demangle.cpp
|
Demangle.cpp
|
||||||
Enum.cpp
|
Enum.cpp
|
||||||
ErrorObjectConstants.cpp
|
ErrorObjectConstants.cpp
|
||||||
@@ -69,14 +66,12 @@ set(swift_runtime_sources
|
|||||||
|
|
||||||
# Acknowledge that the following sources are known.
|
# Acknowledge that the following sources are known.
|
||||||
set(LLVM_OPTIONAL_SOURCES
|
set(LLVM_OPTIONAL_SOURCES
|
||||||
swift_sections.S
|
|
||||||
MutexPThread.cpp
|
MutexPThread.cpp
|
||||||
MutexWin32.cpp
|
MutexWin32.cpp
|
||||||
CygwinPort.cpp
|
CygwinPort.cpp
|
||||||
ImageInspectionInit.cpp
|
|
||||||
ImageInspectionELF.cpp
|
ImageInspectionELF.cpp
|
||||||
ImageInspectionStatic.cpp
|
|
||||||
StaticBinaryELF.cpp
|
StaticBinaryELF.cpp
|
||||||
|
SwiftRT-ELF.cpp
|
||||||
${swift_runtime_sources}
|
${swift_runtime_sources}
|
||||||
${swift_runtime_objc_sources}
|
${swift_runtime_objc_sources}
|
||||||
${swift_runtime_leaks_sources})
|
${swift_runtime_leaks_sources})
|
||||||
@@ -92,14 +87,6 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
|
|||||||
string(TOLOWER "${sdk}" lowercase_sdk)
|
string(TOLOWER "${sdk}" lowercase_sdk)
|
||||||
|
|
||||||
# These two libraries are only used with the static swiftcore
|
# These two libraries are only used with the static swiftcore
|
||||||
add_swift_library(swiftImageInspectionStatic STATIC
|
|
||||||
ImageInspectionStatic.cpp
|
|
||||||
StaticBinaryELF.cpp
|
|
||||||
C_COMPILE_FLAGS ${swift_runtime_library_compile_flags}
|
|
||||||
LINK_FLAGS ${swift_runtime_linker_flags})
|
|
||||||
set_target_properties(swiftImageInspectionStatic PROPERTIES
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${SWIFTSTATICLIB_DIR}/${lowercase_sdk}")
|
|
||||||
|
|
||||||
add_swift_library(swiftImageInspectionShared STATIC
|
add_swift_library(swiftImageInspectionShared STATIC
|
||||||
ImageInspectionELF.cpp
|
ImageInspectionELF.cpp
|
||||||
C_COMPILE_FLAGS ${swift_runtime_library_compile_flags}
|
C_COMPILE_FLAGS ${swift_runtime_library_compile_flags}
|
||||||
@@ -107,10 +94,6 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
|
|||||||
set_target_properties(swiftImageInspectionShared PROPERTIES
|
set_target_properties(swiftImageInspectionShared PROPERTIES
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${SWIFTSTATICLIB_DIR}/${lowercase_sdk}")
|
ARCHIVE_OUTPUT_DIRECTORY "${SWIFTSTATICLIB_DIR}/${lowercase_sdk}")
|
||||||
|
|
||||||
swift_install_in_component(stdlib
|
|
||||||
TARGETS swiftImageInspectionStatic swiftImageInspectionShared
|
|
||||||
DESTINATION "lib/swift_static/${lowercase_sdk}")
|
|
||||||
|
|
||||||
# Generate the static-executable-args.lnk file used for ELF systems (eg linux)
|
# Generate the static-executable-args.lnk file used for ELF systems (eg linux)
|
||||||
set(linkfile "${lowercase_sdk}/static-executable-args.lnk")
|
set(linkfile "${lowercase_sdk}/static-executable-args.lnk")
|
||||||
add_custom_command_target(swift_static_binary_${sdk}_args
|
add_custom_command_target(swift_static_binary_${sdk}_args
|
||||||
@@ -147,111 +130,48 @@ add_swift_library(swiftRuntime OBJECT_LIBRARY TARGET_LIBRARY
|
|||||||
set(ELFISH_SDKS)
|
set(ELFISH_SDKS)
|
||||||
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
|
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
|
||||||
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
|
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
|
||||||
list(APPEND ELFISH_SDKS "${sdk}")
|
list(APPEND ELFISH_SDKS ${sdk})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
add_swift_library(section_magic_loader OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
|
add_swift_library(swiftImageRegistrationObject
|
||||||
ImageInspectionInit.cpp
|
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
|
||||||
C_COMPILE_FLAGS ${section_magic_compile_flags}
|
SwiftRT-ELF.cpp
|
||||||
TARGET_SDKS "${ELFISH_SDKS}"
|
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
|
||||||
LINK_FLAGS ${swift_runtime_linker_flags}
|
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
|
||||||
INSTALL_IN_COMPONENT never_install)
|
TARGET_SDKS ${ELFISH_SDKS}
|
||||||
add_swift_library(section_magic_begin OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
|
INSTALL_IN_COMPONENT none)
|
||||||
swift_sections.S
|
|
||||||
C_COMPILE_FLAGS ${section_magic_compile_flags} "-DSWIFT_BEGIN"
|
|
||||||
TARGET_SDKS "${ELFISH_SDKS}"
|
|
||||||
LINK_FLAGS ${swift_runtime_linker_flags}
|
|
||||||
INSTALL_IN_COMPONENT never_install)
|
|
||||||
add_swift_library(section_magic_end OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
|
|
||||||
swift_sections.S
|
|
||||||
C_COMPILE_FLAGS ${section_magic_compile_flags} "-DSWIFT_END"
|
|
||||||
LINK_FLAGS ${swift_runtime_linker_flags}
|
|
||||||
TARGET_SDKS "${ELFISH_SDKS}"
|
|
||||||
INSTALL_IN_COMPONENT never_install)
|
|
||||||
|
|
||||||
set(object_target_list)
|
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
|
||||||
foreach(sdk ${ELFISH_SDKS})
|
|
||||||
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
|
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
|
||||||
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
|
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
|
||||||
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
|
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
|
||||||
|
|
||||||
set(section_magic_loader_obj "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/section_magic_loader-${arch_suffix}.dir/ImageInspectionInit.cpp${CMAKE_C_OUTPUT_EXTENSION}")
|
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
|
||||||
set(section_magic_begin_obj "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/section_magic_begin-${arch_suffix}.dir/swift_sections.S${CMAKE_C_OUTPUT_EXTENSION}")
|
# TODO(compnerd) switch to the generator expression when cmake is upgraded
|
||||||
set(section_magic_end_obj "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/section_magic_end-${arch_suffix}.dir/swift_sections.S${CMAKE_C_OUTPUT_EXTENSION}")
|
# to a version which supports it.
|
||||||
|
# set(swiftrtObject "$<TARGET_OBJECTS:swiftImageRegistrationObject-${arch_suffix}>")
|
||||||
|
set(swiftrtObject ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/swiftImageRegistrationObject-${arch_suffix}.dir/SwiftRT-ELF.cpp${CMAKE_C_OUTPUT_EXTENSION})
|
||||||
|
set(swiftrtPath "${SWIFTLIB_DIR}/${arch_subdir}/swiftrt${CMAKE_C_OUTPUT_EXTENSION}")
|
||||||
|
|
||||||
set(ld_EXECUTABLE ${CMAKE_LINKER})
|
add_custom_command_target(swiftImageRegistration-${arch_suffix}
|
||||||
if(SWIFT_SDK_${sdk}_ARCH_${arch}_LINKER)
|
|
||||||
set(ld_EXECUTABLE ${SWIFT_SDK_${sdk}_ARCH_${arch}_LINKER})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_custom_command_target(section_magic_${arch_suffix}_begin_object
|
|
||||||
COMMAND
|
COMMAND
|
||||||
# Merge ImageInspectionInit.o + swift_sections.S(BEGIN) => swift_begin.o
|
"${CMAKE_COMMAND}" -E copy "${swiftrtObject}" "${swiftrtPath}"
|
||||||
${ld_EXECUTABLE} -r -o "${SWIFTLIB_DIR}/${arch_subdir}/swift_begin.o"
|
|
||||||
"${section_magic_begin_obj}" "${section_magic_loader_obj}"
|
|
||||||
OUTPUT
|
OUTPUT
|
||||||
"${SWIFTLIB_DIR}/${arch_subdir}/swift_begin.o"
|
"${swiftrtPath}"
|
||||||
DEPENDS
|
DEPENDS
|
||||||
"${section_magic_begin_obj}"
|
"${swiftrtObject}")
|
||||||
"${section_magic_loader_obj}")
|
|
||||||
|
|
||||||
add_custom_command_target(section_magic_${arch_suffix}_end_object
|
|
||||||
COMMAND
|
|
||||||
"${CMAKE_COMMAND}" -E copy
|
|
||||||
"${section_magic_end_obj}"
|
|
||||||
"${SWIFTLIB_DIR}/${arch_subdir}/swift_end.o"
|
|
||||||
OUTPUT
|
|
||||||
"${SWIFTLIB_DIR}/${arch_subdir}/swift_end.o"
|
|
||||||
DEPENDS
|
|
||||||
"${section_magic_end_obj}")
|
|
||||||
|
|
||||||
list(APPEND object_target_list
|
|
||||||
"${section_magic_${arch_suffix}_begin_object}"
|
|
||||||
"${section_magic_${arch_suffix}_end_object}")
|
|
||||||
|
|
||||||
swift_install_in_component(stdlib
|
swift_install_in_component(stdlib
|
||||||
FILES
|
FILES
|
||||||
"${SWIFTLIB_DIR}/${arch_subdir}/swift_begin.o"
|
"${swiftrtPath}"
|
||||||
"${SWIFTLIB_DIR}/${arch_subdir}/swift_end.o"
|
|
||||||
DESTINATION
|
DESTINATION
|
||||||
"lib/swift/${arch_subdir}")
|
"lib/swift/${arch_subdir}")
|
||||||
|
add_dependencies(swift-stdlib-${arch_suffix} ${swiftImageRegistration-${arch_suffix}})
|
||||||
|
|
||||||
if(SWIFT_BUILD_STATIC_STDLIB)
|
add_custom_target(swiftImageRegistration-${arch_suffix}
|
||||||
# Static lib versions of swift_begin.o and swift_end.o
|
ALL DEPENDS
|
||||||
add_custom_command_target(static_section_magic_${arch_suffix}_begin_object
|
${swiftImageRegistration-${arch_suffix}})
|
||||||
COMMAND
|
|
||||||
"${CMAKE_COMMAND}" -E copy
|
|
||||||
"${section_magic_begin_obj}"
|
|
||||||
"${SWIFTSTATICLIB_DIR}/${arch_subdir}/swift_begin.o"
|
|
||||||
OUTPUT
|
|
||||||
"${SWIFTSTATICLIB_DIR}/${arch_subdir}/swift_begin.o"
|
|
||||||
DEPENDS
|
|
||||||
"${section_magic_begin_obj}")
|
|
||||||
|
|
||||||
add_custom_command_target(static_section_magic_${arch_suffix}_end_object
|
|
||||||
COMMAND
|
|
||||||
"${CMAKE_COMMAND}" -E copy
|
|
||||||
"${section_magic_end_obj}"
|
|
||||||
"${SWIFTSTATICLIB_DIR}/${arch_subdir}/swift_end.o"
|
|
||||||
OUTPUT
|
|
||||||
"${SWIFTSTATICLIB_DIR}/${arch_subdir}/swift_end.o"
|
|
||||||
DEPENDS
|
|
||||||
"${section_magic_end_obj}")
|
|
||||||
|
|
||||||
list(APPEND object_target_list
|
|
||||||
"${static_section_magic_${arch_suffix}_begin_object}"
|
|
||||||
"${static_section_magic_${arch_suffix}_end_object}")
|
|
||||||
|
|
||||||
swift_install_in_component(stdlib
|
|
||||||
FILES
|
|
||||||
"${SWIFTSTATICLIB_DIR}/${arch_subdir}/swift_begin.o"
|
|
||||||
"${SWIFTSTATICLIB_DIR}/${arch_subdir}/swift_end.o"
|
|
||||||
DESTINATION
|
|
||||||
"lib/swift_static/${arch_subdir}")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endforeach()
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
add_custom_target(section_magic ALL DEPENDS ${object_target_list})
|
|
||||||
|
|||||||
@@ -1,205 +0,0 @@
|
|||||||
//===--- HaikuPort.cpp - Haiku ELF image inspection --------------------===//
|
|
||||||
//
|
|
||||||
// This source file is part of the Swift.org open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
||||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
//
|
|
||||||
// See https://swift.org/LICENSE.txt for license information
|
|
||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
///
|
|
||||||
/// \file
|
|
||||||
///
|
|
||||||
/// This file includes the Haiku specific implementation of the Image Inspection
|
|
||||||
/// routines specified in ImageInspectionELF. Since Haiku does not use
|
|
||||||
/// dl_iterate_phdr(), a local implementation is used here instead.
|
|
||||||
///
|
|
||||||
///
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#if defined(__HAIKU__)
|
|
||||||
|
|
||||||
#include "ImageInspection.h"
|
|
||||||
#include "swift/Runtime/Debug.h"
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <elf.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <OS.h>
|
|
||||||
#include <image.h>
|
|
||||||
|
|
||||||
struct dl_phdr_info {
|
|
||||||
void *dlpi_addr;
|
|
||||||
const char *dlpi_name;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define RTLD_NOLOAD RTLD_LOCAL
|
|
||||||
|
|
||||||
using namespace swift;
|
|
||||||
|
|
||||||
/// The symbol name in the image that identifies the beginning of the
|
|
||||||
/// protocol conformances table.
|
|
||||||
static const char ProtocolConformancesSymbol[] =
|
|
||||||
".swift2_protocol_conformances_start";
|
|
||||||
/// The symbol name in the image that identifies the beginning of the
|
|
||||||
/// type metadata record table.
|
|
||||||
static const char TypeMetadataRecordsSymbol[] =
|
|
||||||
".swift2_type_metadata_start";
|
|
||||||
|
|
||||||
/// Context arguments passed down from dl_iterate_phdr to its callback.
|
|
||||||
struct InspectArgs {
|
|
||||||
/// Symbol name to look up.
|
|
||||||
const char *symbolName;
|
|
||||||
/// Callback function to invoke with the metadata block.
|
|
||||||
void (*addBlock)(const void *start, uintptr_t size);
|
|
||||||
/// Set to true when initialize*Lookup() is called.
|
|
||||||
bool didInitializeLookup;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Haiku implementation of dl_iterate_phdr
|
|
||||||
static int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data);
|
|
||||||
|
|
||||||
static int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data) {
|
|
||||||
pid_t team_id = getpid();
|
|
||||||
image_info i_info;
|
|
||||||
int32 image_cookie = 0;
|
|
||||||
int ret = 0;
|
|
||||||
while (get_next_image_info(team_id, &image_cookie, &i_info) == B_OK) {
|
|
||||||
if (i_info.type == B_LIBRARY_IMAGE) {
|
|
||||||
// Get the symbol for this particular image //
|
|
||||||
dl_phdr_info hdr;
|
|
||||||
hdr.dlpi_name = i_info.name;
|
|
||||||
hdr.dlpi_addr = i_info.text;
|
|
||||||
ret = callback(&hdr, sizeof(hdr), data);
|
|
||||||
if (ret != 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static InspectArgs ProtocolConformanceArgs = {
|
|
||||||
ProtocolConformancesSymbol,
|
|
||||||
addImageProtocolConformanceBlockCallback,
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
static InspectArgs TypeMetadataRecordArgs = {
|
|
||||||
TypeMetadataRecordsSymbol,
|
|
||||||
addImageTypeMetadataRecordBlockCallback,
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Extract the section information for a named section in an image. imageName
|
|
||||||
// can be nullptr to specify the main executable.
|
|
||||||
static SectionInfo getSectionInfo(const char *imageName,
|
|
||||||
const char *sectionName) {
|
|
||||||
SectionInfo sectionInfo = { 0, nullptr };
|
|
||||||
void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD);
|
|
||||||
if (!handle) {
|
|
||||||
fatalError(/* flags = */ 0, "dlopen() failed on `%s': %s", imageName,
|
|
||||||
dlerror());
|
|
||||||
}
|
|
||||||
void *symbol = dlsym(handle, sectionName);
|
|
||||||
if (symbol) {
|
|
||||||
// Extract the size of the section data from the head of the section.
|
|
||||||
const char *section = reinterpret_cast<const char *>(symbol);
|
|
||||||
memcpy(§ionInfo.size, section, sizeof(uint64_t));
|
|
||||||
sectionInfo.data = section + sizeof(uint64_t);
|
|
||||||
}
|
|
||||||
dlclose(handle);
|
|
||||||
return sectionInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int iteratePHDRCallback(struct dl_phdr_info *info,
|
|
||||||
size_t size, void *data) {
|
|
||||||
InspectArgs *inspectArgs = reinterpret_cast<InspectArgs *>(data);
|
|
||||||
const char *fname = info->dlpi_name;
|
|
||||||
|
|
||||||
// While dl_iterate_phdr() is in progress it holds a lock to prevent other
|
|
||||||
// images being loaded. The initialize flag is set here inside the callback so
|
|
||||||
// that addNewDSOImage() sees a consistent state. If it was set outside the
|
|
||||||
// dl_iterate_phdr() call then it could result in images being missed or
|
|
||||||
// added twice.
|
|
||||||
inspectArgs->didInitializeLookup = true;
|
|
||||||
|
|
||||||
if (fname == nullptr || fname[0] == '\0') {
|
|
||||||
// The filename may be null for both the dynamic loader and main executable.
|
|
||||||
// So ignore null image name here and explicitly add the main executable
|
|
||||||
// in initialize*Lookup() to avoid adding the data twice.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SectionInfo block = getSectionInfo(fname, inspectArgs->symbolName);
|
|
||||||
if (block.size > 0) {
|
|
||||||
inspectArgs->addBlock(block.data, block.size);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the section information in an image specified by an address in that
|
|
||||||
// image.
|
|
||||||
static void addBlockInImage(const InspectArgs *inspectArgs, const void *addr) {
|
|
||||||
const char *fname = nullptr;
|
|
||||||
if (addr) {
|
|
||||||
Dl_info info;
|
|
||||||
if (dladdr((void*)addr, &info) == 0 || info.dli_fname == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fname = info.dli_fname;
|
|
||||||
}
|
|
||||||
SectionInfo block = getSectionInfo(fname, inspectArgs->symbolName);
|
|
||||||
if (block.size > 0) {
|
|
||||||
inspectArgs->addBlock(block.data, block.size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void initializeSectionLookup(InspectArgs *inspectArgs) {
|
|
||||||
// Add section data in the main executable.
|
|
||||||
addBlockInImage(inspectArgs, nullptr);
|
|
||||||
// Search the loaded dls. This only searches the already
|
|
||||||
// loaded ones. Any images loaded after this are processed by
|
|
||||||
// addNewDSOImage() below.
|
|
||||||
dl_iterate_phdr(iteratePHDRCallback, reinterpret_cast<void *>(inspectArgs));
|
|
||||||
}
|
|
||||||
|
|
||||||
void swift::initializeProtocolConformanceLookup() {
|
|
||||||
initializeSectionLookup(&ProtocolConformanceArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
void swift::initializeTypeMetadataRecordLookup() {
|
|
||||||
initializeSectionLookup(&TypeMetadataRecordArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// As ELF images are loaded, ImageInspectionInit:sectionDataInit() will call
|
|
||||||
// addNewDSOImage() with an address in the image that can later be used via
|
|
||||||
// dladdr() to dlopen() the image after the appropriate initialize*Lookup()
|
|
||||||
// function has been called.
|
|
||||||
SWIFT_RUNTIME_EXPORT
|
|
||||||
void swift_addNewDSOImage(const void *addr) {
|
|
||||||
if (ProtocolConformanceArgs.didInitializeLookup) {
|
|
||||||
addBlockInImage(&ProtocolConformanceArgs, addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TypeMetadataRecordArgs.didInitializeLookup) {
|
|
||||||
addBlockInImage(&TypeMetadataRecordArgs, addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int swift::lookupSymbol(const void *address, SymbolInfo *info) {
|
|
||||||
Dl_info dlinfo;
|
|
||||||
if (dladdr((void*)address, &dlinfo) == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
info->fileName = dlinfo.dli_fname;
|
|
||||||
info->baseAddress = dlinfo.dli_fbase;
|
|
||||||
info->symbolName = dlinfo.dli_sname;
|
|
||||||
info->symbolAddress = dlinfo.dli_saddr;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // defined(__HAIKU__)
|
|
||||||
@@ -18,144 +18,58 @@
|
|||||||
///
|
///
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#if (defined(__ELF__) || defined(__ANDROID__)) && !defined(__HAIKU__)
|
#if defined(__ELF__)
|
||||||
|
|
||||||
#include "ImageInspection.h"
|
#include "ImageInspection.h"
|
||||||
#include "swift/Runtime/Debug.h"
|
#include "ImageInspectionELF.h"
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <elf.h>
|
|
||||||
#include <link.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#if defined(__ANDROID__) || defined(__FreeBSD__)
|
|
||||||
#include "llvm/ADT/StringRef.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace swift;
|
using namespace swift;
|
||||||
|
|
||||||
/// The symbol name in the image that identifies the beginning of the
|
namespace {
|
||||||
/// protocol conformances table.
|
static const swift::MetadataSections *registered = nullptr;
|
||||||
static const char ProtocolConformancesSymbol[] =
|
|
||||||
".swift2_protocol_conformances_start";
|
|
||||||
/// The symbol name in the image that identifies the beginning of the
|
|
||||||
/// type metadata record table.
|
|
||||||
static const char TypeMetadataRecordsSymbol[] =
|
|
||||||
".swift2_type_metadata_start";
|
|
||||||
|
|
||||||
/// Context arguments passed down from dl_iterate_phdr to its callback.
|
void record(const swift::MetadataSections *sections) {
|
||||||
struct InspectArgs {
|
if (registered == nullptr) {
|
||||||
/// Symbol name to look up.
|
registered = sections;
|
||||||
const char *symbolName;
|
sections->next = sections->prev = sections;
|
||||||
/// Callback function to invoke with the metadata block.
|
} else {
|
||||||
void (*addBlock)(const void *start, uintptr_t size);
|
registered->prev->next = sections;
|
||||||
/// Set to true when initialize*Lookup() is called.
|
sections->next = registered;
|
||||||
bool didInitializeLookup;
|
sections->prev = registered->prev;
|
||||||
};
|
registered->prev = sections;
|
||||||
|
|
||||||
static InspectArgs ProtocolConformanceArgs = {
|
|
||||||
ProtocolConformancesSymbol,
|
|
||||||
addImageProtocolConformanceBlockCallback,
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
static InspectArgs TypeMetadataRecordArgs = {
|
|
||||||
TypeMetadataRecordsSymbol,
|
|
||||||
addImageTypeMetadataRecordBlockCallback,
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Extract the section information for a named section in an image. imageName
|
|
||||||
// can be nullptr to specify the main executable.
|
|
||||||
static SectionInfo getSectionInfo(const char *imageName,
|
|
||||||
const char *sectionName) {
|
|
||||||
SectionInfo sectionInfo = { 0, nullptr };
|
|
||||||
void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD);
|
|
||||||
if (!handle) {
|
|
||||||
#if defined(__ANDROID__) || defined(__FreeBSD__)
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
const char *systemPath = "/system/lib";
|
|
||||||
#elif defined(__FreeBSD__)
|
|
||||||
const char *systemPath = "/libexec";
|
|
||||||
#endif
|
|
||||||
llvm::StringRef imagePath = llvm::StringRef(imageName);
|
|
||||||
if (imagePath.startswith(systemPath) ||
|
|
||||||
(imageName && !imagePath.endswith(".so"))) {
|
|
||||||
return sectionInfo;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
fatalError(/* flags = */ 0, "dlopen() failed on `%s': %s", imageName,
|
|
||||||
dlerror());
|
|
||||||
}
|
|
||||||
void *symbol = dlsym(handle, sectionName);
|
|
||||||
if (symbol) {
|
|
||||||
// Extract the size of the section data from the head of the section.
|
|
||||||
const char *section = reinterpret_cast<const char *>(symbol);
|
|
||||||
memcpy(§ionInfo.size, section, sizeof(uint64_t));
|
|
||||||
sectionInfo.data = section + sizeof(uint64_t);
|
|
||||||
}
|
|
||||||
dlclose(handle);
|
|
||||||
return sectionInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int iteratePHDRCallback(struct dl_phdr_info *info,
|
|
||||||
size_t size, void *data) {
|
|
||||||
InspectArgs *inspectArgs = reinterpret_cast<InspectArgs *>(data);
|
|
||||||
const char *fname = info->dlpi_name;
|
|
||||||
|
|
||||||
// While dl_iterate_phdr() is in progress it holds a lock to prevent other
|
|
||||||
// images being loaded. The initialize flag is set here inside the callback so
|
|
||||||
// that addNewDSOImage() sees a consistent state. If it was set outside the
|
|
||||||
// dl_iterate_phdr() call then it could result in images being missed or
|
|
||||||
// added twice.
|
|
||||||
inspectArgs->didInitializeLookup = true;
|
|
||||||
|
|
||||||
if (fname == nullptr || fname[0] == '\0') {
|
|
||||||
// The filename may be null for both the dynamic loader and main executable.
|
|
||||||
// So ignore null image name here and explicitly add the main executable
|
|
||||||
// in initialize*Lookup() to avoid adding the data twice.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SectionInfo block = getSectionInfo(fname, inspectArgs->symbolName);
|
|
||||||
if (block.size > 0) {
|
|
||||||
inspectArgs->addBlock(block.data, block.size);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the section information in an image specified by an address in that
|
|
||||||
// image.
|
|
||||||
static void addBlockInImage(const InspectArgs *inspectArgs, const void *addr) {
|
|
||||||
const char *fname = nullptr;
|
|
||||||
if (addr) {
|
|
||||||
Dl_info info;
|
|
||||||
if (dladdr(addr, &info) == 0 || info.dli_fname == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fname = info.dli_fname;
|
|
||||||
}
|
|
||||||
SectionInfo block = getSectionInfo(fname, inspectArgs->symbolName);
|
|
||||||
if (block.size > 0) {
|
|
||||||
inspectArgs->addBlock(block.data, block.size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initializeSectionLookup(InspectArgs *inspectArgs) {
|
|
||||||
// Add section data in the main executable.
|
|
||||||
addBlockInImage(inspectArgs, nullptr);
|
|
||||||
// Search the loaded dls. This only searches the already
|
|
||||||
// loaded ones. Any images loaded after this are processed by
|
|
||||||
// addNewDSOImage() below.
|
|
||||||
dl_iterate_phdr(iteratePHDRCallback, reinterpret_cast<void *>(inspectArgs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void swift::initializeProtocolConformanceLookup() {
|
void swift::initializeProtocolConformanceLookup() {
|
||||||
initializeSectionLookup(&ProtocolConformanceArgs);
|
const swift::MetadataSections *sections = registered;
|
||||||
|
while (true) {
|
||||||
|
const swift::MetadataSections::Range &conformances =
|
||||||
|
sections->swift2_protocol_conformances;
|
||||||
|
if (conformances.length)
|
||||||
|
addImageProtocolConformanceBlockCallback(reinterpret_cast<void *>(conformances.start),
|
||||||
|
conformances.length);
|
||||||
|
|
||||||
|
if (sections->next == registered)
|
||||||
|
break;
|
||||||
|
sections = sections->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void swift::initializeTypeMetadataRecordLookup() {
|
void swift::initializeTypeMetadataRecordLookup() {
|
||||||
initializeSectionLookup(&TypeMetadataRecordArgs);
|
const swift::MetadataSections *sections = registered;
|
||||||
|
while (true) {
|
||||||
|
const swift::MetadataSections::Range &type_metadata =
|
||||||
|
sections->swift2_type_metadata;
|
||||||
|
if (type_metadata.length)
|
||||||
|
addImageTypeMetadataRecordBlockCallback(reinterpret_cast<void *>(type_metadata.start),
|
||||||
|
type_metadata.length);
|
||||||
|
|
||||||
|
if (sections->next == registered)
|
||||||
|
break;
|
||||||
|
sections = sections->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// As ELF images are loaded, ImageInspectionInit:sectionDataInit() will call
|
// As ELF images are loaded, ImageInspectionInit:sectionDataInit() will call
|
||||||
@@ -164,13 +78,22 @@ void swift::initializeTypeMetadataRecordLookup() {
|
|||||||
// function has been called.
|
// function has been called.
|
||||||
SWIFT_RUNTIME_EXPORT
|
SWIFT_RUNTIME_EXPORT
|
||||||
void swift_addNewDSOImage(const void *addr) {
|
void swift_addNewDSOImage(const void *addr) {
|
||||||
if (ProtocolConformanceArgs.didInitializeLookup) {
|
const swift::MetadataSections *sections =
|
||||||
addBlockInImage(&ProtocolConformanceArgs, addr);
|
static_cast<const swift::MetadataSections *>(addr);
|
||||||
}
|
|
||||||
|
|
||||||
if (TypeMetadataRecordArgs.didInitializeLookup) {
|
record(sections);
|
||||||
addBlockInImage(&TypeMetadataRecordArgs, addr);
|
|
||||||
}
|
const auto &protocol_conformances = sections->swift2_protocol_conformances;
|
||||||
|
const void *conformances =
|
||||||
|
reinterpret_cast<void *>(protocol_conformances.start);
|
||||||
|
if (protocol_conformances.length)
|
||||||
|
addImageProtocolConformanceBlockCallback(conformances,
|
||||||
|
protocol_conformances.length);
|
||||||
|
|
||||||
|
const auto &type_metadata = sections->swift2_type_metadata;
|
||||||
|
const void *metadata = reinterpret_cast<void *>(type_metadata.start);
|
||||||
|
if (type_metadata.length)
|
||||||
|
addImageTypeMetadataRecordBlockCallback(metadata, type_metadata.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int swift::lookupSymbol(const void *address, SymbolInfo *info) {
|
int swift::lookupSymbol(const void *address, SymbolInfo *info) {
|
||||||
@@ -186,4 +109,4 @@ int swift::lookupSymbol(const void *address, SymbolInfo *info) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // defined(__ELF__) || defined(__ANDROID__)
|
#endif // defined(__ELF__)
|
||||||
|
|||||||
@@ -19,22 +19,45 @@
|
|||||||
#ifndef SWIFT_RUNTIME_IMAGEINSPECTIONELF_H
|
#ifndef SWIFT_RUNTIME_IMAGEINSPECTIONELF_H
|
||||||
#define SWIFT_RUNTIME_IMAGEINSPECTIONELF_H
|
#define SWIFT_RUNTIME_IMAGEINSPECTIONELF_H
|
||||||
|
|
||||||
#if defined(__ELF__) || defined(__ANDROID__)
|
#if defined(__ELF__)
|
||||||
|
|
||||||
#include "../SwiftShims/Visibility.h"
|
#include "../SwiftShims/Visibility.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace swift {
|
namespace swift {
|
||||||
struct SectionInfo {
|
struct SectionInfo {
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
const char *data;
|
const char *data;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
static constexpr const uintptr_t CurrentSectionMetadataVersion = 1;
|
||||||
|
|
||||||
|
struct MetadataSections {
|
||||||
|
uintptr_t version;
|
||||||
|
uintptr_t reserved;
|
||||||
|
|
||||||
|
mutable const MetadataSections *next;
|
||||||
|
mutable const MetadataSections *prev;
|
||||||
|
|
||||||
|
struct Range {
|
||||||
|
uintptr_t start;
|
||||||
|
size_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
Range swift2_protocol_conformances;
|
||||||
|
Range swift2_type_metadata;
|
||||||
|
Range swift3_typeref;
|
||||||
|
Range swift3_reflstr;
|
||||||
|
Range swift3_fieldmd;
|
||||||
|
Range swift3_assocty;
|
||||||
|
};
|
||||||
|
} // namespace swift
|
||||||
|
|
||||||
// Called by injected constructors when a dynamic library is loaded.
|
// Called by injected constructors when a dynamic library is loaded.
|
||||||
SWIFT_RUNTIME_EXPORT
|
SWIFT_RUNTIME_EXPORT
|
||||||
void swift_addNewDSOImage(const void *addr);
|
void swift_addNewDSOImage(const void *addr);
|
||||||
|
|
||||||
#endif // defined(__ELF__) || defined(__ANDROID__)
|
#endif // defined(__ELF__)
|
||||||
|
|
||||||
#endif // SWIFT_RUNTIME_IMAGE_INSPECTION_ELF_H
|
#endif // SWIFT_RUNTIME_IMAGE_INSPECTION_ELF_H
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
//===--- ImageInspectionInit.cpp ------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This source file is part of the Swift.org open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
||||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
//
|
|
||||||
// See https://swift.org/LICENSE.txt for license information
|
|
||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
///
|
|
||||||
/// \file
|
|
||||||
///
|
|
||||||
/// This file along with swift_sections.S is prepended to each shared library on
|
|
||||||
/// an ELF target which contains protocol and metadata sections.
|
|
||||||
///
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#if defined(__ELF__) || defined(__ANDROID__)
|
|
||||||
|
|
||||||
#include "ImageInspection.h"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
// This is called at startup and by each shared object as it is dlopen()'d to
|
|
||||||
// allow the section data for the object to be loaded.
|
|
||||||
__attribute__((constructor))
|
|
||||||
static void sectionDataInit() {
|
|
||||||
void *addr = reinterpret_cast<void *>(std::addressof(sectionDataInit));
|
|
||||||
swift_addNewDSOImage(addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
//===--- ImageInspectionStatic.cpp ----------------------------------------===//
|
|
||||||
//
|
|
||||||
// This source file is part of the Swift.org open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
||||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
//
|
|
||||||
// See https://swift.org/LICENSE.txt for license information
|
|
||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// Implementation of functions to read data sections from static executable.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
// Currently only tested on linux but should work for any ELF platform
|
|
||||||
#if defined(__ELF__) && defined(__linux__)
|
|
||||||
|
|
||||||
#include "ImageInspection.h"
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
// These are defined in swift_sections.S to mark the start of a section with the
|
|
||||||
// length of the data followed immediately by the section data
|
|
||||||
struct alignas(uint64_t) Section;
|
|
||||||
extern const Section protocolConformancesStart asm(".swift2_protocol_conformances_start");
|
|
||||||
extern const Section typeMetadataStart asm(".swift2_type_metadata_start");
|
|
||||||
|
|
||||||
using namespace swift;
|
|
||||||
|
|
||||||
static SectionInfo
|
|
||||||
getSectionInfo(const Section *section) {
|
|
||||||
SectionInfo info;
|
|
||||||
memcpy(&info.size, section, sizeof(uint64_t));
|
|
||||||
info.data = reinterpret_cast<const char *>(section) + sizeof(uint64_t);
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
swift::initializeProtocolConformanceLookup() {
|
|
||||||
auto protocolConformances = getSectionInfo(&protocolConformancesStart);
|
|
||||||
addImageProtocolConformanceBlockCallback(protocolConformances.data,
|
|
||||||
protocolConformances.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
swift::initializeTypeMetadataRecordLookup() {
|
|
||||||
auto typeMetadata = getSectionInfo(&typeMetadataStart);
|
|
||||||
addImageTypeMetadataRecordBlockCallback(typeMetadata.data,
|
|
||||||
typeMetadata.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // defined(__ELF__) && defined(__linux__)
|
|
||||||
@@ -273,8 +273,8 @@ _registerProtocolConformances(ConformanceState &C,
|
|||||||
|
|
||||||
void swift::addImageProtocolConformanceBlockCallback(const void *conformances,
|
void swift::addImageProtocolConformanceBlockCallback(const void *conformances,
|
||||||
uintptr_t conformancesSize) {
|
uintptr_t conformancesSize) {
|
||||||
assert(conformancesSize % sizeof(ProtocolConformanceRecord) == 0
|
assert(conformancesSize % sizeof(ProtocolConformanceRecord) == 0 &&
|
||||||
&& "weird-sized conformances section?!");
|
"conformances section not a multiple of ProtocolConformanceRecord");
|
||||||
|
|
||||||
// If we have a section, enqueue the conformances for lookup.
|
// If we have a section, enqueue the conformances for lookup.
|
||||||
auto conformanceBytes = reinterpret_cast<const char *>(conformances);
|
auto conformanceBytes = reinterpret_cast<const char *>(conformances);
|
||||||
|
|||||||
68
stdlib/public/runtime/SwiftRT-ELF.cpp
Normal file
68
stdlib/public/runtime/SwiftRT-ELF.cpp
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
//===--- SwiftRT-ELF.cpp --------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This source file is part of the Swift.org open source project
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||||
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
//
|
||||||
|
// See https://swift.org/LICENSE.txt for license information
|
||||||
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "ImageInspectionELF.h"
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
// Create empty sections to ensure that the start/stop symbols are synthesized
|
||||||
|
// by the linker. Otherwise, we may end up with undefined symbol references as
|
||||||
|
// the linker table section was never constructed.
|
||||||
|
|
||||||
|
#define DECLARE_SWIFT_SECTION(name) \
|
||||||
|
__asm__("\t.section " #name ",\"a\"\n"); \
|
||||||
|
__attribute__((__visibility__("hidden"))) extern const char __start_##name; \
|
||||||
|
__attribute__((__visibility__("hidden"))) extern const char __stop_##name;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
DECLARE_SWIFT_SECTION(swift2_protocol_conformances)
|
||||||
|
DECLARE_SWIFT_SECTION(swift2_type_metadata)
|
||||||
|
|
||||||
|
DECLARE_SWIFT_SECTION(swift3_typeref)
|
||||||
|
DECLARE_SWIFT_SECTION(swift3_reflstr)
|
||||||
|
DECLARE_SWIFT_SECTION(swift3_fieldmd)
|
||||||
|
DECLARE_SWIFT_SECTION(swift3_assocty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef DECLARE_SWIFT_SECTION
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
static swift::MetadataSections sections{};
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((__constructor__))
|
||||||
|
static void swift_image_constructor() {
|
||||||
|
#define SWIFT_SECTION_RANGE(name) \
|
||||||
|
{ reinterpret_cast<uintptr_t>(&__start_##name), \
|
||||||
|
static_cast<uintptr_t>(&__stop_##name - &__start_##name) }
|
||||||
|
|
||||||
|
sections = {
|
||||||
|
swift::CurrentSectionMetadataVersion,
|
||||||
|
0,
|
||||||
|
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
|
||||||
|
SWIFT_SECTION_RANGE(swift2_protocol_conformances),
|
||||||
|
SWIFT_SECTION_RANGE(swift2_type_metadata),
|
||||||
|
|
||||||
|
SWIFT_SECTION_RANGE(swift3_typeref),
|
||||||
|
SWIFT_SECTION_RANGE(swift3_reflstr),
|
||||||
|
SWIFT_SECTION_RANGE(swift3_fieldmd),
|
||||||
|
SWIFT_SECTION_RANGE(swift3_assocty),
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef SWIFT_SECTION_RANGE
|
||||||
|
|
||||||
|
swift_addNewDSOImage(§ions);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
//===--- swift_sections.S -------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This source file is part of the Swift.org open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
||||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
//
|
|
||||||
// See https://swift.org/LICENSE.txt for license information
|
|
||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
///
|
|
||||||
/// \swift_sections.S
|
|
||||||
/// This file contains section markers for the computation of the location and
|
|
||||||
/// size of the conformances and metadata information for non-Darwin targets.
|
|
||||||
///
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#if !defined(SWIFT_BEGIN) && !defined(SWIFT_END)
|
|
||||||
#error "Define SWIFT_BEGIN or SWIFT_END to compile this file."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
.macro define_sized_section name=1
|
|
||||||
|
|
||||||
#if defined(__arm__)
|
|
||||||
.section .\()\name, "aw", %progbits
|
|
||||||
#else
|
|
||||||
.section .\()\name, "aw", @progbits
|
|
||||||
#endif
|
|
||||||
|
|
||||||
.p2align 3
|
|
||||||
|
|
||||||
#if defined(SWIFT_BEGIN)
|
|
||||||
.globl .\()\name\()_start
|
|
||||||
.protected .\()\name\()_start
|
|
||||||
.\()\name\()_start:
|
|
||||||
#if defined(__BIG_ENDIAN__)
|
|
||||||
.long 0
|
|
||||||
.long .\()\name\()_end - .\()\name\()_start - 8
|
|
||||||
#else
|
|
||||||
.long .\()\name\()_end - .\()\name\()_start - 8
|
|
||||||
.long 0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SWIFT_END)
|
|
||||||
.globl .\()\name\()_end
|
|
||||||
.protected .\()\name\()_end
|
|
||||||
.\()\name\()_end:
|
|
||||||
#endif
|
|
||||||
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.macro define_simple_section name=1
|
|
||||||
|
|
||||||
#if defined(SWIFT_BEGIN)
|
|
||||||
#if defined(__arm__)
|
|
||||||
.section .\()\name, "aw", %progbits
|
|
||||||
#else
|
|
||||||
.section .\()\name, "aw", @progbits
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO .p2align 2 ?
|
|
||||||
|
|
||||||
.globl .\()\name\()_section
|
|
||||||
.protected .\()\name\()_section
|
|
||||||
.\()\name\()_section:
|
|
||||||
#endif
|
|
||||||
|
|
||||||
.endm
|
|
||||||
|
|
||||||
define_simple_section swift3_typeref
|
|
||||||
define_simple_section swift3_reflstr
|
|
||||||
define_simple_section swift3_fieldmd
|
|
||||||
define_simple_section swift3_assocty
|
|
||||||
|
|
||||||
define_sized_section swift2_protocol_conformances
|
|
||||||
define_sized_section swift2_type_metadata
|
|
||||||
#if defined(__arm__)
|
|
||||||
.section .note.GNU-stack,"",%progbits
|
|
||||||
#else
|
|
||||||
.section .note.GNU-stack,"",@progbits
|
|
||||||
#endif
|
|
||||||
@@ -281,6 +281,10 @@ foreach(SDK ${SWIFT_SDKS})
|
|||||||
list(APPEND dependencies ${validation_test_dependencies})
|
list(APPEND dependencies ${validation_test_dependencies})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if("${SWIFT_SDK_${SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
|
||||||
|
list(APPEND dependencies swiftImageRegistration${VARIANT_SUFFIX})
|
||||||
|
endif()
|
||||||
|
|
||||||
set(test_subset_target_suffix "-${test_subset}")
|
set(test_subset_target_suffix "-${test_subset}")
|
||||||
if(test_subset STREQUAL "primary")
|
if(test_subset STREQUAL "primary")
|
||||||
set(test_subset_target_suffix "")
|
set(test_subset_target_suffix "")
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ print("hello world!")
|
|||||||
// RUN: %target-swiftc_driver -driver-print-jobs -static-stdlib -o %t/static-stdlib %s -Xlinker --no-allow-multiple-definition 2>&1| %FileCheck %s
|
// RUN: %target-swiftc_driver -driver-print-jobs -static-stdlib -o %t/static-stdlib %s -Xlinker --no-allow-multiple-definition 2>&1| %FileCheck %s
|
||||||
// CHECK: {{.*}}/swift -frontend -c -primary-file {{.*}}/linker-args-order-linux.swift -target x86_64-unknown-linux-gnu -disable-objc-interop
|
// CHECK: {{.*}}/swift -frontend -c -primary-file {{.*}}/linker-args-order-linux.swift -target x86_64-unknown-linux-gnu -disable-objc-interop
|
||||||
// CHECK: {{.*}}/swift-autolink-extract{{.*}}
|
// CHECK: {{.*}}/swift-autolink-extract{{.*}}
|
||||||
// CHECK: {{.*}}swift_begin.o /{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.o @/{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.autolink {{.*}} @{{.*}}/static-stdlib-args.lnk {{.*}} -Xlinker --no-allow-multiple-definition {{.*}}/swift_end.o
|
// CHECK: {{.*}}swiftrt.o /{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.o @/{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.autolink {{.*}} @{{.*}}/static-stdlib-args.lnk {{.*}} -Xlinker --no-allow-multiple-definition
|
||||||
|
|||||||
@@ -260,13 +260,12 @@
|
|||||||
// LINUX_DYNLIB-x86_64-DAG: -fuse-ld=gold
|
// LINUX_DYNLIB-x86_64-DAG: -fuse-ld=gold
|
||||||
// LINUX_DYNLIB-x86_64-NOT: -pie
|
// LINUX_DYNLIB-x86_64-NOT: -pie
|
||||||
// LINUX_DYNLIB-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+/lib/swift/linux]]
|
// LINUX_DYNLIB-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH:[^ ]+/lib/swift/linux]]
|
||||||
// LINUX_DYNLIB-x86_64: [[STDLIB_PATH]]/x86_64/swift_begin.o
|
// LINUX_DYNLIB-x86_64: [[STDLIB_PATH]]/x86_64/swiftrt.o
|
||||||
// LINUX_DYNLIB-x86_64-DAG: [[OBJECTFILE]]
|
// LINUX_DYNLIB-x86_64-DAG: [[OBJECTFILE]]
|
||||||
// LINUX_DYNLIB-x86_64-DAG: @[[AUTOLINKFILE]]
|
// LINUX_DYNLIB-x86_64-DAG: @[[AUTOLINKFILE]]
|
||||||
// LINUX_DYNLIB-x86_64-DAG: [[STDLIB_PATH]]
|
// LINUX_DYNLIB-x86_64-DAG: [[STDLIB_PATH]]
|
||||||
// LINUX_DYNLIB-x86_64-DAG: -lswiftCore
|
// LINUX_DYNLIB-x86_64-DAG: -lswiftCore
|
||||||
// LINUX_DYNLIB-x86_64-DAG: -L bar
|
// LINUX_DYNLIB-x86_64-DAG: -L bar
|
||||||
// LINUX_DYNLIB-x86_64: [[STDLIB_PATH]]/x86_64/swift_end.o
|
|
||||||
// LINUX_DYNLIB-x86_64: -o dynlib.out
|
// LINUX_DYNLIB-x86_64: -o dynlib.out
|
||||||
|
|
||||||
// DEBUG: bin/swift
|
// DEBUG: bin/swift
|
||||||
|
|||||||
@@ -21,9 +21,8 @@
|
|||||||
// LINUX: -sdk {{.*}}/Inputs/clang-importer-sdk
|
// LINUX: -sdk {{.*}}/Inputs/clang-importer-sdk
|
||||||
// LINUX-NEXT: bin/swift
|
// LINUX-NEXT: bin/swift
|
||||||
// LINUX: -sdk {{.*}}/Inputs/clang-importer-sdk
|
// LINUX: -sdk {{.*}}/Inputs/clang-importer-sdk
|
||||||
// LINUX: bin/{{.+}} {{.*}}swift_begin.o
|
// LINUX: bin/{{.+}} {{.*}}swiftrt.o
|
||||||
// LINUX: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
|
// LINUX: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
|
||||||
// LINUX: {{.*}}swift_end.o
|
|
||||||
|
|
||||||
// FREEBSD-NOT: warning: no such SDK:
|
// FREEBSD-NOT: warning: no such SDK:
|
||||||
// FREEBSD: bin/swift
|
// FREEBSD: bin/swift
|
||||||
@@ -31,9 +30,8 @@
|
|||||||
// FREEBSD: -sdk {{.*}}/Inputs/clang-importer-sdk
|
// FREEBSD: -sdk {{.*}}/Inputs/clang-importer-sdk
|
||||||
// FREEBSD-NEXT: bin/swift
|
// FREEBSD-NEXT: bin/swift
|
||||||
// FREEBSD: -sdk {{.*}}/Inputs/clang-importer-sdk
|
// FREEBSD: -sdk {{.*}}/Inputs/clang-importer-sdk
|
||||||
// FREEBSD: bin/{{.+}} {{.*}}swift_begin.o
|
// FREEBSD: bin/{{.+}} {{.*}}swiftrt.o
|
||||||
// FREEBSD: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
|
// FREEBSD: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
|
||||||
// FREEBSD: {{.*}}swift_end.o
|
|
||||||
|
|
||||||
// RUN: %swift_driver -driver-print-jobs -repl -sdk %S/Inputs/nonexistent-sdk 2>&1 | %FileCheck %s --check-prefix=SDKWARNING
|
// RUN: %swift_driver -driver-print-jobs -repl -sdk %S/Inputs/nonexistent-sdk 2>&1 | %FileCheck %s --check-prefix=SDKWARNING
|
||||||
// RUN: %swift_driver -driver-print-jobs -sdk %S/Inputs/nonexistent-sdk 2>&1 | %FileCheck %s --check-prefix=SDKWARNING
|
// RUN: %swift_driver -driver-print-jobs -sdk %S/Inputs/nonexistent-sdk 2>&1 | %FileCheck %s --check-prefix=SDKWARNING
|
||||||
|
|||||||
@@ -111,17 +111,17 @@ static Section findReflectionSection(const ObjectFile *objectFile,
|
|||||||
|
|
||||||
static ReflectionInfo findReflectionInfo(const ObjectFile *objectFile) {
|
static ReflectionInfo findReflectionInfo(const ObjectFile *objectFile) {
|
||||||
auto fieldSection = findReflectionSection<FieldSection>(
|
auto fieldSection = findReflectionSection<FieldSection>(
|
||||||
objectFile, {"__swift3_fieldmd", ".swift3_fieldmd"});
|
objectFile, {"__swift3_fieldmd", ".swift3_fieldmd", "swift3_fieldmd"});
|
||||||
auto associatedTypeSection = findReflectionSection<AssociatedTypeSection>(
|
auto associatedTypeSection = findReflectionSection<AssociatedTypeSection>(
|
||||||
objectFile, {"__swift3_assocty", ".swift3_assocty"});
|
objectFile, {"__swift3_assocty", ".swift3_assocty", "swift3_assocty"});
|
||||||
auto builtinTypeSection = findReflectionSection<BuiltinTypeSection>(
|
auto builtinTypeSection = findReflectionSection<BuiltinTypeSection>(
|
||||||
objectFile, {"__swift3_builtin", ".swift3_builtin"});
|
objectFile, {"__swift3_builtin", ".swift3_builtin", "swift3_builtin"});
|
||||||
auto captureSection = findReflectionSection<CaptureSection>(
|
auto captureSection = findReflectionSection<CaptureSection>(
|
||||||
objectFile, {"__swift3_capture", ".swift3_capture"});
|
objectFile, {"__swift3_capture", ".swift3_capture", "swift3_capture"});
|
||||||
auto typeRefSection = findReflectionSection<GenericSection>(
|
auto typeRefSection = findReflectionSection<GenericSection>(
|
||||||
objectFile, {"__swift3_typeref", ".swift3_typeref"});
|
objectFile, {"__swift3_typeref", ".swift3_typeref", "swift3_typeref"});
|
||||||
auto reflectionStringsSection = findReflectionSection<GenericSection>(
|
auto reflectionStringsSection = findReflectionSection<GenericSection>(
|
||||||
objectFile, {"__swift3_reflstr", ".swift3_reflstr"});
|
objectFile, {"__swift3_reflstr", ".swift3_reflstr", "swift3_reflstr"});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fieldSection,
|
fieldSection,
|
||||||
|
|||||||
Reference in New Issue
Block a user