generating proper filename for "*_stub.o" file

Bulat Ziganshin bulatz at HotPOP.com
Thu Nov 24 16:36:23 EST 2005


Hello glasgow-haskell-bugs,

  GHC contains long-standing bug in generating proper filename for the
"*_stub.o" file. If the corresponding module is already compiled and
we need only to link it - name for this file is determined in
"findLinkable" procedure from the name of main object file for this
module by replacing ".o" with "_stub.o"

But when corresponding module is compiled this algorithm is not used.
Instead, execution goes through "compileStub" routine, which DON'T
RECEIVE INFORMATION ABOUT NAME OF ".o" FILE OF MODULE ITSELF.
Therefore, "genOutputFilenameFunc" called as part of stub file
compilation, builds "*_stub.o" filename from name of "*_stub.c" file,
that CAN'T BE DONE 100% PROPERLY JUST BECAUSE THERE IS NOT ENOUGH
INFORMATION

GHC 6.4.0 works improper when -odir was specified AND module was
imported from subdirectory using hierarchical name ("import
Subdir.Module"). i demonstrate this in attached ghc640bug.zip

GHC 6.4.1 dropped call to replaceFilenameDirectory in
genOutputFilenameFunc, that fixed the previous case, but resulted in
improper work when -odir was specified AND module was
imported from any directory specified by "-i" option. i demonstrate
this in attached ghc641bug.zip

i think that any auto-generated filenames, not only stub object files, may
have this problems - if the execution falls to the line "| Just d <-
odir = d ++ '/':persistent" in genOutputFilenameFunc, then filename,
generated by this line, may differ with filename for the same file,
generated in another program places, when abovementioned conditions
are met


to properly generate "*_stub.o" filenames i propose to do the
following changes (modeled on 6.4.1 sources):

1) replace first call to compileStub with lines:

           let object_filename = ml_obj_file location
           maybe_stub_o <- compileStub dyn_flags' stub_c_exists (stubOFilename object_filename)

2) replace second call to compileStub with line:

                maybe_stub_o <- compileStub dflags' stub_c_exists (stubOFilename o_file)

3) define stubOFilename as:

stubOFilename:: FilePath->FilePath
stubOFilename obj_fn = case splitFilename3 obj_fn of
                         (dir, base, ext) -> dir ++ "/" ++ base ++ "_stub.o"
                
i also highly recommend to use this function in definition of
"findLinkable"

4) add to compileStub using of stub_o_filename:

compileStub dflags stub_c_exists stub_o_filename
  | not stub_c_exists = return Nothing
  | stub_c_exists = do
        -- compile the _stub.c file w/ gcc
        let stub_c = hscStubCOutName dflags
        (_, stub_o) <- runPipeline StopLn "stub-compile" dflags
                            True{-persistent output-} 
                            (Just stub_o_filename)
                            stub_c
                            Nothing{-no ModLocation-}
        return (Just stub_o)


This must make happy both cases i attached

-- 
Best regards,
 Bulat                          mailto:bulatz at HotPOP.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghc640bug.zip
Type: application/x-zip-compressed
Size: 2063 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20051125/0a504cf9/ghc640bug.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghc641bug.zip
Type: application/x-zip-compressed
Size: 2078 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20051125/0a504cf9/ghc641bug.bin


More information about the Glasgow-haskell-bugs mailing list