Skip to content

Zig cross build for powerpc64-linux-gnu failed by not setting _CALL_ELF correctly #23333

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

Closed
congcongkuo opened this issue Mar 23, 2025 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@congcongkuo
Copy link

congcongkuo commented Mar 23, 2025

Zig Version

zig-macos-aarch64-0.14.0

Steps to Reproduce and Observed Behavior

I am trying to upgrade bdwgc's build.zig file to Zig 0.14. I encountered problems when cross build to powerpc64-linux-gnu.

minimal reproducible example:
main.c

#include <stdio.h>

int fun(int a, int b) {
    printf("%d", _CALL_ELF);
}

build.zig

const builtin = @import("builtin");
const std = @import("std");

pub fn build(b: *std.Build) void {
    const optimize = b.standardOptimizeOption(.{});
    const target = b.standardTargetOptions(.{});

    const gc_mod = b.createModule(.{
        .target = target,
        .optimize = optimize,
    });

    const gc = b.addLibrary(.{
        .linkage = .dynamic,
        .name = "gc",
        .root_module = gc_mod,
    });

    gc.addCSourceFiles(.{
        .files = &.{"main.c"},
    });

    gc.linkLibC();

    b.installArtifact(gc);
}

erroe message:

install
└─ install gc
   └─ zig build-lib gc Debug powerpc64-linux-gnu 1 errors
/zig-macos-aarch64-0.14.0/lib//libc/include/powerpc64-linux-gnu/gnu/stubs.h:14:11: error: 'gnu/stubs-64-v2.h' file not found
# include <gnu/stubs-64-v2.h>
          ^~~~~~~~~~~~~~~~~~~~
/Developer/_play/zig/play5/main.c:1:10: note: in file included from /Developer/_play/zig/play5/main.c:1:
#include <stdio.h>
         ^
/zig-macos-aarch64-0.14.0/lib//libc/include/generic-glibc/stdio.h:28:10: note: in file included from /zig-macos-aarch64-0.14.0/lib//libc/include/generic-glibc/stdio.h:28:
#include <bits/libc-header-start.h>
         ^
/zig-macos-aarch64-0.14.0/lib//libc/include/generic-glibc/bits/libc-header-start.h:33:10: note: in file included from /zig-macos-aarch64-0.14.0/lib//libc/include/generic-glibc/bits/libc-header-start.h:33:
#include <features.h>
         ^
/zig-macos-aarch64-0.14.0/lib//libc/include/generic-glibc/features.h:564:10: note: in file included from /zig-macos-aarch64-0.14.0/lib//libc/include/generic-glibc/features.h:564:
#include <gnu/stubs.h>
         ^
error: warning(compilation): failed to delete '/Users/guo/Developer/_play/zig/play5/.zig-cache/tmp/8e9ccc696ed1dc25-main.o.d': FileNotFound

error: the following command failed with 1 compilation errors:
/zig-macos-aarch64-0.14.0/zig build-lib /Developer/_play/zig/play5/main.c -ODebug -target powerpc64-linux-gnu -mcpu baseline -Mroot -lc --cache-dir /Developer/_play/zig/play5/.zig-cache --global-cache-dir /.cache/zig --name gc -dynamic --zig-lib-dir /zig-macos-aarch64-0.14.0/lib/ --listen=-
Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
└─ install gc transitive failure
   └─ zig build-lib gc Debug powerpc64-linux-gnu 1 errors
error: the following build command failed with exit code 1:
/Developer/_play/zig/play5/.zig-cache/o/f7380d759af2e9268205837f85703565/build /zig-macos-aarch64-0.14.0/zig /zig-macos-aarch64-0.14.0/lib /Developer/_play/zig/play5 /Developer/_play/zig/play5/.zig-cache /.cache/zig --seed 0x5be4522d -Zf2f28acb7b0e9878 -Dtarget=powerpc64-linux-gnu

Expected Behavior

According to a stackoverflow post, powerpc64-linux-gnu build should use <gnu/stubs-64-v1.h> as the file content of /zig-macos-aarch64-0.14.0/lib/libc/include/powerpc64-linux-gnu/gnu/stubs.h

#include <bits/wordsize.h>

#if __WORDSIZE == 32
# include <gnu/stubs-32.h>
#endif
#if __WORDSIZE == 64 && _CALL_ELF != 2
# include <gnu/stubs-64-v1.h>
#endif
#if __WORDSIZE == 64 && _CALL_ELF == 2
# include <gnu/stubs-64-v2.h>
#endif

I think _CALL_ELF doesn't be set properly.

@congcongkuo congcongkuo added the bug Observed behavior contradicts documented or intended behavior label Mar 23, 2025
@alexrp
Copy link
Member

alexrp commented Mar 23, 2025

powerpc64-linux-gnu is not currently supported due to #5927. We force ELFv2 because it at least allows powerpc64-linux-none to work for Zig code that doesn't link libc.

@alexrp alexrp closed this as completed Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants