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

make -fcompiler_rt default to enabled when building static libraries #1993

Open
markfirmware opened this issue Feb 21, 2019 · 8 comments
Open
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@markfirmware
Copy link
Contributor

markfirmware commented Feb 21, 2019

I also need this for armv6, and another test case was missing memcpy.
I see something similar in #254 which is closed.

debian9/x64
Linux localhost 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux

$ zig version
0.3.0+db31c252

$ cat file.zig
const std = @import("std");

export fn zigmain() void {
    var warnBuf: [1024]u8 = undefined;
    _ = std.fmt.bufPrint(&warnBuf, "");
}


$ zig build-obj --target-arch armv7 --target-os freestanding --target-environ gnueabihf file.zig
$ nm file.o | grep U
        U __aeabi_uidivmod
        U memset
@andrewrk
Copy link
Member

These functions are provided automatically by Zig when you use build-exe, but not build-obj.

One thing it may make sense to do is to provide these symbols but with weak linkage, for build-lib --static. So then instead of zig build-obj --target-arch armv7 --target-os freestanding --target-environ gnueabihf file.zig you would do zig build-lib --static --target-arch armv7 --target-os freestanding --target-environ gnueabihf file.zig. Does that sound good?

@markfirmware markfirmware changed the title armv7 freestanding gnueabihf - undefined memset __aeabi_uidivmod build-obj armv7 freestanding gnueabihf - undefined memset __aeabi_uidivmod Feb 21, 2019
@markfirmware
Copy link
Contributor Author

That sounds great. This is not holding me up, I just noticed that I was linking in an extra dependency that I don't want. Mark.

@andrewrk andrewrk added this to the 0.5.0 milestone Feb 21, 2019
@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Feb 21, 2019
@andrewrk andrewrk changed the title build-obj armv7 freestanding gnueabihf - undefined memset __aeabi_uidivmod when building static libraries, include compiler_rt and builtin in the static library with weak linkage Feb 21, 2019
@andrewrk
Copy link
Member

I want to note - LLVM emits libcalls to these functions; its generated code depends on them being available. Furthermore, when the optimizer runs it may collapse a for loop into a call to memset or memcpy, or other functions such as these. Zig provides all these functions in compiler_rt and builtin.

So you cannot escape them as dependencies, but you can rely on the dependencies always being fulfilled.

@markfirmware
Copy link
Contributor Author

markfirmware commented Feb 21, 2019

I see. The dependency is supplied in zig's stdlib.

@andrewrk
Copy link
Member

That's correct, they are supplied by zig's stdlib, in std/special/builtin.zig and std/special/compiler_rt/*. However it's common for these symbols to be supplied by external libs such as libc, libgcc, compiler_rt, and they have well-defined ABIs. So Zig supplies these dependencies in a way that will not take up double-space if they are ultimately fulfilled externally. For example, if you link libc, then Zig's implementation of memcpy and memset are garbage-collected by the linker thus waste no space.

@markfirmware
Copy link
Contributor Author

Thanks for the attention. Great service!

@andrewrk
Copy link
Member

andrewrk commented Jan 3, 2020

Zig has --bundle-compiler-rt and corresponding build.zig API, so this is a low priority issue.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 3, 2020
@markfirmware
Copy link
Contributor Author

@andrewrk Thanks I will look at --bundle-compiler-rt. This issue arose when trying to integrate zig with https://ultibo.org which is taking lower priority to zig-only solutions.

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. and removed enhancement Solving this issue will likely involve adding new logic or components to the codebase. labels Oct 13, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk changed the title when building static libraries, include compiler_rt and builtin in the static library with weak linkage make -fcompiler_rt default to enabled when building static libraries Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants