The previous CL's approach of using `__attribute__((weakref()))` was not actually behaving as expected, and the unit tests were not sufficient to catch this.
We now use inline assembly to achieve the functionality that we thought we were getting with `__attribute__((weakref()))`. From assembly, we can create a weak symbol whose value is the same as another "stub" symbol in the same file.
Unfortunately we cannot have all of our weak symbols reference a single placeholder "empty" message, due to a bug I discovered in the LLVM linker and reported in https://github.com/llvm/llvm-project/issues/167262
If and when that bug is fixed, we should be able to get optimal tree shaking behavior, even on iOS.
PiperOrigin-RevId: 831396179
To do this, we use `__attribute__((weakref()))` to weakly reference a placeholder definition for tree shaken sub-messages. This provides the same tree shaking behavior we had before, but without needing an extra indirection. If we had discovered this technique before, we would have had no reason to add the indirection in cl/640369522.
This will reduce the code size and memory overhead of any MiniTables with sub-messages in them, because we no longer need an extra `void*` per sub-message field to store the extra indirect pointer.
It also should improve efficiency a bit since there is one fewer indirection when recursing into a sub-message field.
PiperOrigin-RevId: 829022414
General test for it is done in Rust, and then extensions are tested in UPB as they're not currently supported in Rust-upb.
PiperOrigin-RevId: 651113583