From a038ef3570caed01815173d95089e016fab3a050 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 11 May 2019 21:06:31 +0200 Subject: Assemble asm files using CC Stuffing all the files together and compiling the resulting blob with the main program is a terrible idea. Some files, namely the .S ones, must be run trough the C preprocessor before assembling them (#2437). Beside that the aggregate may be mis-compiled due to the presence of some flags that affect the following code. For example let's consider two files, a.s and b.s a.s ``` fn1: ret .data data1: .word 0 ``` b.s ``` fn2: ret ``` Now, fn1 and fn2 will be both placed in the .text section as intended if the two files are compiled separately. But if we merge them the `.data` flag ends up placing fn2 in the wrong section! This fixes a nasty crash where musl's memset ended up in the non-executable data segment, leading to too many hours of head-scratching. --- src/main.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 5659624cb7..934c998435 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,7 +48,6 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) { " zen print zen of zig and exit\n" "\n" "Compile Options:\n" - " --assembly [source] add assembly file to build\n" " --c-source [options] [file] compile C source code\n" " --cache-dir [path] override the local cache directory\n" " --cache [auto|off|on] build in cache, print output path to stdout\n" @@ -428,7 +427,6 @@ int main(int argc, char **argv) { bool each_lib_rpath = false; ZigList objects = {0}; ZigList c_source_files = {0}; - ZigList asm_files = {0}; const char *test_filter = nullptr; const char *test_name_prefix = nullptr; size_t ver_major = 0; @@ -774,8 +772,6 @@ int main(int argc, char **argv) { break; } } - } else if (strcmp(arg, "--assembly") == 0) { - asm_files.append(argv[i]); } else if (strcmp(arg, "--cache-dir") == 0) { cache_dir = argv[i]; } else if (strcmp(arg, "-target") == 0) { @@ -971,14 +967,13 @@ int main(int argc, char **argv) { case CmdTranslateCUserland: case CmdTest: { - if (cmd == CmdBuild && !in_file && objects.length == 0 && asm_files.length == 0 && + if (cmd == CmdBuild && !in_file && objects.length == 0 && c_source_files.length == 0) { fprintf(stderr, "Expected at least one of these things:\n" " * Zig root source file argument\n" " * --object argument\n" - " * --assembly argument\n" " * --c-source argument\n"); return print_error_usage(arg0); } else if ((cmd == CmdTranslateC || cmd == CmdTranslateCUserland || @@ -1130,9 +1125,6 @@ int main(int argc, char **argv) { for (size_t i = 0; i < objects.length; i += 1) { codegen_add_object(g, buf_create_from_str(objects.at(i))); } - for (size_t i = 0; i < asm_files.length; i += 1) { - codegen_add_assembly(g, buf_create_from_str(asm_files.at(i))); - } } -- cgit v1.2.3