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/cache_hash.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/cache_hash.cpp') diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp index 2a0810eced..66e8a94153 100644 --- a/src/cache_hash.cpp +++ b/src/cache_hash.cpp @@ -470,9 +470,6 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) { Error err; Buf *contents = buf_alloc(); if ((err = os_fetch_file_path(dep_file_path, contents))) { - if (verbose) { - fprintf(stderr, "unable to read .d file: %s\n", err_str(err)); - } return ErrorReadingDepFile; } SplitIterator it = memSplit(buf_to_slice(contents), str("\r\n")); -- cgit v1.2.3 From 7330a6102f7a8108ee364b9de79efe4a70049167 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 13 May 2019 12:15:55 -0400 Subject: cache_add_dep_file: handle ErrorFileNotFound specially --- src/cache_hash.cpp | 5 +++++ src/codegen.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/cache_hash.cpp') diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp index 66e8a94153..cd0cc5324d 100644 --- a/src/cache_hash.cpp +++ b/src/cache_hash.cpp @@ -470,6 +470,11 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) { Error err; Buf *contents = buf_alloc(); if ((err = os_fetch_file_path(dep_file_path, contents))) { + if (err == ErrorFileNotFound) + return err; + if (verbose) { + fprintf(stderr, "unable to read .d file: %s\n", err_str(err)); + } return ErrorReadingDepFile; } SplitIterator it = memSplit(buf_to_slice(contents), str("\r\n")); diff --git a/src/codegen.cpp b/src/codegen.cpp index feb3cae95a..4529abcc83 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8732,12 +8732,14 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) { // Don't treat the absence of the .d file as a fatal error, the // compiler may not produce one eg. when compiling .s files - if (err != ErrorReadingDepFile) { + if (err != ErrorFileNotFound) { fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err)); exit(1); } } - os_delete_file(out_dep_path); + if (err != ErrorFileNotFound) { + os_delete_file(out_dep_path); + } if ((err = cache_final(cache_hash, &digest))) { fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err)); -- cgit v1.2.3