Skip to content

Remove metadata section functions from the stdlib #39236

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 1 commit into from
Sep 14, 2021
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
21 changes: 21 additions & 0 deletions stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ import Glibc

let rtldDefault: UnsafeMutableRawPointer? = nil

#if INTERNAL_CHECKS_ENABLED
@_silgen_name("swift_getMetadataSection")
internal func _getMetadataSection(_ index: UInt) -> UnsafeRawPointer?

@_silgen_name("swift_getMetadataSectionCount")
internal func _getMetadataSectionCount() -> UInt

@_silgen_name("swift_getMetadataSectionName")
internal func _getMetadataSectionName(
_ metadata_section: UnsafeRawPointer
) -> UnsafePointer<CChar>
#endif

extension Section {
init(range: MetadataSectionRange) {
self.startAddress = UnsafeRawPointer(bitPattern: range.start)!
Expand All @@ -139,6 +152,7 @@ extension Section {
}

internal func getReflectionInfoForImage(atIndex i: UInt32) -> ReflectionInfo? {
#if INTERNAL_CHECKS_ENABLED
return _getMetadataSection(UInt(i)).map { rawPointer in
let name = _getMetadataSectionName(rawPointer)
let metadataSection = rawPointer.bindMemory(to: MetadataSections.self, capacity: 1).pointee
Expand All @@ -150,10 +164,17 @@ internal func getReflectionInfoForImage(atIndex i: UInt32) -> ReflectionInfo? {
typeref: Section(range: metadataSection.swift5_typeref),
reflstr: Section(range: metadataSection.swift5_reflstr))
}
#else
return nil
#endif
}

internal func getImageCount() -> UInt32 {
#if INTERNAL_CHECKS_ENABLED
return UInt32(_getMetadataSectionCount())
#else
return 0
#endif
}

internal func sendImages() {
Expand Down
14 changes: 0 additions & 14 deletions stdlib/public/core/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,3 @@ public func _getTypeByMangledNameInContext(
genericContext: UnsafeRawPointer?,
genericArguments: UnsafeRawPointer?)
-> Any.Type?

@_silgen_name("swift_getMetadataSection")
public func _getMetadataSection(
_ index: UInt)
-> UnsafeRawPointer?

@_silgen_name("swift_getMetadataSectionCount")
public func _getMetadataSectionCount()
-> UInt

@_silgen_name("swift_getMetadataSectionName")
public func _getMetadataSectionName(
_ metadata_section: UnsafeRawPointer)
-> UnsafePointer<CChar>
15 changes: 5 additions & 10 deletions stdlib/public/runtime/ImageInspectionCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ void swift::initializeTypeMetadataRecordLookup() {
void swift::initializeDynamicReplacementLookup() {
}

#ifndef NDEBUG

SWIFT_RUNTIME_EXPORT
const swift::MetadataSections *swift_getMetadataSection(size_t index) {
#ifndef NDEBUG
if (swift::registered == nullptr) {
return nullptr;
}
Expand All @@ -147,27 +148,21 @@ const swift::MetadataSections *swift_getMetadataSection(size_t index) {
--index;
}
return selected;
#else // NDEBUG
return nullptr;
#endif // else NDEBUG
}

SWIFT_RUNTIME_EXPORT
const char *swift_getMetadataSectionName(void *metadata_section) {
#ifndef NDEBUG
swift::SymbolInfo info;
if (lookupSymbol(metadata_section, &info)) {
if (info.fileName) {
return info.fileName;
}
}
#endif // NDEBUG
return "";
}

SWIFT_RUNTIME_EXPORT
size_t swift_getMetadataSectionCount() {
#ifndef NDEBUG
if (swift::registered == nullptr)
return 0;

Expand All @@ -176,10 +171,10 @@ size_t swift_getMetadataSectionCount() {
current != swift::registered; current = current->next, ++count);

return count;
#else // NDEBUG
return 0;
#endif // else NDEBUG
}

#endif // NDEBUG

#endif // !defined(__MACH__)

#endif // SWIFT_RUNTIME_IMAGEINSPECTIONCOMMON_H
5 changes: 0 additions & 5 deletions test/api-digester/stability-stdlib-abi-without-asserts.test
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
Func _prespecialize() is a new API without @available attribute
Func _stdlib_isOSVersionAtLeastOrVariantVersionAtLeast(_:_:_:_:_:_:) is a new API without @available attribute

// These reflection APIs are exposed to facilitate building SwiftReflectionTest.swift when testing Release builds.
Func _getMetadataSection(_:) is a new API without @available attribute
Func _getMetadataSectionCount() is a new API without @available attribute
Func _getMetadataSectionName(_:) is a new API without @available attribute

Func Collection.removingSubranges(_:) has been removed
Func Collection.subranges(of:) has been removed
Func Collection.subranges(where:) has been removed
Expand Down