#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 hgolden):
Replying to [comment:9 heatsink]:
> 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.
Here's my approach to that:
1. (Currently) redefining a global symbol is an error (that terminates the
program). This wouldn't change.
2. When a weak symbol is defined and there is no defined global symbol,
save the first defined weak symbol. (In other words, only save the first
weak definition, if at all.)
3. When a weak symbol is "resolved" (actually called for in another
module), it becomes a global symbol. The reason for this is that case 1
should follow if there is any global symbol defined later. This avoids the
problems you have noted above.
4. If the weak symbol hasn't been "upgraded" to a global symbol by case 3,
it will be superseded by a global symbol definition.
This approach is somewhat conservative, since a weak definition that
hasn't been "used" (i.e., called or accessed), as opposed to "resolved,"
could be replaced by a global definition. However, to implement this would
require some method of determining the first use of a symbol. (Perhaps
this could be done, but I don't plan to implement it at present.)
To implement this, only one version of a global/weak symbol needs to be
saved in the defined symbol table. (This revises my earlier statement that
global and weak symbols with the same name would need to co-exist in the
symbol table.)
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3333#comment:10>
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