Skip to content

link builtins in a way that lets unused functions get omitted from final library/binary #54

Description

@andrewrk

when linking without libc, build memcpy.o and memset.o. we can cache these objects with a hash of (release/debug, conditional compilation values, target triple/data layout).

generate a compile unit without memcpy/memset exported. when linking the final output, use ar rcs foo.a foo.o memcpy.o memset.o. Then ld -o foo foo.a (or equivalent).

This accomplishes several things:

  • omit memcpy/memset when the functions are unused
  • avoid compiling memcpy/memset with every compiler invocation
  • allow linking zig-created .o files with libc .o files, so that a single project can have both c code and zig code and everything can be linked together. in this case zig generated code will depend on the libc memset/memcpy implementations.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions