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

zig cc not creating libresolv stubs #12628

Closed
motiejus opened this issue Aug 25, 2022 · 0 comments · Fixed by #12629
Closed

zig cc not creating libresolv stubs #12628

motiejus opened this issue Aug 25, 2022 · 0 comments · Fixed by #12629
Labels
bug Observed behavior contradicts documented or intended behavior os-linux
Milestone

Comments

@motiejus
Copy link
Contributor

motiejus commented Aug 25, 2022

Zig Version

0.10.0-dev.3672+cd5a9ba1f

Steps to Reproduce

testresolv.c

#include <stdio.h>
#include <resolv.h>

int main() {
    printf("res_query: %p\n", res_query);
    printf("dn_expand: %p\n", dn_expand);
}

Compile for x86_64-linux-gnu.2.33:

$ ZIG_VERBOSE_LINK=1 zig cc --target=x86_64-linux-gnu.2.33 -lresolv testresolv.c -o testresolv 
LLD Link... ld.lld -error-limit=0 -O0 -z stack-size=16777216 --gc-sections --eh-frame-hdr -znow -m elf_x86_64 -o /home/motiejus/.cache/zig/o/cb35c829f307f454aa748de0e579d29a/testresolv /home/motiejus/.cache/zig/o/479dd8cc8de0fb41dd40abf62f254c4a/Scrt1.o /home/motiejus/.cache/zig/o/e7beca82c5577aea9885d59a7e4096da/crti.o -dynamic-linker /lib64/ld-linux-x86-64.so.2 /home/motiejus/.cache/zig/o/db5fa2707fb80a202fbe609594d23cc2/testresolv.o /home/motiejus/.cache/zig/o/8d7a9daa5963045c0ecc7ac066259b7f/libcompiler_rt.a --as-needed /home/motiejus/.cache/zig/o/1ccb25741ec2e9c844aced091e012f89/libm.so.6 /home/motiejus/.cache/zig/o/1ccb25741ec2e9c844aced091e012f89/libpthread.so.0 /home/motiejus/.cache/zig/o/1ccb25741ec2e9c844aced091e012f89/libc.so.6 /home/motiejus/.cache/zig/o/1ccb25741ec2e9c844aced091e012f89/libdl.so.2 /home/motiejus/.cache/zig/o/1ccb25741ec2e9c844aced091e012f89/librt.so.1 /home/motiejus/.cache/zig/o/1ccb25741ec2e9c844aced091e012f89/libld.so.2 /home/motiejus/.cache/zig/o/1ccb25741ec2e9c844aced091e012f89/libutil.so.1 /home/motiejus/.cache/zig/o/729209225ef10d542a54765aaf478e99/libc_nonshared.a /home/motiejus/.cache/zig/o/9a75a4492a68987917fb40c469decd3b/crtn.o --allow-shlib-undefined
ld.lld: error: undefined symbol: res_query
>>> referenced by testresolv.c:5 (/home/motiejus/x/testresolv.c:5)
>>>               /home/motiejus/.cache/zig/o/db5fa2707fb80a202fbe609594d23cc2/testresolv.o:(main)

ld.lld: error: undefined symbol: dn_expand
>>> referenced by testresolv.c:6 (/home/motiejus/x/testresolv.c:6)
>>>               /home/motiejus/.cache/zig/o/db5fa2707fb80a202fbe609594d23cc2/testresolv.o:(main)

If we use gnu.2.34, when it was moved from libresolv.so to libc.so, it compiles successfully:

$ zig cc --target=x86_64-linux-gnu.2.34 testresolv.c -o testresolv  && ./testresolv
res_query: 0x7fb2b12ffa40
dn_expand: 0x7fb2b12f6810

There are a few issues:

  1. -lresolv is a "libc name", which causes it to be skipped from the linker line.
  2. libresolv.so stub is not built together with the rest of glibc stubs:
ls /home/motiejus/.cache/zig/o/1ccb25741ec2e9c844aced091e012f89/*.so* | xargs -n1 basename
libc.so.6
libdl.so.2
libld.so.2
libm.so.6
libpthread.so.0
librt.so.1
libutil.so.1
@motiejus motiejus added the bug Observed behavior contradicts documented or intended behavior label Aug 25, 2022
motiejus added a commit to motiejus/glibc-abi-tool that referenced this issue Aug 25, 2022
motiejus added a commit to motiejus/zig that referenced this issue Aug 25, 2022
andrewrk pushed a commit to ziglang/glibc-abi-tool that referenced this issue Aug 26, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Aug 26, 2022
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 os-linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants