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

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

Closed
andrewrk opened this issue Jan 7, 2016 · 2 comments · Fixed by #1647
Closed
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jan 7, 2016

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.
@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Jan 7, 2016
@thejoshwolfe
Copy link
Sponsor Contributor

Why have separate memcpy.o and memset.o instead of prebuilding a mem.a and linking with ld -o foo foo.o mem.a? Doesn't that still provide the selective linking feature we want?

@andrewrk
Copy link
Member Author

andrewrk commented Jan 7, 2016

That should work too.

@andrewrk andrewrk added this to the debut milestone Jan 18, 2016
@andrewrk andrewrk removed this from the 0.1.0 milestone Mar 23, 2017
@andrewrk andrewrk added this to the 0.2.0 milestone May 7, 2017
@andrewrk andrewrk changed the title link against memcpy and memset properly link builtins in a way that lets unused functions get omitted from final library/binary May 21, 2017
@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Jan 3, 2018
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Sep 28, 2018
andrewrk added a commit that referenced this issue Oct 8, 2018
andrewrk added a commit that referenced this issue Oct 9, 2018
@andrewrk andrewrk modified the milestones: 0.5.0, 0.4.0 Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants