20
20
21
21
#if defined(__ELF__)
22
22
23
+ #include " ../SwiftShims/MetadataSections.h"
23
24
#include " ImageInspection.h"
24
25
#include " ImageInspectionELF.h"
25
26
#include < dlfcn.h>
26
27
27
28
using namespace swift ;
28
29
29
30
namespace {
30
- static const swift::MetadataSections *registered = nullptr ;
31
+ static swift::MetadataSections *registered = nullptr ;
31
32
32
- void record (const swift::MetadataSections *sections) {
33
+ void record (swift::MetadataSections *sections) {
33
34
if (registered == nullptr ) {
34
35
registered = sections;
35
36
sections->next = sections->prev = sections;
@@ -45,7 +46,7 @@ void record(const swift::MetadataSections *sections) {
45
46
void swift::initializeProtocolLookup () {
46
47
const swift::MetadataSections *sections = registered;
47
48
while (true ) {
48
- const swift::MetadataSections::Range &protocols =
49
+ const swift::MetadataSectionRange &protocols =
49
50
sections->swift5_protocols ;
50
51
if (protocols.length )
51
52
addImageProtocolsBlockCallbackUnsafe (
@@ -59,7 +60,7 @@ void swift::initializeProtocolLookup() {
59
60
void swift::initializeProtocolConformanceLookup () {
60
61
const swift::MetadataSections *sections = registered;
61
62
while (true ) {
62
- const swift::MetadataSections::Range &conformances =
63
+ const swift::MetadataSectionRange &conformances =
63
64
sections->swift5_protocol_conformances ;
64
65
if (conformances.length )
65
66
addImageProtocolConformanceBlockCallbackUnsafe (
@@ -74,7 +75,7 @@ void swift::initializeProtocolConformanceLookup() {
74
75
void swift::initializeTypeMetadataRecordLookup () {
75
76
const swift::MetadataSections *sections = registered;
76
77
while (true ) {
77
- const swift::MetadataSections::Range &type_metadata =
78
+ const swift::MetadataSectionRange &type_metadata =
78
79
sections->swift5_type_metadata ;
79
80
if (type_metadata.length )
80
81
addImageTypeMetadataRecordBlockCallbackUnsafe (
@@ -98,7 +99,11 @@ void swift_addNewDSOImage(const void *addr) {
98
99
const swift::MetadataSections *sections =
99
100
static_cast <const swift::MetadataSections *>(addr);
100
101
101
- record (sections);
102
+ // We cast off the const in order to update the linked list
103
+ // data structure. This is safe to do since we don't touch
104
+ // any other fields.
105
+ auto casted_sections = const_cast <MetadataSections *>(sections);
106
+ record (casted_sections);
102
107
103
108
const auto &protocols_section = sections->swift5_protocols ;
104
109
const void *protocols =
0 commit comments