ack icon indicating copy to clipboard operation
ack copied to clipboard

mcg crash, also bug with a > b

Open kernigh opened this issue 8 years ago • 1 comments

I played with mcg in 559233e. I changed plat/linuxppc/descr from ncg to mcg, then rebuilt the ack. (I'm running OpenBSD 6.0 for amd64.) It crashed, as mcg "got signal 11" (SIGSEGV) when compiling something in libcc.ansi. When I looked at the core dump, I found that data_block() in mach/proto/mcg/data.c had taken data pointing to memory shorter than size. I made this change:

diff --git a/mach/proto/mcg/parse_em.c b/mach/proto/mcg/parse_em.c
index b66b177..91d90b6 100644
--- a/mach/proto/mcg/parse_em.c
+++ b/mach/proto/mcg/parse_em.c
@@ -237,8 +237,12 @@ static void parse_pseu(void)
                 }
 
 				case str_ptyp:
-                    data_block(strdup(em.em_string), em.em_size, ro);
+                {
+                    void* buf = malloc(em.em_size);
+                    memcpy(buf, em.em_string, em.em_size);
+                    data_block(buf, em.em_size, ro);
 					break;
+                }
 
                 case cst_ptyp:
                     data_int(em.em_cst, EM_wordsize, ro);

I guess that the buffer from strdup() was shorter than em.em_size bytes, so I changed it to malloc() and memcpy(). After this change, mcg didn't crash.

Then I ran my tests from https://bitbucket.org/kernigh/ack-ptest with mcg compiling for linuxppc. Some tests failed. I want to report these 3 failures from logic.c:

not ok 6 - six > twelve (2nd)
not ok 18 - negnine > six (2nd)
not ok 42 - !(six < twelve) (2nd)

These failed to be false. Seems that if (a > b) works, but passing a > b to a function is broken. I want to have comparisons that work, so we can use them in other tests. It might be time to copy and adapt my logic.c (or something like it) to the tests in plat/tests.

kernigh avatar Jan 27 '17 04:01 kernigh

Hmm; thanks. I bet that first is due to a zero byte in the string. Will fix.

Regarding the second --- the condition-to-integer rules for the PowerPC is a mess. I fixed a bunch of mistakes when doing the B port, but there's obviously some more. Your new extended operands will make that easier because now I won't have to have to use rlwinm instructions everywhere.

Right now I'm working on a new mcg register allocator, with slow but encouraging results, so I'm going to leave this for a bit --- the rules file is going to need a bit of an overhaul.

davidgiven avatar Jan 30 '17 18:01 davidgiven