Skip to content

Bootstrapping from bootstrap.c, issues compiling zig2.c with tcc and slimcc #22114

@fuhsnn

Description

@fuhsnn

These are encountered at the $CC -o zig2 zig2.c compiler_rt.c -std=c99 ... step, with shell command ulimit -s unlimited to workaround stack-overflow mentioned at issue #22111

Here in stage1/zig.h, cpuid.h is included on any x86-64 compiler that is not MSVC. This header may not be present if the C compiler implemented their own preprocessor, tcc, slimcc as well as pcc, cparser, currently don't provide it.

zig/stage1/zig.h

Lines 11 to 17 in aa7d138

#if _MSC_VER
#include <intrin.h>
#elif defined(__i386__) || defined(__x86_64__)
#include <cpuid.h>
#endif

With #include <cpuid.h> commented out (to see what lies ahead), tcc and slimcc failed at, respectively:

The zig_import macro use the non-standard __asm convention for function aliasing on any compiler not MSVC. slimcc stopped here, as its maintainer I will implement it ASAP.

zig/stage1/zig.h

Lines 224 to 234 in aa7d138

#if _MSC_VER
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\
__pragma(comment(linker, "/alternatename:" zig_mangle_c(#fn_name) "=" zig_mangle_c(#libc_name)));
#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, sig_args, call_args)
#else /* _MSC_VER */
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(zig_mangle_c(#libc_name));
#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type libc_name sig_args; \
static inline Type fn_name sig_args { return libc_name call_args; }
#endif

tcc stopped at this point,

zig/stage1/zig.h

Lines 1250 to 1252 in aa7d138

typedef struct { zig_align(16) uint64_t hi; uint64_t lo; } zig_u128;
typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128;
#endif

since it does not advertise __has_attribute((aligned)) and the build driver passes -std=c99, zig_align expands to zig_align_unavailable as the result of these two macro, failing the compilation.

zig/stage1/zig.h

Lines 132 to 146 in aa7d138

#if zig_has_attribute(aligned)
#define zig_under_align(alignment) __attribute__((aligned(alignment)))
#elif _MSC_VER
#define zig_under_align(alignment) __declspec(align(alignment))
#else
#define zig_under_align zig_align_unavailable
#endif
#if __STDC_VERSION__ >= 201112L
#define zig_align(alignment) _Alignas(alignment)
#else
#define zig_align(alignment) zig_under_align(alignment)
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions