From 1ec1097bd389b9af1b3e40d9edbc4c1c0b65f6a1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 26 Feb 2019 14:50:20 -0500 Subject: [PATCH] use -nostdinc and sometimes -nolibc when compiling C code --- src/codegen.cpp | 7 +++++++ src/translate_c.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 6e4e66e97..b7230328c 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8151,8 +8151,15 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { } args.append("-nobuiltininc"); + args.append("-nostdinc"); args.append("-nostdinc++"); + if (g->libc_link_lib == nullptr) { + args.append("-nolibc"); + } + + args.append("-fno-spell-checking"); + args.append("-isystem"); args.append(buf_ptr(g->zig_c_headers_dir)); diff --git a/src/translate_c.cpp b/src/translate_c.cpp index 6bd2f7e6d..8525d73f5 100644 --- a/src/translate_c.cpp +++ b/src/translate_c.cpp @@ -4805,7 +4805,11 @@ Error parse_h_file(ImportTableEntry *import, ZigList *errors, const } clang_argv.append("-nobuiltininc"); + clang_argv.append("-nostdinc"); clang_argv.append("-nostdinc++"); + if (codegen->libc_link_lib == nullptr) { + clang_argv.append("-nolibc"); + } clang_argv.append("-isystem"); clang_argv.append(buf_ptr(codegen->zig_c_headers_dir)); @@ -4832,7 +4836,9 @@ Error parse_h_file(ImportTableEntry *import, ZigList *errors, const clang_argv.append("-Xclang"); clang_argv.append("-detailed-preprocessing-record"); - if (!c->codegen->zig_target->is_native) { + if (c->codegen->zig_target->is_native) { + clang_argv.append("-march=native"); + } else { clang_argv.append("-target"); clang_argv.append(buf_ptr(&c->codegen->triple_str)); }