Skip to content

Code fails to link on macOS with incremental compilation #51608

@jrmuizel

Description

@jrmuizel

The following code fails to link on macOS with incremental compilation. It works fine with incremental compilation turned off.

fn obj_alloc<T>(_p: T) -> *const [u8; 6] {
        struct Foo(*const [u8; 6]);
        unsafe impl Send for Foo {}
        unsafe impl Sync for Foo {}
        #[link_section="__TEXT,__objc_methname,cstring_literals"]
        static OBJC_METH_VAR_NAME_ : [u8; 6] = *b"alloc\0";

        #[link_section="__DATA,__objc_selrefs,literal_pointers,no_dead_strip"]
        static OBJC_SELECTOR_REFERENCES_: Foo = Foo(&OBJC_METH_VAR_NAME_);
        return OBJC_SELECTOR_REFERENCES_.0;
}

fn main() {
    let i: u32 = 0;
    obj_alloc(i);
}

The linker error is

  = note: Undefined symbols for architecture x86_64:
            "example::obj_alloc::OBJC_SELECTOR_REFERENCES_::ha196cc644aeae679", referenced from:
                example::obj_alloc::h54a034c209c8e4e3 in example-4a01b102e2898ce7.4jffkl93bkv60fxe.rcgu.o
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

The motivation for this weird code is getting native performance for objective-c message selectors. See SSheldon/rust-objc#49

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-incr-compArea: Incremental compilationA-linkageArea: linking into static, shared libraries and binariesC-enhancementCategory: An issue proposing an enhancement or a PR with one.O-macosOperating system: macOSP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions