Skip to content

Commit 11033c6

Browse files
grynspanxedin
authored andcommitted
Fill out dynamic loading of the runtime attributes section
1 parent a5af302 commit 11033c6

File tree

7 files changed

+79
-2
lines changed

7 files changed

+79
-2
lines changed

stdlib/public/runtime/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ set(swift_runtime_sources
6969
SwiftDtoa.cpp
7070
SwiftTLSContext.cpp
7171
ThreadingError.cpp
72-
AccessibleFunction.cpp)
72+
AccessibleFunction.cpp
73+
RuntimeAttribute.cpp)
7374

7475
# Acknowledge that the following sources are known.
7576
set(LLVM_OPTIONAL_SOURCES

stdlib/public/runtime/ImageInspection.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ void initializeDynamicReplacementLookup();
5555
/// Load the metadata from the image necessary to find functions by name.
5656
void initializeAccessibleFunctionsLookup();
5757

58+
/// Load the metadata from the image necessary to find runtime metadata.
59+
void initializeRuntimeAttributesLookup();
60+
5861
// Callbacks to register metadata from an image to the runtime.
5962
void addImageProtocolsBlockCallback(const void *baseAddress,
6063
const void *start, uintptr_t size);
@@ -82,6 +85,12 @@ void addImageAccessibleFunctionsBlockCallback(const void *baseAddress,
8285
void addImageAccessibleFunctionsBlockCallbackUnsafe(const void *baseAddress,
8386
const void *start,
8487
uintptr_t size);
88+
void addImageRuntimeAttributesBlockCallback(const void *baseAddress,
89+
const void *start,
90+
uintptr_t size);
91+
void addImageRuntimeAttributesBlockCallbackUnsafe(const void *baseAddress,
92+
const void *start,
93+
uintptr_t size);
8594

8695
#if defined(_WIN32)
8796
/// Configure the environment to allow calling into the Debug Help library.

stdlib/public/runtime/ImageInspectionCommon.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ void swift_addNewDSOImage(swift::MetadataSections *sections) {
129129
swift::addImageAccessibleFunctionsBlockCallback(
130130
baseAddress, functions, accessible_funcs_section.length);
131131

132+
const auto &runtime_attribs_section = sections->swift5_runtime_attributes;
133+
const void *functions =
134+
reinterpret_cast<void *>(runtime_attribs_section.start);
135+
if (runtime_attribs_section.length)
136+
swift::addImageRuntimeAttributesBlockCallback(
137+
baseAddress, functions, runtime_attribs_section.length);
138+
132139
// Register this section for future enumeration by clients. This should occur
133140
// after this function has done all other relevant work to avoid a race
134141
// condition when someone calls swift_enumerateAllMetadataSections() on
@@ -168,6 +175,9 @@ void swift::initializeDynamicReplacementLookup() {
168175
void swift::initializeAccessibleFunctionsLookup() {
169176
}
170177

178+
void swift::initializeRuntimeAttributesLookup() {
179+
}
180+
171181
#ifndef NDEBUG
172182

173183
SWIFT_RUNTIME_EXPORT

stdlib/public/runtime/ImageInspectionCommon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
namespace swift {
5353
struct MetadataSections;
54-
static constexpr const uintptr_t CurrentSectionMetadataVersion = 2;
54+
static constexpr const uintptr_t CurrentSectionMetadataVersion = 3;
5555
}
5656

5757
struct SectionInfo {

stdlib/public/runtime/ImageInspectionMachO.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ constexpr const char DynamicReplacementSomeSection[] =
4545
MachODynamicReplacementSomeSection;
4646
constexpr const char AccessibleFunctionsSection[] =
4747
MachOAccessibleFunctionsSection;
48+
constexpr const char RuntimeAttributesSection[] =
49+
MachORuntimeAttributesSection;
4850
constexpr const char TextSegment[] = MachOTextSegment;
4951

5052
#if __POINTER_WIDTH__ == 64
@@ -171,5 +173,11 @@ void swift::initializeAccessibleFunctionsLookup() {
171173
addImageAccessibleFunctionsBlockCallbackUnsafe>);
172174
}
173175

176+
void swift::initializeRuntimeAttributesLookup() {
177+
REGISTER_FUNC(
178+
addImageCallback<TextSegment, RuntimeAttributesSection,
179+
addImageRuntimeAttributesBlockCallbackUnsafe>);
180+
}
181+
174182
#endif // defined(__APPLE__) && defined(__MACH__) &&
175183
// !defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)

stdlib/public/runtime/ImageInspectionStatic.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,14 @@ void swift::initializeAccessibleFunctionsLookup() {
8686
return;
8787
addImageAccessibleFunctionsBlockCallbackUnsafe(__dso_handle, start, size);
8888
}
89+
void swift::initializeRuntimeAttributesLookup() {
90+
void *start;
91+
uintptr_t size;
92+
GET_SECTION_START_AND_SIZE(start, size, MachOTextSegment,
93+
MachORuntimeAttributesSection);
94+
if (start == nullptr || size == 0)
95+
return;
96+
addImageRuntimeAttributesBlockCallbackUnsafe(__dso_handle, start, size);
97+
}
8998

9099
#endif // defined(__MACH__) && defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===---- AccessibleFunction.cpp - Swift protocol conformance checking ----===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Checking and caching of Swift runtime attributes.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#include "ImageInspection.h"
18+
#include "swift/Basic/Lazy.h"
19+
20+
using namespace swift;
21+
22+
// TODO: implement me!
23+
static Lazy<int> Functions;
24+
25+
void
26+
swift::addImageRuntimeAttributesBlockCallbackUnsafe(const void *baseAddress,
27+
const void *attribs,
28+
uintptr_t size) {
29+
auto &C = Functions.unsafeGetAlreadyInitialized();
30+
// TODO: implement me!
31+
// _registerRuntimeAttributes(C, RuntimeAttributesSection{attribs, size});
32+
}
33+
34+
void
35+
swift::addImageRuntimeAttributesBlockCallback(const void *baseAddress,
36+
const void *attribs,
37+
uintptr_t size) {
38+
Functions.get();
39+
addImageRuntimeAttributesBlockCallbackUnsafe(baseAddress, attribs, size);
40+
}

0 commit comments

Comments
 (0)