Files
swift-mirror/stdlib/public/runtime/ObjCRuntimeGetImageNameFromClass.h
Jordan Rose a2c1aa3624 [runtime] Backwards-deployment support for class_getImageName
Follow-up to 3ed3774e07. On Apple OSs that don't have the new
Objective-C runtime function 'objc_setHook_getImageName', override the
system definition of 'class_getImageName' by literally rewriting
symbol tables at run time.

Yes, you read that correctly.

The low-level part of this patch was written by Greg Parker, then
simplified and tweaked by me to fit the Swift coding style. Don't try
this at home; it comes with all sorts of caveats and won't actually
work on this year's iOS. (Fortunately we don't need it there, because
that will have the new ObjC entry point.)

The rest of the patch is pretty straightforward: the replacement
implementation calls the code that supports Swift objects (the same
code we use on newer OSs), which then chains back to the original
system implementation of class_getImageName. May we never have to
touch this again.

rdar://problem/41535552
2018-07-18 18:28:12 -07:00

30 lines
1000 B
C++

//===--- ObjCRuntimeGetImageNameFromClass.h - ObjC hook setup ---*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2018 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
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_RUNTIME_OBJCRUNTIMEGETIMAGENAMEFROMCLASS_H
#define SWIFT_RUNTIME_OBJCRUNTIMEGETIMAGENAMEFROMCLASS_H
#include "swift/Runtime/Config.h"
namespace swift {
#if SWIFT_OBJC_INTEROP
/// Set up class_getImageName so that it will understand Swift classes.
///
/// This function should only be called once per process.
void setUpObjCRuntimeGetImageNameFromClass();
#endif // SWIFT_OBJC_INTEROP
} // end namespace swift
#endif // SWIFT_RUNTIME_OBJCRUNTIMEGETIMAGENAMEFROMCLASS_H