Skip to content

Add .note.swift_reflection_metadata #26479

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
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
4 changes: 4 additions & 0 deletions stdlib/public/runtime/ImageInspectionELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef SWIFT_RUNTIME_IMAGEINSPECTIONELF_H
#define SWIFT_RUNTIME_IMAGEINSPECTIONELF_H

#define SWIFT_REFLECTION_METADATA_ELF_NOTE_MAGIC_STRING "swift_reflection_metadata_magic_string"

#if defined(__ELF__)

#include "../SwiftShims/Visibility.h"
Expand Down Expand Up @@ -54,6 +56,8 @@ struct MetadataSections {
Range swift5_assocty;
Range swift5_replace;
Range swift5_replac2;
Range swift5_builtin;
Range swift5_capture;
};
} // namespace swift

Expand Down
14 changes: 14 additions & 0 deletions stdlib/public/runtime/SwiftRT-ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ DECLARE_SWIFT_SECTION(swift5_fieldmd)
DECLARE_SWIFT_SECTION(swift5_assocty)
DECLARE_SWIFT_SECTION(swift5_replace)
DECLARE_SWIFT_SECTION(swift5_replac2)
DECLARE_SWIFT_SECTION(swift5_builtin)
DECLARE_SWIFT_SECTION(swift5_capture)
}

#undef DECLARE_SWIFT_SECTION
Expand Down Expand Up @@ -65,10 +67,22 @@ static void swift_image_constructor() {
SWIFT_SECTION_RANGE(swift5_assocty),
SWIFT_SECTION_RANGE(swift5_replace),
SWIFT_SECTION_RANGE(swift5_replac2),
SWIFT_SECTION_RANGE(swift5_builtin),
SWIFT_SECTION_RANGE(swift5_capture),
};

#undef SWIFT_SECTION_RANGE

swift_addNewDSOImage(&sections);
}

__asm__(".section \".note.swift_reflection_metadata\", \"aw\"");

static __attribute__((__used__))
__attribute__((__section__(".note.swift_reflection_metadata")))
__attribute__((__aligned__(1)))
struct {
const char MagicString[sizeof(SWIFT_REFLECTION_METADATA_ELF_NOTE_MAGIC_STRING)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that doing sizeof(SWIFT_REFLECTION_METADATA_ELF_NOTE_MAGIC_STRING)/sizeof(*SWIFT_REFLECTION_METADATA_ELF_NOTE_MAGIC_STRING) is better.

const swift::MetadataSections *Sections;
} __attribute__((__packed__))
Note = {SWIFT_REFLECTION_METADATA_ELF_NOTE_MAGIC_STRING, &sections};