Skip to content

Commit

Permalink
Revert "Add option for eliding property metadata from messages"
Browse files Browse the repository at this point in the history
This reverts commit ca3674b.

While there are savings, it ends up being to easy/common to run into issues with
AppStore validation since the selector usage now appears to be a possible match
for private apis vs. for selectors/properties in the generated code.
  • Loading branch information
thomasvl committed Jul 12, 2021
1 parent 378238e commit 4b3da9f
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 1,430 deletions.
24 changes: 2 additions & 22 deletions objectivec/DevTools/compile_testing_protos.sh
@@ -1,34 +1,15 @@
#!/bin/bash -eu
# Invoked by the Xcode projects to build the protos needed for the unittests.

readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos"

# -----------------------------------------------------------------------------
# Helper for bailing.
die() {
echo "Error: $1"
exit 2
}

# -----------------------------------------------------------------------------
# Parameters.
if (( $# > 1 )); then
die "Script takes only one parameter: $#"
fi

if (( $# == 1 )); then
case "$1" in
"--elide_message_metadata")
readonly ELIDE_MESSAGE_METADATA_OPTION="--objc_opt=elide_message_metadata"
readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/elided/protos"
;;
*)
die "Unknown option: $1"
;;
esac
else
readonly ELIDE_MESSAGE_METADATA_OPTION=""
readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/normal/protos"
fi

# -----------------------------------------------------------------------------
# What to do.
case "${ACTION}" in
Expand Down Expand Up @@ -176,7 +157,6 @@ compile_protos() {
--proto_path=src/google/protobuf/ \
--proto_path=src \
--experimental_allow_proto3_optional \
${ELIDE_MESSAGE_METADATA_OPTION} \
"$@"
}

Expand Down
130 changes: 0 additions & 130 deletions objectivec/GPBMessage_PackagePrivate.h
Expand Up @@ -34,8 +34,6 @@

#import "GPBMessage.h"

#import "GPBUtilities_PackagePrivate.h"

// TODO: Remove this import. Older generated code use the OSAtomic* apis,
// so anyone that hasn't regenerated says building by having this. After
// enough time has passed, this likely can be removed as folks should have
Expand All @@ -44,134 +42,6 @@

#import "GPBBootstrap.h"

#if defined(__LP64__) && __LP64__
#define GPB_ASM_PTR " .quad "
#define GPB_ASM_PTRSIZE " 8 "
#define GPB_ASM_ONLY_LP64(x) x
#define GPB_ALIGN_SIZE " 3 "
#define GPB_DESCRIPTOR_METHOD_TYPE "@16@0:8"
#else // __LP64__
#define GPB_ASM_PTR " .long "
#define GPB_ASM_PTRSIZE " 4 "
#define GPB_ASM_ONLY_LP64(x)
#define GPB_ALIGN_SIZE " 2 "
#define GPB_DESCRIPTOR_METHOD_TYPE "@8@0:4"
#endif // __LP64__

#define GPB_MESSAGE_CLASS_NAME_RAW GPBMessage
#define GPB_MESSAGE_CLASS_NAME GPBStringifySymbol(GPB_MESSAGE_CLASS_NAME_RAW)

#if !__has_feature(objc_arc)
#define GPB_CLASS_FLAGS " 0x00 "
#define GPB_METACLASS_FLAGS " 0x01 "
#else
// 0x80 denotes that the class supports ARC.
#define GPB_CLASS_FLAGS " 0x80 "
#define GPB_METACLASS_FLAGS " 0x81 "
#endif

// This generates code equivalent to:
// ```
// @implementation _name_
// + (GPBDescriptor *)descriptor {
// return _descriptorFunc_(self, _cmd);
// }
// @end
// ```
// We do this to avoid all of the @property metadata.
// If we use `@dynamic` the compiler generates a lot of property data including
// selectors and encoding strings. For large uses of protobufs, this can add
// up to several megabytes of unused Objective-C metadata.
// This inline class definition avoids the property data generation at the
// cost of being a little ugly. This has been tested with both 32 and 64 bits
// on intel and arm with Xcode 11.7 and Xcode 12.4.
// We make cstring_literals be local definitions by starting them with "L".
// https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_chapter/as_5.html#SEC48
// This keeps our symbols tables smaller, and is what the linker expects.
// The linker in Xcode 12+ seems to be a bit more lenient about it, but the
// Xcode 11 linker requires it, and will give a cryptic "malformed method list"
// assertion if they are global.
#define GPB_MESSAGE_SUBCLASS_IMPL(name, descriptorFunc) \
__asm__( \
".section __TEXT, __objc_classname, cstring_literals \n" \
"L_OBJC_CLASS_NAME_" GPBStringifySymbol(name) ": " \
" .asciz \"" GPBStringifySymbol(name) "\" \n" \
\
".ifndef L_GBPDescriptorMethodName \n" \
".section __TEXT, __objc_methname, cstring_literals \n" \
"L_GBPDescriptorMethodName: .asciz \"descriptor\" \n" \
".endif \n" \
\
".ifndef L_GPBDescriptorMethodType \n" \
".section __TEXT, __objc_methtype, cstring_literals \n" \
"L_GPBDescriptorMethodType: .asciz \"" GPB_DESCRIPTOR_METHOD_TYPE "\" \n" \
".endif \n" \
\
".section __DATA,__objc_const, regular \n" \
".p2align" GPB_ALIGN_SIZE "\n" \
"__OBJC_$_CLASS_METHODS_" GPBStringifySymbol(name) ": \n" \
".long 3 *" GPB_ASM_PTRSIZE "\n" \
".long 0x1 \n" \
GPB_ASM_PTR "L_GBPDescriptorMethodName \n" \
GPB_ASM_PTR "L_GPBDescriptorMethodType \n" \
GPB_ASM_PTR "_" #descriptorFunc " \n" \
\
".section __DATA,__objc_const, regular \n" \
".p2align" GPB_ALIGN_SIZE "\n" \
"__OBJC_METACLASS_RO_$_" GPBStringifySymbol(name) ": \n" \
".long" GPB_METACLASS_FLAGS "\n" \
".long 5 *" GPB_ASM_PTRSIZE "\n" \
".long 5 *" GPB_ASM_PTRSIZE "\n" \
GPB_ASM_ONLY_LP64(".space 4 \n") \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "L_OBJC_CLASS_NAME_" GPBStringifySymbol(name) " \n" \
GPB_ASM_PTR "__OBJC_$_CLASS_METHODS_" GPBStringifySymbol(name) " \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "0 \n" \
\
".section __DATA,__objc_const, regular \n" \
".p2align" GPB_ALIGN_SIZE "\n" \
"__OBJC_CLASS_RO_$_" GPBStringifySymbol(name) ": \n" \
".long" GPB_CLASS_FLAGS "\n" \
".long" GPB_ASM_PTRSIZE "\n" \
".long" GPB_ASM_PTRSIZE "\n" \
GPB_ASM_ONLY_LP64(".long 0 \n") \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "L_OBJC_CLASS_NAME_" GPBStringifySymbol(name) " \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "0 \n" \
\
".globl _OBJC_METACLASS_$_" GPBStringifySymbol(name) "\n" \
".section __DATA,__objc_data, regular \n" \
".p2align" GPB_ALIGN_SIZE "\n" \
"_OBJC_METACLASS_$_" GPBStringifySymbol(name) ": \n" \
GPB_ASM_PTR "_OBJC_METACLASS_$_NSObject \n" \
GPB_ASM_PTR "_OBJC_METACLASS_$_" GPB_MESSAGE_CLASS_NAME " \n" \
GPB_ASM_PTR "__objc_empty_cache \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "__OBJC_METACLASS_RO_$_" GPBStringifySymbol(name) " \n" \
\
".globl _OBJC_CLASS_$_" GPBStringifySymbol(name) "\n" \
".section __DATA,__objc_data, regular \n" \
".p2align" GPB_ALIGN_SIZE "\n" \
"_OBJC_CLASS_$_" GPBStringifySymbol(name) ": \n" \
GPB_ASM_PTR "_OBJC_METACLASS_$_" GPBStringifySymbol(name) " \n" \
GPB_ASM_PTR "_OBJC_CLASS_$_" GPB_MESSAGE_CLASS_NAME " \n" \
GPB_ASM_PTR "__objc_empty_cache \n" \
GPB_ASM_PTR "0 \n" \
GPB_ASM_PTR "__OBJC_CLASS_RO_$_" GPBStringifySymbol(name) " \n" \
\
".section __DATA, __objc_classlist, regular, no_dead_strip \n" \
".p2align" GPB_ALIGN_SIZE "\n" \
"_OBJC_LABEL_CLASS_$" GPBStringifySymbol(name) ": \n" \
GPB_ASM_PTR "_OBJC_CLASS_$_" GPBStringifySymbol(name) " \n" \
)

typedef struct GPBMessage_Storage {
uint32_t _has_storage_[0];
} GPBMessage_Storage;
Expand Down

0 comments on commit 4b3da9f

Please sign in to comment.