Skip to content

Move 'MetadataSections' from 'ImageInspectionElf.h' to SwiftShims #32493

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
Jun 29, 2020
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
1 change: 1 addition & 0 deletions stdlib/public/SwiftShims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(sources
KeyPath.h
LibcOverlayShims.h
LibcShims.h
MetadataSections.h
Random.h
RefCount.h
RuntimeShims.h
Expand Down
63 changes: 63 additions & 0 deletions stdlib/public/SwiftShims/MetadataSections.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//===--- MetadataSections.h -----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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 contains the declaration of the MetadataSectionsRange and
/// MetadataSections struct, which represent, respectively, information about
/// an image's section, and an image's metadata information (which is composed
/// of multiple section information).
///
//===----------------------------------------------------------------------===//

#ifndef SWIFT_STDLIB_SHIMS_METADATASECTIONS_H
#define SWIFT_STDLIB_SHIMS_METADATASECTIONS_H

#include "SwiftStddef.h"
#include "SwiftStdint.h"

#ifdef __cplusplus
namespace swift {
extern "C" {
#endif

typedef struct MetadataSectionRange {
__swift_uintptr_t start;
__swift_size_t length;
} MetadataSectionRange;

struct MetadataSections {
__swift_uintptr_t version;
__swift_uintptr_t reserved;

struct MetadataSections *next;
struct MetadataSections *prev;


MetadataSectionRange swift5_protocols;
MetadataSectionRange swift5_protocol_conformances;
MetadataSectionRange swift5_type_metadata;
MetadataSectionRange swift5_typeref;
MetadataSectionRange swift5_reflstr;
MetadataSectionRange swift5_fieldmd;
MetadataSectionRange swift5_assocty;
MetadataSectionRange swift5_replace;
MetadataSectionRange swift5_replac2;
MetadataSectionRange swift5_builtin;
MetadataSectionRange swift5_capture;
};

#ifdef __cplusplus
} //extern "C"
} // namespace swift
#endif

#endif // SWIFT_STDLIB_SHIMS_METADATASECTIONS_H
1 change: 1 addition & 0 deletions stdlib/public/SwiftShims/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module SwiftShims {
header "HeapObject.h"
header "KeyPath.h"
header "LibcShims.h"
header "MetadataSections.h"
header "Random.h"
header "RefCount.h"
header "RuntimeShims.h"
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/runtime/ImageInspection.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#ifndef SWIFT_RUNTIME_IMAGEINSPECTION_H
#define SWIFT_RUNTIME_IMAGEINSPECTION_H

#include "ImageInspectionELF.h"
#include <cstdint>
#include <cstddef>
#if defined(__cplusplus)
Expand Down
17 changes: 11 additions & 6 deletions stdlib/public/runtime/ImageInspectionELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@

#if defined(__ELF__)

#include "../SwiftShims/MetadataSections.h"
#include "ImageInspection.h"
#include "ImageInspectionELF.h"
#include <dlfcn.h>

using namespace swift;

namespace {
static const swift::MetadataSections *registered = nullptr;
static swift::MetadataSections *registered = nullptr;

void record(const swift::MetadataSections *sections) {
void record(swift::MetadataSections *sections) {
if (registered == nullptr) {
registered = sections;
sections->next = sections->prev = sections;
Expand All @@ -45,7 +46,7 @@ void record(const swift::MetadataSections *sections) {
void swift::initializeProtocolLookup() {
const swift::MetadataSections *sections = registered;
while (true) {
const swift::MetadataSections::Range &protocols =
const swift::MetadataSectionRange &protocols =
sections->swift5_protocols;
if (protocols.length)
addImageProtocolsBlockCallbackUnsafe(
Expand All @@ -59,7 +60,7 @@ void swift::initializeProtocolLookup() {
void swift::initializeProtocolConformanceLookup() {
const swift::MetadataSections *sections = registered;
while (true) {
const swift::MetadataSections::Range &conformances =
const swift::MetadataSectionRange &conformances =
sections->swift5_protocol_conformances;
if (conformances.length)
addImageProtocolConformanceBlockCallbackUnsafe(
Expand All @@ -74,7 +75,7 @@ void swift::initializeProtocolConformanceLookup() {
void swift::initializeTypeMetadataRecordLookup() {
const swift::MetadataSections *sections = registered;
while (true) {
const swift::MetadataSections::Range &type_metadata =
const swift::MetadataSectionRange &type_metadata =
sections->swift5_type_metadata;
if (type_metadata.length)
addImageTypeMetadataRecordBlockCallbackUnsafe(
Expand All @@ -98,7 +99,11 @@ void swift_addNewDSOImage(const void *addr) {
const swift::MetadataSections *sections =
static_cast<const swift::MetadataSections *>(addr);

record(sections);
// We cast off the const in order to update the linked list
// data structure. This is safe to do since we don't touch
// any other fields.
auto casted_sections = const_cast<MetadataSections *>(sections);
record(casted_sections);

const auto &protocols_section = sections->swift5_protocols;
const void *protocols =
Expand Down
25 changes: 0 additions & 25 deletions stdlib/public/runtime/ImageInspectionELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,6 @@ struct SectionInfo {
};

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 swift5_protocols;
Range swift5_protocol_conformances;
Range swift5_type_metadata;
Range swift5_typeref;
Range swift5_reflstr;
Range swift5_fieldmd;
Range swift5_assocty;
Range swift5_replace;
Range swift5_replac2;
Range swift5_builtin;
Range swift5_capture;
};
} // namespace swift

// Called by injected constructors when a dynamic library is loaded.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/runtime/SwiftRT-ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "ImageInspectionELF.h"
#include "../SwiftShims/MetadataSections.h"

#include <cstddef>

Expand Down