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

Code fails to link on macOS with incremental compilation #51608

Open
jrmuizel opened this issue Jun 17, 2018 · 15 comments
Open

Code fails to link on macOS with incremental compilation #51608

jrmuizel opened this issue Jun 17, 2018 · 15 comments
Labels
A-incr-comp Area: Incremental compilation A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one. O-macos Operating system: macOS P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jrmuizel
Copy link
Contributor

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

@jrmuizel
Copy link
Contributor Author

@michaelwoerister

@jrmuizel
Copy link
Contributor Author

Here's the relevant portions of assembly.

Incremental:

        .section        __TEXT,__objc_methname,cstring_literals
__ZN7example9obj_alloc19OBJC_METH_VAR_NAME_17h2ea10c5dd1335938E:
        .asciz  "alloc"

        .private_extern __ZN7example9obj_alloc25OBJC_SELECTOR_REFERENCES_17ha196cc644aeae679E
        .section        __DATA,__objc_selrefs,literal_pointers,no_dead_strip
        .globl  __ZN7example9obj_alloc25OBJC_SELECTOR_REFERENCES_17ha196cc644aeae679E
        .p2align        3
__ZN7example9obj_alloc25OBJC_SELECTOR_REFERENCES_17ha196cc644aeae679E:
        .quad   __ZN7example9obj_alloc19OBJC_METH_VAR_NAME_17h2ea10c5dd1335938E

non-incremental

        .section        __TEXT,__objc_methname,cstring_literals
__ZN7example9obj_alloc19OBJC_METH_VAR_NAME_17h2ea10c5dd1335938E:
        .asciz  "alloc"

        .section        __DATA,__objc_selrefs,literal_pointers,no_dead_strip
        .p2align        3
__ZN7example9obj_alloc25OBJC_SELECTOR_REFERENCES_17ha196cc644aeae679E:
        .quad   __ZN7example9obj_alloc19OBJC_METH_VAR_NAME_17h2ea10c5dd1335938E

The notable difference is the addition of .private_extern

@jrmuizel
Copy link
Contributor Author

And the LLVM ir.

Incremental:

@_ZN7example9obj_alloc19OBJC_METH_VAR_NAME_17h2ea10c5dd1335938E = internal constant <{ [6 x i8] }> <{ [6 x i8] c"alloc\00" }>, section "__TEXT,__objc_methname,cstring_literals", align 1, !dbg !0
@_ZN7example9obj_alloc25OBJC_SELECTOR_REFERENCES_17ha196cc644aeae679E = hidden constant <{ i8*, [0 x i8] }> <{ i8* getelementptr inbounds (<{ [6 x i8] }>, <{ [6 x i8] }>* @_ZN7example9obj_alloc19OBJC_METH_VAR_NAME_17h2ea10c5dd1335938E, i32 0, i32 0, i32 0), [0 x i8] zeroinitializer }>, section "__DATA,__objc_selrefs,literal_pointers,no_dead_strip", align 8, !dbg !9

non-incremental

@_ZN7example9obj_alloc19OBJC_METH_VAR_NAME_17h2ea10c5dd1335938E = internal constant <{ [6 x i8] }> <{ [6 x i8] c"alloc\00" }>, section "__TEXT,__objc_methname,cstring_literals", align 1, !dbg !11
@_ZN7example9obj_alloc25OBJC_SELECTOR_REFERENCES_17ha196cc644aeae679E = internal constant <{ i8*, [0 x i8] }> <{ i8* getelementptr inbounds (<{ [6 x i8] }>, <{ [6 x i8] }>* @_ZN7example9obj_alloc19OBJC_METH_VAR_NAME_17h2ea10c5dd1335938E, i32 0, i32 0, i32 0), [0 x i8] zeroinitializer }>, section "__DATA,__objc_selrefs,literal_pointers,no_dead_strip", align 8, !dbg !20

@jrmuizel
Copy link
Contributor Author

Also, it's worth noting the link failure only happens with the constants inside generic functions.

@stokhos stokhos added A-linkage Area: linking into static, shared libraries and binaries O-macos Operating system: macOS A-incr-comp Area: Incremental compilation labels Jun 18, 2018
@jkordish jkordish added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 26, 2018
@michaelwoerister
Copy link
Member

Thanks for the bug report! Nominating for priority assignment.

@jrmuizel
Copy link
Contributor Author

jrmuizel commented Jul 3, 2018

I think @pcwalton figured out what was going on here.

@pnkfelix
Copy link
Member

triage: P-high

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Jul 12, 2018
@pnkfelix
Copy link
Member

hey @jrmuizel did you actually find anything interesting out from @pcwalton about this?

@pnkfelix
Copy link
Member

assigning to @michaelwoerister under assumption that he is best suited to attack this issue

@jrmuizel
Copy link
Contributor Author

Here's what he wrote: SSheldon/rust-objc#49 (comment). I don't know anything beyond that.

@pnkfelix
Copy link
Member

pnkfelix commented Jul 26, 2018

visiting for triage.

I'm currently trying to understand whether this should remain at P-high or not; it sounds like servo is making do without this fixed, but there maybe efficiency issues (in our generated code) that could be addressed if we fixed this? not clear.

@pnkfelix
Copy link
Member

pnkfelix commented Aug 2, 2018

visiting for triage again

@pcwalton do you have any input on whether this should remain at P-high?

(I figure if we have radio silence for another week, we should probably downgrade at the next compiler team meeting.)

@nikomatsakis nikomatsakis added P-medium Medium priority and removed P-high High priority labels Aug 9, 2018
@nikomatsakis
Copy link
Contributor

Downgrading to P-medium for now. Please feel free to complain.

@nvzqz
Copy link
Contributor

nvzqz commented Dec 14, 2020

Has any progress been made here? I would like to emit selectors just like in ObjC/Swift in my library (issue: nvzqz/fruity#2).

@jrmuizel
Copy link
Contributor Author

See also #53929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one. O-macos Operating system: macOS P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants