Skip to content

Weak aliases on MacOS aren't made global/public #111321

@tgross35

Description

@tgross35

Sample code:

int bar();
int foo() { return 20; }

#pragma weak bar = foo

This should make a symbol that is linkable from external libraries, but instead bar gets placed in private text. Attempting to link fails.

$ nm a.o
0000000000000000 t _bar
0000000000000000 T _foo
0000000000000000 t ltmp0
0000000000000008 s ltmp1
$ clang b.c a.o    # b.c just tries to call `bar()`
Undefined symbols for architecture arm64:
  "_bar", referenced from:
      _main in b-457c5f.o
ld: symbol(s) not found for architecture arm64

On Linux, bar correctly gets made a public weak symbol:

0000000000000000 W bar
0000000000000000 T foo

This functionality should be supported in MacOS:

Metadata

Metadata

Assignees

No one assigned

    Labels

    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