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] unistd.h doesn't appear to reflect the targeted glibc version #22765

Closed
chouquette opened this issue Feb 5, 2025 · 2 comments
Closed
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. zig cc Zig as a drop-in C compiler feature
Milestone

Comments

@chouquette
Copy link
Contributor

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

Hello!
I'm trying to compile utils-linux with zig cc while targeting glibc 2.17.
From what I can see, the glibc library itself is correctly missing symbols added in later versions, however unistd.h does include the prototypes for such functions.
In this case, close_range which was added in 2.34

This leads to compile error as utils-linux attempts to provide a compat function:

In file included from ../disk-utils/fsck.c:59:
../include/fileutils.h:90:19: error: static declaration of 'close_range' follows non-static declaration
   90 | static inline int close_range(unsigned int first, unsigned int last, int flags)
      |                   ^
/snap/zig/11625/lib/libc/include/generic-glibc/unistd.h:1211:12: note: previous declaration is here
 1211 | extern int close_range (unsigned int __fd, unsigned int __max_fd,
      |            ^

The setup can easily be reproduced with git clone --depth=1 https://github.com/util-linux/util-linux.git && cd util-linux && mkdir build-zig && ./autogen.sh && cd build-zig && CC='zig cc --target=x86_64-linux-gnu.2.17' ../configure && make

Expected Behavior

unistd.h doesn't include declaration for functions unavailable in the targeted glibc version

@chouquette chouquette added the bug Observed behavior contradicts documented or intended behavior label Feb 5, 2025
@alexrp
Copy link
Member

alexrp commented Feb 5, 2025

We unfortunately don't have a good solution for versioning headers at the moment. The current approach is to manually patch them with appropriate checks, e.g. b7a98d0.

@alexrp alexrp added this to the unplanned milestone Feb 5, 2025
@alexrp alexrp added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. zig cc Zig as a drop-in C compiler feature labels Feb 5, 2025
@chouquette
Copy link
Contributor Author

Alright, that seems fair :)

I opened #22771 which solves my use case for now!

Thanks for your very quick response 🙏

@alexrp alexrp modified the milestones: unplanned, 0.14.0 Feb 8, 2025
@alexrp alexrp closed this as completed Feb 8, 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 contributor friendly This issue is limited in scope and/or knowledge of Zig internals. zig cc Zig as a drop-in C compiler feature
Projects
None yet
Development

No branches or pull requests

2 participants