Skip to content

zig ld: support LTO #8680

Closed as not planned
Closed as not planned

Description

@xxxbxxx

main.zig:

const std = @import("std");

pub fn main() anyerror!void {
    std.log.info("All your codebase are belong to us.", .{});
}
zig build-exe main.zig -OReleaseFast -target native-macos

--> ok.

touch dummy.c
zig build-exe main.zig dummy.c -OReleaseFast -target native-macos

--> error: MissingMainEntrypoint

zig build-exe main.zig dummy.c -target native-macos

--> ok

Activity

  1. added
    bug
    on May 5, 2021
  2. kubkon commented on May 5, 2021

    @kubkon
    Member

    Potentially related #8552

  3. xxxbxxx commented on May 5, 2021

    @xxxbxxx
    ContributorAuthor

    I wanted to verify this but it's probably that wanting to link with a c file makes the zip compilation unit compile with LTO, and so the .o file is a llvm ir and not a 'normal' object file.
    And probably the new linker doesn't know how to deal with it.

  4. added this to the 0.9.0 milestone on May 5, 2021
  5. kubkon commented on May 5, 2021

    @kubkon
    Member

    I wanted to verify this but it's probably that wanting to link with a c file makes the zip compilation unit compile with LTO, and so the .o file is a llvm ir and not a 'normal' object file.
    And probably the new linker doesn't know how to deal with it.

    Correct, zig ld is not advanced enough just yet, but it's defo on the roadmap. Thanks for filing the issue!

  6. wojtekmach commented on May 13, 2021

    @wojtekmach
    Contributor

    not sure if it is related but I noticed a similar error when using zig cc -shared. Targeting x86_64 works perfectly but I'm getting this error for aarch64.

    on an Intel Mac:

    ~% uname -a
    Darwin imac.local 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64
    ~% cat hello.c
    int hello() {
      return 0;
    }
    ~% zig cc hello.c -shared
    ~% zig cc hello.c -shared -target aarch64-macos
    error: MissingMainEntrypoint
    

    and on a M1 Mac:

    ~% uname -a
    Darwin m1.local 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:41 PDT 2021; root:xnu-7195.101.2~1/RELEASE_ARM64_T8101 arm64
    ~% zig cc hello.c -shared -target x86_64-macos
    ~% zig cc hello.c -shared
    error: MissingMainEntrypoint
    
  7. kubkon commented on May 13, 2021

    @kubkon
    Member

    @wojtekmach actually, your issue is related to #8317. zig ld is not yet able to link nor produce a shared library and on x64 we fallback to LLD hence why it works on a native host. On arm64, we always use zig ld however hence why the deceptive error message which I should really tweak!

  8. kubkon commented on May 13, 2021

    @kubkon
    Member

    @wojtekmach when linking natively on arm64, you could fallback to the system linker for the time being btw until zig ld gains the missing abilities to link and produce shared libs: see #8728

  9. wojtekmach commented on May 13, 2021

    @wojtekmach
    Contributor

    I tried that too but I'm unfortunately getting the same error:

    % zig version
    0.8.0-dev.2133+ad33e3483
    % ZIG_SYSTEM_LINKER_HACK=1 zig cc hello.c -shared -target aarch64-macos
    error: MissingMainEntrypoint
    
  10. wojtekmach commented on May 13, 2021

    @wojtekmach
    Contributor

    oh I'm sorry, I was cross-compiling from a x64 host. linker hack works from the arm64 host. Thanks and sorry for the noise!

  11. modified the milestones: 0.9.0, 0.10.0 on May 19, 2021
  12. wojtekmach commented on May 20, 2021

    @wojtekmach
    Contributor

    @kubkon I saw in #8317 that some zig ld preliminary work landed so just in case I gave it another shot here but I see the same result. I was wondering if this problem will be solved by this issue, #8317, or some other one. Just wondering which issue I should track is all :) In any case, thank you and the team for the work on this, I'm really keen on using Zig for this use case in particular. And again sorry for hijacking this issue!

    ~% uname -a
    Darwin m1.local 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:41 PDT 2021; root:xnu-7195.101.2~1/RELEASE_ARM64_T8101 arm64
    ~% zig version
    0.8.0-dev.2305+d228d8605
    ~% cat hello.c
    int hello() {
      return 0;
    }
    ~% zig cc hello.c -shared
    error: MissingMainEntrypoint
    
  13. 5 remaining items

  14. kubkon commented on Mar 28, 2023

    @kubkon
    Member

    @alloveras issue extracted into #15103. Thanks for filing it!

  15. alloveras commented on Mar 28, 2023

    @alloveras

    @alloveras issue extracted into #15103. Thanks for filing it!

    Thanks to you for the super fast response and for extracting it into a separate issue 🙇

  16. p7r0x7 commented on Aug 25, 2025

    @p7r0x7

    No love for this issue?

  17. andrewrk commented on Aug 25, 2025

    @andrewrk
    Member

    This is not planned.

  18. removed
    bug
    on Aug 25, 2025
  19. modified the milestones: upcoming, 0.16.0 on Mar 17, 2026
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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions