cil-project / cil

C Intermediate Language
Other
348 stars 86 forks source link

CIL throws syntax error for file wget1.14/lib/md5.c during compilation to create the library libgnu.a #36

Open sensorhound-akash opened 6 years ago

sensorhound-akash commented 6 years ago

I am trying to compile Wget-1.14 source code with CIL. I made the default configuration of the Makefile in wget-1.14/lib/Makefile from:

AR = ar
ARFLAGS = cru
CC = gcc
CFLAGS = -g -O2 -Wall -pthread -static

to

AR =  cilly --save-temps=build  --merge --keepmerged --mode=AR
ARFLAGS = r
CC =  cilly --save-temps=build --merge --keepmerged
CFLAGS = -g -O2 -Wall -pthread -static

When the make file is run, to create the library libgnu.a the following command is run as the last step:

cilly --save-temps=build  --merge --keepmerged --mode=AR r libgnu.a base32.o c-ctype.o c-strcasecmp.o c-strncasecmp.o cloexec.o md5.o sha1.o dirname-lgpl.o basename-lgpl.o stripslash.o exitfail.o fatal-signal.o fd-hook.o fd-safer-flag.o dup-safer-flag.o gettime.o localcharset.o glthread/lock.o pipe2.o pipe2-safer.o quotearg.o sockets.o spawn-pipe.o stat-time.o tempname.o glthread/threadlib.o timespec.o tmpdir.o dup-safer.o fd-safer.o pipe-safer.o utimens.o wait-process.o xmalloc.o xalloc-die.o asnprintf.o fcntl.o futimens.o getpass.o ioctl.o printf-args.o printf-parse.o strerror_r.o vasnprintf.o

On running this command, the following error is thrown at line 258 of md5.c:

Library libgnu.a not found; creating. at *******
Turning off warn-is-error flag 
***/cil/obj/x86_LINUX/cilly.asm.exe --extrafiles ___extra_files --mergedout libgnu.a
md5.c[258:0-0] : syntax error
Parsing errorFatal error: exception Frontc.ParseError("Parse error")
Makefile:1383: recipe for target 'libgnu.a' failed
make[2]: *** [libgnu.a] Error 2

The code for md5.c from line 258 is in function md5_process_bytes. Lines 253-273 looks like:

253   /* Process available complete blocks.  */
254   if (len >= 64)
255     {
256 #if !_STRING_ARCH_unaligned
257 # define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0)
258       if (UNALIGNED_P (buffer)){
259         while (len > 64)
260           {
261             md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
262             buffer = (const char *) buffer + 64;
263             len -= 64;
264           }
265         }
266       else
267 #endif
268         {
269           md5_process_block (buffer, len & ~63, ctx);
270           buffer = (const char *) buffer + (len & ~63);
271           len &= 63;
272         }
273     }

I hope if anyone can share your opinions and suggestions on the potential syntactical error that CIL might be encountering.

Thanks in advance.

kerneis commented 6 years ago

257 # define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0) alignof has been introduced in C11. Unfortunately, CIL only supports C99 (and even some parts have not been implemented iirc). Patches are welcome. Otherwise, you may consider switching to FramaC, a similar analysis framework originally forked from CIL and better maintained.