#3333: GHCi doesn't load weak symbols
--------------------------------------+-------------------------------------
    Reporter:  heatsink               |        Owner:  hgolden     
        Type:  bug                    |       Status:  assigned    
    Priority:  normal                 |    Milestone:  6.14.1      
   Component:  GHCi                   |      Version:  6.10.4      
    Keywords:  weak, dynamic loading  |   Difficulty:  Unknown     
          Os:  Linux                  |     Testcase:              
Architecture:  x86                    |      Failure:  None/Unknown
--------------------------------------+-------------------------------------

Comment(by heatsink):

 Replying to [comment:8 hgolden]:

 > OK. Then I think the following approach would work:
 >
 > 1. Add local, global and the first occurrence of a weak symbol to the
 symbol table (if the global symbol doesn't exist already). It is allowable
 to have all 3 types of a single name in the symbol table.
 >
 > 2. When a local symbol is called for, return that. When a global symbol
 is called for, return the global symbol if it exists. If a global symbol
 doesn't exist, return a weak symbol if it exists.

 There are three cases when a global symbol is called for.
  1. If the global symbol is defined, return it.
  2. Otherwise, if a weak symbol is defined in the table, return it.
  3. Otherwise, if a weak symbol is in the table and marked "undefined",
 return NULL.
  4. Otherwise, report an error because the symbol is undefined.

 Weak undefined symbols can satisfy a need for a symbol, in contrast to
 global undefined symbols which cannot.  Weak undefined symbols are
 sometimes used in the C/C++ domain as a way of allowing optional hooks or
 callbacks.

 > I believe this can be implemented in the rts/Linker.c in a
 straightforward way. I will start working on this. If you disagree with my
 analysis of the semantics, please let me know what you want instead.

 There is one complication due to incremental linking.  We could have a
 situation where a symbol's value changes as a result of module imports:

  * load A.o which uses X (global undefined) [[BR]] and B.o which defines X
 = 1 (weak defined)
  * call a function in A, which reveals that X has the value 1
  * load C.o which defines X = 2 (global defined) [[BR]] and D.o which uses
 X (global undefined) [[BR]] Although X had the value 1 before, the global
 definition takes precedence over the weak definition so it now has the
 value 2
  * call a function in D, which reveals that X has the value 2
  * call a function in A, which reveals that X has the value 1
 (inconsistent) or 2 (not referentially transparent)

 I think that to avoid problems, it has to be detected whenever loading new
 modules would change a symbol's value.  GHCi already detects redefined
 global symbols, so hopefully you can reuse that.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3333#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to