chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] Re: csc -Ob (-O5) bug


From: Derrell Piper
Subject: [Chicken-hackers] Re: csc -Ob (-O5) bug
Date: Sat, 26 Dec 2009 11:02:31 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (darwin)

Derrell Piper <address@hidden> writes:

Here's a fix.  I'll attach this to the Trac ticket (#150) as well.

fluffy547% csc -v hello.scm
/usr/local/bin/chicken hello.scm -output-file hello.c
gcc hello.c -o hello.o -c -no-cpp-precomp -fno-strict-aliasing -fno-common 
-DHAVE_CHICKEN_CONFIG_H -m64 -DC_ENABLE_PTABLES -Os -fomit-frame-pointer 
-I/usr/local/include
rm hello.c
gcc hello.o -o hello -m64 -L/usr/local/lib -lchicken -lm
install_name_tool -change libchicken.dylib /usr/local/lib/libchicken.dylib hello
rm hello.o
fluffy548% ./hello
Hello, World!
fluffy549% csc -v -O5 hello.scm
/usr/local/bin/chicken hello.scm -output-file hello.c -unsafe-libraries 
-optimize-level 5
gcc hello.c -o hello.o -c -no-cpp-precomp -fno-strict-aliasing -fno-common 
-DHAVE_CHICKEN_CONFIG_H -m64 -DC_ENABLE_PTABLES -Os -fomit-frame-pointer -O3 
-fomit-frame-pointer -I/usr/local/include
rm hello.c
gcc hello.o -o hello -m64 -L/usr/local/lib -luchicken -lm
install_name_tool -change libuchicken.dylib /usr/local/lib/libuchicken.dylib 
hello
rm hello.o
fluffy550% ./hello
Hello, World!

Derrell

diff --git a/csc.scm b/csc.scm
index 4f3afe5..c2e899e 100644
--- a/csc.scm
+++ b/csc.scm
@@ -199,6 +199,7 @@
 (define default-shared-library-files (if msvc
                                          (list (string-append "libchicken." 
library-extension))
                                          '("-lchicken")))
+(define unsafe-libraries #f)
 (define unsafe-library-files
   (list
    (quotewrap 
@@ -639,6 +640,7 @@ EOF
               [(|-O5|)
                (set! rest (cons* "-optimize-level" "5" rest))
                (t-options "-unsafe-libraries")
+               (set! unsafe-libraries #t)
                (set! library-files unsafe-library-files)
                (set! shared-library-files unsafe-shared-library-files)
                (when (memq (build-platform) '(mingw32 cygwin gnu))
@@ -685,6 +687,7 @@ EOF
                (set! rest (cdr rest)) ]
               [(-unsafe-libraries)
                (t-options arg)
+               (set! unsafe-libraries #t)
                (set! library-files unsafe-library-files)
                (set! shared-library-files unsafe-shared-library-files) ]
               [(-rpath)
@@ -699,6 +702,7 @@ EOF
               [else
                (when (memq s '(-unsafe -benchmark-mode))
                  (when (eq? s '-benchmark-mode)
+                       (set! unsafe-libraries #t)
                    (set! library-files unsafe-library-files)
                    (set! shared-library-files unsafe-shared-library-files) ) )
                (when (eq? s '-to-stdout) 
@@ -845,14 +849,14 @@ EOF
     (when (and osx (or (not cross-chicken) host-mode))
       (unless (zero? ($system 
                      (string-append
-                      "install_name_tool -change libchicken.dylib "
+                      "install_name_tool -change lib" (if unsafe-libraries "u" 
"") "chicken.dylib "
                       (quotewrap 
                        (make-pathname
                         (prefix "" "lib"
                                 (if host-mode
                                     INSTALL_LIB_HOME
                                     TARGET_RUN_LIB_HOME))
-                        "libchicken.dylib") )
+                        (if unsafe-libraries "libuchicken.dylib" 
"libchicken.dylib")) )
                       " " 
                       target) ) )
        (exit last-exit-code) ) )

> There's a bug with the unsafe processing in csc.  When it's compiling unsafe, 
> it doesn't reflect this out to the 'install_name_tool' invocation, resulting 
> in no fixup in the resulting image.  So if libuchicken.dylib doesn't happen 
> to be in the standard library search path, it blows up at runtime:
>
> fluffy659% csc -O5 -verbose hello.scm
> /usr/local/chicken/bin/chicken hello.scm -output-file hello.c 
> -unsafe-libraries -optimize-level 5 -verbose
> Loading compiler extensions...
> debugging info: none
> loading identifier database /usr/local/chicken/lib/chicken/4/modules.db ...
> compiling `hello.scm' ...
> pass: source
> pass: canonicalized
> pass: initial node tree
> pass: analysis
> pass: lambda lifted
> pass: cps
> pass: analysis
> pass: optimized-iteration
> pass: analysis
> pass: optimized-iteration
> pass: analysis
> pass: optimized-iteration
> pass: analysis
> pass: optimized
> pass: final-analysis
> pass: closure-converted
> generating `hello.c' ...
> compilation finished.
> gcc hello.c -o hello.o -c -no-cpp-precomp -fno-strict-aliasing -fno-common 
> -DHAVE_CHICKEN_CONFIG_H -m64 -DC_ENABLE_PTABLES -Os -fomit-frame-pointer -O3 
> -fomit-frame-pointer -I/usr/local/chicken/include
> rm hello.c
> gcc hello.o -o hello -m64 -L/usr/local/chicken/lib -luchicken -lm
> install_name_tool -change libchicken.dylib 
> /usr/local/chicken/lib/libchicken.dylib hello
> rm hello.o
> fluffy660% otool -L hello
> hello:
>       libuchicken.dylib (compatibility version 1.0.0, current version 1.0.0)
>       /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current 
> version 125.0.0)
> fluffy661% ./hello
> dyld: Library not loaded: libuchicken.dylib
>   Referenced from: /Users/ddp/src/scm/./hello
>   Reason: image not found
> Trace/BPT trap
> fluffy662% install_name_tool -change libuchicken.dylib 
> /usr/local/chicken/lib/libuchicken.dylib hello
> fluffy663% ./hello
> Hello, World!





reply via email to

[Prev in Thread] Current Thread [Next in Thread]