2020-08-18 14:37:04 -07:00
|
|
|
//===- ObjC.h ---------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_MACHO_OBJC_H
|
|
|
|
#define LLD_MACHO_OBJC_H
|
|
|
|
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
|
2022-08-07 10:37:49 -04:00
|
|
|
namespace lld::macho {
|
2020-08-18 14:37:04 -07:00
|
|
|
|
|
|
|
namespace objc {
|
|
|
|
|
2024-03-01 14:12:56 -08:00
|
|
|
namespace symbol_names {
|
2020-08-18 14:37:04 -07:00
|
|
|
constexpr const char klass[] = "_OBJC_CLASS_$_";
|
[lld-macho] Implement ObjC category merging (-objc_category_merging) (#85727)
This change adds a flag to lld to enable category merging for MachoO +
ObjC.
It adds the '-objc_category_merging' flag for enabling this option and
uses the existing '-no_objc_category_merging' flag for disabling it.
In ld64, this optimization is enabled by default, but in lld, for now,
we require explicitly passing the '-objc_category_merging' flag in order
to enable it.
Behavior: if in the same link unit, multiple categories are extending
the same class, then they get merged into a single category.
Ex: Cat1(method1+method2,protocol1) + Cat2(method3+method4,protocol2,
property1) = Cat1_2(method1+method2+method3+method4,
protocol1+protocol2, property1)
Notes on implementation decisions made in this diff:
There is a possibility to further improve the current implementation by
directly merging the category data into the base class (if the base
class is present in the link unit) - this improvement may be done as a
follow-up. This improved functionality is already present in ld64.
We do the merging on the raw inputSections - after dead-stripping
(categories can't be dead stripped anyway).
The changes are mostly self-contained to ObjC.cpp, except for adding a
new flag (linkerOptimizeReason) to ConcatInputSection and StringPiece to
mark that this data has been optimized away. Another way to do it would
have been to just mark the pieces as not 'live' but this would cause the
old symbols to show up in the linker map as being dead-stripped - even
if dead-stripping is disabled. This flag allows us to match the ld64
behavior.
Note: This is a re-land of
https://github.com/llvm/llvm-project/pull/82928 after fixing using
already freed memory in `generatedSectionData`. This issue was detected
by ASAN build.
---------
Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-19 13:14:29 -07:00
|
|
|
constexpr const char klassPropList[] = "__OBJC_$_CLASS_PROP_LIST_";
|
|
|
|
|
2020-08-18 14:37:04 -07:00
|
|
|
constexpr const char metaclass[] = "_OBJC_METACLASS_$_";
|
|
|
|
constexpr const char ehtype[] = "_OBJC_EHTYPE_$_";
|
|
|
|
constexpr const char ivar[] = "_OBJC_IVAR_$_";
|
2024-03-27 14:34:27 -07:00
|
|
|
constexpr const char instanceMethods[] = "__OBJC_$_INSTANCE_METHODS_";
|
|
|
|
constexpr const char classMethods[] = "__OBJC_$_CLASS_METHODS_";
|
[lld-macho] Implement ObjC category merging (-objc_category_merging) (#85727)
This change adds a flag to lld to enable category merging for MachoO +
ObjC.
It adds the '-objc_category_merging' flag for enabling this option and
uses the existing '-no_objc_category_merging' flag for disabling it.
In ld64, this optimization is enabled by default, but in lld, for now,
we require explicitly passing the '-objc_category_merging' flag in order
to enable it.
Behavior: if in the same link unit, multiple categories are extending
the same class, then they get merged into a single category.
Ex: Cat1(method1+method2,protocol1) + Cat2(method3+method4,protocol2,
property1) = Cat1_2(method1+method2+method3+method4,
protocol1+protocol2, property1)
Notes on implementation decisions made in this diff:
There is a possibility to further improve the current implementation by
directly merging the category data into the base class (if the base
class is present in the link unit) - this improvement may be done as a
follow-up. This improved functionality is already present in ld64.
We do the merging on the raw inputSections - after dead-stripping
(categories can't be dead stripped anyway).
The changes are mostly self-contained to ObjC.cpp, except for adding a
new flag (linkerOptimizeReason) to ConcatInputSection and StringPiece to
mark that this data has been optimized away. Another way to do it would
have been to just mark the pieces as not 'live' but this would cause the
old symbols to show up in the linker map as being dead-stripped - even
if dead-stripping is disabled. This flag allows us to match the ld64
behavior.
Note: This is a re-land of
https://github.com/llvm/llvm-project/pull/82928 after fixing using
already freed memory in `generatedSectionData`. This issue was detected
by ASAN build.
---------
Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-19 13:14:29 -07:00
|
|
|
constexpr const char listProprieties[] = "__OBJC_$_PROP_LIST_";
|
|
|
|
|
|
|
|
constexpr const char category[] = "__OBJC_$_CATEGORY_";
|
|
|
|
constexpr const char categoryInstanceMethods[] =
|
|
|
|
"__OBJC_$_CATEGORY_INSTANCE_METHODS_";
|
|
|
|
constexpr const char categoryClassMethods[] =
|
|
|
|
"__OBJC_$_CATEGORY_CLASS_METHODS_";
|
|
|
|
constexpr const char categoryProtocols[] = "__OBJC_CATEGORY_PROTOCOLS_$_";
|
2024-06-13 08:06:25 -07:00
|
|
|
|
|
|
|
constexpr const char swift_objc_category[] = "__CATEGORY_";
|
2024-06-17 18:58:02 -07:00
|
|
|
constexpr const char swift_objc_klass[] = "_$s";
|
2024-03-01 14:12:56 -08:00
|
|
|
} // namespace symbol_names
|
2020-08-18 14:37:04 -07:00
|
|
|
|
2023-02-16 16:18:46 -05:00
|
|
|
// Check for duplicate method names within related categories / classes.
|
|
|
|
void checkCategories();
|
[lld-macho] Implement ObjC category merging (-objc_category_merging) (#85727)
This change adds a flag to lld to enable category merging for MachoO +
ObjC.
It adds the '-objc_category_merging' flag for enabling this option and
uses the existing '-no_objc_category_merging' flag for disabling it.
In ld64, this optimization is enabled by default, but in lld, for now,
we require explicitly passing the '-objc_category_merging' flag in order
to enable it.
Behavior: if in the same link unit, multiple categories are extending
the same class, then they get merged into a single category.
Ex: Cat1(method1+method2,protocol1) + Cat2(method3+method4,protocol2,
property1) = Cat1_2(method1+method2+method3+method4,
protocol1+protocol2, property1)
Notes on implementation decisions made in this diff:
There is a possibility to further improve the current implementation by
directly merging the category data into the base class (if the base
class is present in the link unit) - this improvement may be done as a
follow-up. This improved functionality is already present in ld64.
We do the merging on the raw inputSections - after dead-stripping
(categories can't be dead stripped anyway).
The changes are mostly self-contained to ObjC.cpp, except for adding a
new flag (linkerOptimizeReason) to ConcatInputSection and StringPiece to
mark that this data has been optimized away. Another way to do it would
have been to just mark the pieces as not 'live' but this would cause the
old symbols to show up in the linker map as being dead-stripped - even
if dead-stripping is disabled. This flag allows us to match the ld64
behavior.
Note: This is a re-land of
https://github.com/llvm/llvm-project/pull/82928 after fixing using
already freed memory in `generatedSectionData`. This issue was detected
by ASAN build.
---------
Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-19 13:14:29 -07:00
|
|
|
void mergeCategories();
|
2023-02-16 16:18:46 -05:00
|
|
|
|
[lld-macho] Implement ObjC category merging (-objc_category_merging) (#85727)
This change adds a flag to lld to enable category merging for MachoO +
ObjC.
It adds the '-objc_category_merging' flag for enabling this option and
uses the existing '-no_objc_category_merging' flag for disabling it.
In ld64, this optimization is enabled by default, but in lld, for now,
we require explicitly passing the '-objc_category_merging' flag in order
to enable it.
Behavior: if in the same link unit, multiple categories are extending
the same class, then they get merged into a single category.
Ex: Cat1(method1+method2,protocol1) + Cat2(method3+method4,protocol2,
property1) = Cat1_2(method1+method2+method3+method4,
protocol1+protocol2, property1)
Notes on implementation decisions made in this diff:
There is a possibility to further improve the current implementation by
directly merging the category data into the base class (if the base
class is present in the link unit) - this improvement may be done as a
follow-up. This improved functionality is already present in ld64.
We do the merging on the raw inputSections - after dead-stripping
(categories can't be dead stripped anyway).
The changes are mostly self-contained to ObjC.cpp, except for adding a
new flag (linkerOptimizeReason) to ConcatInputSection and StringPiece to
mark that this data has been optimized away. Another way to do it would
have been to just mark the pieces as not 'live' but this would cause the
old symbols to show up in the linker map as being dead-stripped - even
if dead-stripping is disabled. This flag allows us to match the ld64
behavior.
Note: This is a re-land of
https://github.com/llvm/llvm-project/pull/82928 after fixing using
already freed memory in `generatedSectionData`. This issue was detected
by ASAN build.
---------
Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-19 13:14:29 -07:00
|
|
|
void doCleanup();
|
2020-08-18 14:37:04 -07:00
|
|
|
} // namespace objc
|
|
|
|
|
|
|
|
bool hasObjCSection(llvm::MemoryBufferRef);
|
|
|
|
|
2022-08-07 10:37:49 -04:00
|
|
|
} // namespace lld::macho
|
2020-08-18 14:37:04 -07:00
|
|
|
|
|
|
|
#endif
|