mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
mingw libc: solve the segfault having to do with destructors
* fixed --verbose-cc printing an extra "zig" before the rest of the command line * windows-gnu targets use libfoo.a, foo.o extensions to match mingw conventions.
This commit is contained in:
parent
d9c4c96bf2
commit
7b8ba871a9
@ -2,7 +2,7 @@
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Whether the linker provides __CTOR_LIST__ */
|
||||
/* #undef HAVE_CTOR_LIST */
|
||||
#define HAVE_CTOR_LIST 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
@ -8741,10 +8741,10 @@ static void gen_root_source(CodeGen *g) {
|
||||
|
||||
}
|
||||
|
||||
static void print_zig_cc_cmd(const char *zig_exe, ZigList<const char *> *args) {
|
||||
fprintf(stderr, "%s", zig_exe);
|
||||
static void print_zig_cc_cmd(ZigList<const char *> *args) {
|
||||
for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) {
|
||||
fprintf(stderr, " %s", args->at(arg_i));
|
||||
const char *space_str = (arg_i == 0) ? "" : " ";
|
||||
fprintf(stderr, "%s%s", space_str, args->at(arg_i));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@ -8882,12 +8882,12 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
|
||||
}
|
||||
|
||||
if (g->verbose_cc) {
|
||||
print_zig_cc_cmd("zig", &args);
|
||||
print_zig_cc_cmd(&args);
|
||||
}
|
||||
os_spawn_process(args, &term);
|
||||
if (term.how != TerminationIdClean || term.code != 0) {
|
||||
fprintf(stderr, "\nThe following command failed:\n");
|
||||
print_zig_cc_cmd(buf_ptr(self_exe_path), &args);
|
||||
print_zig_cc_cmd(&args);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
20
src/link.cpp
20
src/link.cpp
@ -646,6 +646,8 @@ static const char *build_libunwind(CodeGen *parent) {
|
||||
}
|
||||
|
||||
static void mingw_add_cc_args(CodeGen *parent, CFile *c_file) {
|
||||
c_file->args.append("-DHAVE_CONFIG_H");
|
||||
|
||||
c_file->args.append("-I");
|
||||
c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "include",
|
||||
buf_ptr(parent->zig_lib_dir))));
|
||||
@ -1158,7 +1160,7 @@ static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char *
|
||||
|
||||
static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
|
||||
if (parent->libc == nullptr && parent->zig_target->os == OsWindows) {
|
||||
if (strcmp(file, "crt2.obj") == 0) {
|
||||
if (strcmp(file, "crt2.o") == 0) {
|
||||
CFile *c_file = allocate<CFile>(1);
|
||||
c_file->source_path = buf_ptr(buf_sprintf(
|
||||
"%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtexe.c", buf_ptr(parent->zig_lib_dir)));
|
||||
@ -1170,7 +1172,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
|
||||
//c_file->args.append("-D_UNICODE");
|
||||
//c_file->args.append("-DWPRFLAG=1");
|
||||
return build_libc_object(parent, "crt2", c_file);
|
||||
} else if (strcmp(file, "dllcrt2.obj") == 0) {
|
||||
} else if (strcmp(file, "dllcrt2.o") == 0) {
|
||||
CFile *c_file = allocate<CFile>(1);
|
||||
c_file->source_path = buf_ptr(buf_sprintf(
|
||||
"%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtdll.c", buf_ptr(parent->zig_lib_dir)));
|
||||
@ -1916,10 +1918,10 @@ static const char *get_libc_static_file(ZigLibCInstallation *lib, const char *fi
|
||||
return buf_ptr(out_buf);
|
||||
}
|
||||
|
||||
static void print_zig_cc_cmd(const char *zig_exe, ZigList<const char *> *args) {
|
||||
fprintf(stderr, "%s", zig_exe);
|
||||
static void print_zig_cc_cmd(ZigList<const char *> *args) {
|
||||
for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) {
|
||||
fprintf(stderr, " %s", args->at(arg_i));
|
||||
const char *space_str = (arg_i == 0) ? "" : " ";
|
||||
fprintf(stderr, "%s%s", space_str, args->at(arg_i));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@ -2017,13 +2019,13 @@ static const char *get_def_lib(CodeGen *parent, const char *name, const char *de
|
||||
args.append(buf_ptr(def_final_path));
|
||||
|
||||
if (parent->verbose_cc) {
|
||||
print_zig_cc_cmd("zig", &args);
|
||||
print_zig_cc_cmd(&args);
|
||||
}
|
||||
Termination term;
|
||||
os_spawn_process(args, &term);
|
||||
if (term.how != TerminationIdClean || term.code != 0) {
|
||||
fprintf(stderr, "\nThe following command failed:\n");
|
||||
print_zig_cc_cmd(buf_ptr(self_exe_path), &args);
|
||||
print_zig_cc_cmd(&args);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -2070,9 +2072,9 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) {
|
||||
|
||||
if (g->libc == nullptr) {
|
||||
if (is_dll) {
|
||||
lj->args.append(get_libc_crt_file(g, "dllcrt2.obj"));
|
||||
lj->args.append(get_libc_crt_file(g, "dllcrt2.o"));
|
||||
} else {
|
||||
lj->args.append(get_libc_crt_file(g, "crt2.obj"));
|
||||
lj->args.append(get_libc_crt_file(g, "crt2.o"));
|
||||
}
|
||||
|
||||
lj->args.append(get_libc_crt_file(g, "mingw32.lib"));
|
||||
|
||||
@ -993,7 +993,9 @@ bool target_allows_addr_zero(const ZigTarget *target) {
|
||||
}
|
||||
|
||||
const char *target_o_file_ext(const ZigTarget *target) {
|
||||
if (target->abi == ZigLLVM_MSVC || target->os == OsWindows || target->os == OsUefi) {
|
||||
if (target->abi == ZigLLVM_MSVC ||
|
||||
(target->os == OsWindows && !target_abi_is_gnu(target->abi)) ||
|
||||
target->os == OsUefi) {
|
||||
return ".obj";
|
||||
} else {
|
||||
return ".o";
|
||||
@ -1021,7 +1023,10 @@ const char *target_exe_file_ext(const ZigTarget *target) {
|
||||
}
|
||||
|
||||
const char *target_lib_file_prefix(const ZigTarget *target) {
|
||||
if (target->os == OsWindows || target->os == OsUefi || target_is_wasm(target)) {
|
||||
if ((target->os == OsWindows && !target_abi_is_gnu(target->abi)) ||
|
||||
target->os == OsUefi ||
|
||||
target_is_wasm(target))
|
||||
{
|
||||
return "";
|
||||
} else {
|
||||
return "lib";
|
||||
@ -1036,7 +1041,11 @@ const char *target_lib_file_ext(const ZigTarget *target, bool is_static,
|
||||
}
|
||||
if (target->os == OsWindows || target->os == OsUefi) {
|
||||
if (is_static) {
|
||||
return ".lib";
|
||||
if (target->os == OsWindows && target_abi_is_gnu(target->abi)) {
|
||||
return ".a";
|
||||
} else {
|
||||
return ".lib";
|
||||
}
|
||||
} else {
|
||||
return ".dll";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user