Files
swift-mirror/stdlib/public/runtime/SwiftRT-ELF.cpp
Alastair Houghton 5e6c8b18ba Remove erroneous ELF note.
On ELF platforms we currently output an ELF note but with totally invalid
contents.  I tried experimenting to see whether it was possible to do it
properly and tie the result into ReflectionContext, but it turns out to be a
hard problem because of issues to do with cross-segment symbol references and
relocations.

The upshot is that I think for now it's best just to remove it.

We might revisit this in future at some point; it would be good to be able to
reliably find the Swift metadata just from the ELF Phdrs.

rdar://101749382
2022-11-04 02:51:20 -07:00

86 lines
2.9 KiB
C++

//===--- SwiftRT-ELF.cpp --------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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
//
//===----------------------------------------------------------------------===//
#include "ImageInspectionCommon.h"
#include "swift/shims/MetadataSections.h"
#include <cstddef>
#include <new>
extern "C" const char __dso_handle[];
// Create empty sections to ensure that the start/stop symbols are synthesized
// by the linker. Otherwise, we may end up with undefined symbol references as
// the linker table section was never constructed.
#define DECLARE_SWIFT_SECTION(name) \
__asm__("\t.section " #name ",\"a\"\n"); \
__attribute__((__visibility__("hidden"),__aligned__(1))) extern const char __start_##name; \
__attribute__((__visibility__("hidden"),__aligned__(1))) extern const char __stop_##name;
extern "C" {
DECLARE_SWIFT_SECTION(swift5_protocols)
DECLARE_SWIFT_SECTION(swift5_protocol_conformances)
DECLARE_SWIFT_SECTION(swift5_type_metadata)
DECLARE_SWIFT_SECTION(swift5_typeref)
DECLARE_SWIFT_SECTION(swift5_reflstr)
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)
DECLARE_SWIFT_SECTION(swift5_mpenum)
DECLARE_SWIFT_SECTION(swift5_accessible_functions)
}
#undef DECLARE_SWIFT_SECTION
namespace {
static swift::MetadataSections sections{};
}
__attribute__((__constructor__))
static void swift_image_constructor() {
#define SWIFT_SECTION_RANGE(name) \
{ reinterpret_cast<uintptr_t>(&__start_##name), \
static_cast<uintptr_t>(&__stop_##name - &__start_##name) }
::new (&sections) swift::MetadataSections {
swift::CurrentSectionMetadataVersion,
{ __dso_handle },
nullptr,
nullptr,
SWIFT_SECTION_RANGE(swift5_protocols),
SWIFT_SECTION_RANGE(swift5_protocol_conformances),
SWIFT_SECTION_RANGE(swift5_type_metadata),
SWIFT_SECTION_RANGE(swift5_typeref),
SWIFT_SECTION_RANGE(swift5_reflstr),
SWIFT_SECTION_RANGE(swift5_fieldmd),
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),
SWIFT_SECTION_RANGE(swift5_mpenum),
SWIFT_SECTION_RANGE(swift5_accessible_functions),
};
#undef SWIFT_SECTION_RANGE
swift_addNewDSOImage(&sections);
}