Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ld64.lld: Support synthesizing relative ObjC method lists #57809

Closed
BertalanD opened this issue Sep 18, 2022 · 1 comment · Fixed by #86231
Closed

ld64.lld: Support synthesizing relative ObjC method lists #57809

BertalanD opened this issue Sep 18, 2022 · 1 comment · Fixed by #86231

Comments

@BertalanD
Copy link
Member

BertalanD commented Sep 18, 2022

Starting with macOS 11, a more compact encoding is available for ObjC method lists. Previously, each method had a descriptor consisting of 3 pointers:

struct _objc_method {
    SEL _cmd;
    char *method_type;
    char *_imp;
}

In the new format, __TEXT,__objc_methlist stores 32-bit offsets instead.

struct _objc_method_rel {
    int32_t _cmd;
    int32_t method_type;
    int32_t _imp;
}

This transformation can be controlled with the -objc_relative_method_lists/-no_objc_relative_method_lists linker flags.

Currently, method lists are stored in __DATA,__objc_const. With this transformation, Chromium Framework's data segment will shrink by about 40 KB, meaning that 3 fewer pages will have to be relocated at startup.

ref #48630

Sidenote: AppleClang itself can be coaxed into generating the relative encoding with `-fobjc-relative-method-lists`
// test.m
#include <Foundation/Foundation.h>

int main() {
    NSObject *foo = [[NSObject alloc] init];
}
clang test.m  -S -emit-llvm  -o - | grep _objc_method
%struct.__method_list_t = type { i32, i32, [0 x %struct._objc_method] }
%struct._objc_method = type { i8*, i8*, i8* }clang test.m  -S -emit-llvm  -o - -fobjc-relative-method-lists | grep _objc_method
%struct.__method_list_t = type { i32, i32, [0 x %struct._objc_method_rel] }
%struct._objc_method_rel = type { i32, i32, i32 }
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 18, 2022

@llvm/issue-subscribers-lld-macho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants