[GHC] #9481: Linker does not correctly resolve symbols in previously loaded objects

#9481: Linker does not correctly resolve symbols in previously loaded objects
-------------------------------------+-------------------------------------
Reporter: edsko | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Keywords: | Operating System:
Architecture: Unknown/Multiple | Unknown/Multiple
Difficulty: Unknown | Type of failure:
Blocked By: | None/Unknown
Related Tickets: | Test Case:
| Blocking:
| Differential Revisions:
-------------------------------------+-------------------------------------
'''Summary''': Given two object files (created from C files) A and B,
where B refers to symbols defined in A, if we load B before A, calling
`resolveObjs` after each object file, symbol resolution goes wrong. Full
test case attached.
'''Detailed description''': Consider
{{{#!c
// a.c
#include

#9481: Linker does not correctly resolve symbols in previously loaded objects -------------------------------------+------------------------------------- Reporter: edsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by rwbarton): I should be able to reproduce by downloading all the attachments and running `make` followed by `Linkerbug` right? In that case it seems to work for me (GHC 7.8.3, Linux x86_64): {{{ rwbarton@morphism:/tmp/linkerbug$ make ghc -c -O a.c ghc -c -O b.c ghc -package ghc Linkerbug [1 of 1] Compiling Main ( Linkerbug.hs, Linkerbug.o ) Linking Linkerbug ... rwbarton@morphism:/tmp/linkerbug$ ./Linkerbug Loading object "b.o" Linkerbug: b.o: unknown symbol `defined_in_A' symbol resolution failed Loading object "a.o" symbol resolution ok Loading Haskell module "Main.hs" ok Running "Main.main" In B In A In B ok }}} I assume you are on OS X? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9481#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9481: Linker does not correctly resolve symbols in previously loaded objects -------------------------------------+------------------------------------- Reporter: edsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by edsko): Yup, I'm on OSX. For me this gives: {{{ # make ghc -c -O a.c ghc -c -O b.c ghc -package ghc Linkerbug [1 of 1] Compiling Main ( Linkerbug.hs, Linkerbug.o ) Linking Linkerbug ... # ./Linkerbug Loading object "b.o" Linkerbug: lookupSymbol failed in relocateSection (relocate external) b.o: unknown symbol `_defined_in_A' symbol resolution failed Loading object "a.o" symbol resolution ok Loading Haskell module "Main.hs" ok Running "Main.main" In B In A Segmentation fault: 11 }}} (with GHC 7.4.2, 7.6.3, 7.8.2, 7.8.3; OSX 64 bit). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9481#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9481: Linker does not correctly resolve symbols in previously loaded objects -------------------------------------+------------------------------------- Reporter: edsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: MacOS X | Architecture: Unknown/Multiple Type of failure: | Difficulty: Unknown None/Unknown | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by rwbarton): * os: Unknown/Multiple => MacOS X -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9481#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9481: Linker does not correctly resolve symbols in previously loaded objects -------------------------------------+------------------------------------- Reporter: edsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: MacOS X | Architecture: Unknown/Multiple Type of failure: | Difficulty: Unknown None/Unknown | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by simonmar): Works for me on Linux x86_64... somewhat surprisingly, since after `resolveObjs` has already failed once it seems likely that things might be left in a partially-linked state, and repeating `resolveObjs` might not work. I think after `resolveObjs` has failed you probably shouldn't use the linker any more and should report the error and exit, which is what GHCi does. What is the use case for retrying `resolveObjs` after it has failed? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9481#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9481: Linker does not correctly resolve symbols in previously loaded objects -------------------------------------+------------------------------------- Reporter: edsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.8.2 (Linker) | Resolution: | Keywords: Operating System: MacOS X | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by ezyang): * component: Compiler => Runtime System (Linker) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9481#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC