Skip to content

compiler: update aro and translate-c to latest; delete clang translate-c #24497

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Jul 18, 2025

This deletes our implementation of translate-c which is based on libclang and replaces it with one based on arocc and translate-c.

Goodbye, and good riddance, to 5,940 lines of our remaining C++ code in the source repository, with 3,763 remaining.

Progress towards #20630. In the future, Zig will drop the @cImport language builtin, but for now, it remains, backed by Aro instead of Clang.

Progress towards #16270

Upgrade Guide

This is technically a non-breaking change. While breakage is likely due to one C compiler being swapped out for another, if it occurs it is a bug rather than a feature.

So, cross your fingers when you upgrade and report a bug if something breaks.

Merge Checklist

  • get the standalone executable working
  • integrate with frontend using jitCmd, properly passing Compilation state (mainly include dirs and target information)

@andrewrk andrewrk added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. and removed breaking Implementing this issue could cause existing code to no longer compile or have different behavior. labels Jul 18, 2025
@andrewrk
Copy link
Member Author

When trying to communicate CLI options to the translate-c executable these are not yet handled:

  • target cpu features
  • -x c
  • warning: unknown argument '--no-default-config'
  • warning: unknown argument '-gdwarf-4'
  • warning: unknown argument '-gdwarf32'
  • warning: unknown argument '-fno-lto'
  • warning: unknown argument '-MD'
  • warning: unknown argument '-MV'
  • warning: unknown argument '-MF'
  • warning: unknown argument '-mred-zone'
  • warning: unknown argument '-fno-omit-frame-pointer'
  • warning: unknown argument '-fno-stack-protector'
  • warning: unknown argument '-fbuiltin'
  • warning: unknown argument '-fno-function-sections'
  • warning: unknown argument '-fno-data-sections'
  • warning: unknown argument '-fasynchronous-unwind-tables'
  • warning: unknown argument '-fno-spell-checking'
  • warning: unknown argument '-fsanitize=undefined'
  • warning: unknown argument '-fno-sanitize=vptr'
  • warning: unknown argument '-fno-sanitize=function'
  • warning: unknown argument '-Xclang -detailed-preprocessing-record'
  • error: invalid target 'x86_64-unknown-linux6.15.1-gnu2.39.0'

manually reduced command:

./translate_c -target x86_64-linux-gnu -fno-PIE -fno-PIC -fhosted -nostdinc -D__GLIBC_MINOR__=39 -isystem /home/andy/dev/zig/lib/include -isystem /nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include -O0 hello.c

fails:

/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/features.h:503:9: warning: '__GLIBC_MINOR__' macro redefined [-Wmacro-redefined]
#define __GLIBC_MINOR__ 40
        ^
<command line>:2:9: note: previous definition is here
#define __GLIBC_MINOR__ 39
        ^
/home/andy/dev/zig/lib/include/__stddef_size_t.h:15:33: error: function-like macro '__building_module' is not defined
    (__has_feature(modules) && !__building_module(_Builtin_stddef))
                                ^
/home/andy/dev/zig/lib/include/__stddef_null.h:10:24: error: function-like macro '__building_module' is not defined
#if !defined(NULL) || !__building_module(_Builtin_stddef)
                       ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:28:43: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
                                          size_t __nbytes);
                                          ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:28:50: error: expected ')', found 'an identifier'
                                          size_t __nbytes);
                                                 ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:27:42: note: to match this '('
typedef __ssize_t cookie_read_function_t (void *__cookie, char *__buf,
                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:28:50: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
                                          size_t __nbytes);
                                                 ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:28:58: error: expected ';', found ')'
                                          size_t __nbytes);
                                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:37:44: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
                                           size_t __nbytes);
                                           ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:37:51: error: expected ')', found 'an identifier'
                                           size_t __nbytes);
                                                  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:36:43: note: to match this '('
typedef __ssize_t cookie_write_function_t (void *__cookie, const char *__buf,
                                          ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:37:51: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
                                           size_t __nbytes);
                                                  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:37:59: error: expected ';', found ')'
                                           size_t __nbytes);
                                                          ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:57:3: error: unknown type name 'cookie_read_function_t'
  cookie_read_function_t *read;         /* Read bytes.  */
  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:58:3: error: unknown type name 'cookie_write_function_t'
  cookie_write_function_t *write;       /* Write bytes.  */
  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:184:36: warning: unknown attribute '__nonnull__' ignored [-Wunknown-attributes]
extern int fclose (FILE *__stream) __nonnull ((1));
                                   ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/sys/cdefs.h:561:28: note: expanded from here
# define __nonnull(params) __attribute_nonnull__ (params)
                           ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/sys/cdefs.h:555:57: note: expanded from here
#  define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
                                                        ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:273:42: warning: unknown attribute '__nonnull__' ignored [-Wunknown-attributes]
                      FILE *__restrict __stream) __wur __nonnull ((3));
                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/sys/cdefs.h:561:28: note: expanded from here
# define __nonnull(params) __attribute_nonnull__ (params)
                           ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/sys/cdefs.h:555:57: note: expanded from here
#  define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
                                                        ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:35: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:42: error: expected ')', found 'an identifier'
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:23: note: to match this '('
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                      ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:42: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:49: error: expected identifier or '('
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                                ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:68: error: expected ';', found ')'
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                                                   ^

(truncated)

@andrewrk
Copy link
Member Author

aha, aro does not support clang's C runtime includes, which makes sense.

andy@bark ~/d/z/build-release (aro-translate-c)> ./translate_c -target x86_64-linux-gnu -fno-PIE -fno-PIC -fhosted -nostdinc -D__GLIBC_MINOR__=39 -isystem /home/andy/src/arocc/include -isystem /nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include -O0 hello.c > hello.zig 2>stderr.txt
andy@bark ~/d/z/build-release (aro-translate-c)> stage3/bin/zig run hello.zig -lc
hello world

stderr.txt contains:

/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/features.h:503:9: warning: '__GLIBC_MINOR__' macro redefined [-Wmacro-redefined]
#define	__GLIBC_MINOR__	40
        ^
<command line>:2:9: note: previous definition is here
#define __GLIBC_MINOR__ 39
        ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:184:36: warning: unknown attribute '__nonnull__' ignored [-Wunknown-attributes]
extern int fclose (FILE *__stream) __nonnull ((1));
                                   ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes This PR should be mentioned in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants