mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Restructure the ELF handling to be completely agnostic to the OS. Rather than usng the loader to query the section information, use the linker to construct linker tables and synthetic markers for the beginning and of the table. Save off the values of these pointers and pass them along through the constructor to the runtime for registration. This removes the need for the begin/end objects. Remove the special construction of the begin/end objects through the special assembly constructs, preferring to do this in C with a bit of inline assembly to ensure that the section is always allocated. Remove the special handling for the various targets, the empty object file can be linked on all the targets. The new object file has no requirements on the ordering. It needs to simply be injected into the link. Name the replacement file `swiftrt.o` mirroring `crt.o` from libc. Merge the constructor and the definition into a single object file. This approach is generally more portable, overall simpler to implement, and more robust. Thanks to Orlando Bassotto for help analyzing some of the odd behaviours when switching over.
64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
//===--- ImageInspectionELF.h -----------------------------------*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
///
|
|
/// ELF specific image inspection routines.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_RUNTIME_IMAGEINSPECTIONELF_H
|
|
#define SWIFT_RUNTIME_IMAGEINSPECTIONELF_H
|
|
|
|
#if defined(__ELF__)
|
|
|
|
#include "../SwiftShims/Visibility.h"
|
|
#include <cstdint>
|
|
#include <cstddef>
|
|
|
|
namespace swift {
|
|
struct SectionInfo {
|
|
uint64_t size;
|
|
const char *data;
|
|
};
|
|
|
|
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 swift2_protocol_conformances;
|
|
Range swift2_type_metadata;
|
|
Range swift3_typeref;
|
|
Range swift3_reflstr;
|
|
Range swift3_fieldmd;
|
|
Range swift3_assocty;
|
|
};
|
|
} // namespace swift
|
|
|
|
// Called by injected constructors when a dynamic library is loaded.
|
|
SWIFT_RUNTIME_EXPORT
|
|
void swift_addNewDSOImage(const void *addr);
|
|
|
|
#endif // defined(__ELF__)
|
|
|
|
#endif // SWIFT_RUNTIME_IMAGE_INSPECTION_ELF_H
|