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

Static libraries include full paths #21496

Open
peppergrayxyz opened this issue Sep 23, 2024 · 0 comments
Open

Static libraries include full paths #21496

peppergrayxyz opened this issue Sep 23, 2024 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@peppergrayxyz
Copy link

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

When building a static library, the full path to the object file is included in the output (This may relate to #18450).

This behavior is present in Debug and Release mode. Especially for Release builds, local path should not be shared with everyone.

Zig library

$ zig init
$ zig build
$ nm -g zig-out/lib/libtest.a

/home/user/repos/test/.zig-cache/o/9e8763c141c04c7df9724acbbf6ab810/libtest.a.o:
0000000000000000 T add
                 w _DYNAMIC
0000000000030240 W getauxval
                 U memcpy
                 U memset
                 U __zig_probe_stack
$ zig build -Doptimize=ReleaseSmall                                                  
$ nm -g zig-out/lib/libtest.a

/home/user/repos/test/.zig-cache/o/9e8763c141c04c7df9724acbbf6ab810/libtest.a.o:
0000000000000000 T add

C library

This is also the case, when building a c-library.

// src/module/add.c
int add(int a, int b) { return a + b; }

// src/module/sub.c
int sub(int a, int b) { return a - b; }

// src/module/lib.c
extern int add(int a, int b);
extern int sub(int a, int b);
int math_add(int a, int b) { return add(a, b); }
int math_sub(int a, int b) { return sub(a, b); }

build.zig

const std = @import("std");

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

    const lib = b.addStaticLibrary(.{
        .name = "math",
        .target = target,
        .optimize = optimize,
        .link_libc = true,
    });
    
    lib.addCSourceFiles(.{ .files = &.{ "src/lib.c", "src/module/add.c", "src/module/sub.c" }, .flags = &.{} });

    b.installArtifact(lib);
}
$ zig build
$ nm -g zig-out/lib/libmath.a

/home/user/repos/test-c/.zig-cache/o/df1ceb68b0cb3b5d5375d6d191b61744/lib.o:
                 U add
0000000000000000 T math_add
0000000000000020 T math_sub
                 U sub

/home/user/repos/test-c/.zig-cache/o/65d3a2b2cb6c15a834c2f7f78aaabe6d/add.o:
0000000000000000 T add

/home/user/repos/test-c/.zig-cache/o/daef4e863ef4545f15791d571b39e315/sub.o:
0000000000000000 T sub
$ zig build -Doptimize=ReleaseSafe
$ nm -g zig-out/lib/libmath.a

/home/user/repos/test-c/.zig-cache/o/f9eb70172b51837f406b61e4e5f0fbce/lib.o:
                 U add
0000000000000000 T math_add
0000000000000010 T math_sub
                 U sub

/home/user/repos/test-c/.zig-cache/o/b6b5b473535e751271e5801ee1030388/add.o:
0000000000000000 T add

/home/user/repos/test-c/.zig-cache/o/e2c1f520300946aa4150d54bb69471bd/sub.o:
0000000000000000 T sub

Expected Behavior

Only object file names and relative paths (i.a.) are present:

Zig library

$ zig init
$ zig build
$ nm -g zig-out/lib/libtest.a

libtest.a.o:
0000000000000000 T add
                 w _DYNAMIC
0000000000030240 W getauxval
                 U memcpy
                 U memset
                 U __zig_probe_stack
$ zig build -Doptimize=ReleaseSmall                                                  
$ nm -g zig-out/lib/libtest.a

libtest.a.o:
0000000000000000 T add

C library

$ zig build
$ nm -g zig-out/lib/libmath.a

lib.o:
                 U add
0000000000000000 T math_add
0000000000000020 T math_sub
                 U sub

module/add.o:
0000000000000000 T add

module/sub.o:
0000000000000000 T sub
$ zig build -Doptimize=ReleaseSafe
$ nm -g zig-out/lib/libmath.a

lib.o:
                 U add
0000000000000000 T math_add
0000000000000010 T math_sub
                 U sub

module/add.o:
0000000000000000 T add

module/sub.o:
0000000000000000 T sub

@peppergrayxyz peppergrayxyz added the bug Observed behavior contradicts documented or intended behavior label Sep 23, 2024
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

1 participant