Opened 4 years ago

Closed 3 years ago

Last modified 12 months ago

#11155 closed bug (fixed)

Trivial thunk gives "undefined reference to stg_ap_0_upd_info"

Reported by: simonpj Owned by:
Priority: highest Milestone: 8.0.1
Component: Compiler Version: 7.10.2
Keywords: Cc: alanz
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: simplCore/should_compile/T11155
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by bgamari)

This error popped up when Alan was coding the solution for #11028. The error is utterly unrelated to what Alan was working on. Here's a reproducer

{-# OPTIONS_GHC -O -fno-full-laziness #-}
module Main where

foo :: Bool
{-# NOINLINE foo #-}
foo = error "rk"

bar x = let t :: Char
            t = case foo of { True -> 'v'; False -> 'y' }
        in [t]

main = print (bar ())

Just compile that and you get

Foo.o: In function `c1Sm_info':
(.text+0x29a): undefined reference to `stg_ap_0_upd_info'

Why do we get that unresolved symbol? The STG code for bar looks like

Main.bar :: forall t_aup. t_aup -> [GHC.Types.Char]
[GblId, Arity=1, Str=DmdType <L,A>m2, Unf=OtherCon []] =
    \r srt:SRT:[rf :-> Main.foo] [x_s1RR]
        let {
          sat_s1RT [Occ=Once] :: GHC.Types.Char
          [LclId, Str=DmdType] =
              \u srt:SRT:[rf :-> Main.foo] [] Main.foo;
        } in  : [sat_s1RT GHC.Types.[]];

Look at that: an updatable thunk saying sat_s1RT = Main.foo! The error message is terrible, but the problem is a thunk whose only payload is a single variable.

Why does that happen? The Core is

bar =
  \ (@ t_aup) _  -> let t::Char = case foo of wild_00 { }
                    in : @ Char t ([] @ Char)

The case is needed to change foo's type from Bool to Char. The Core-to-STG pass drops the empty case alternatives as useless (rightly), but leaves a bare variable as the RHS, which confuses the code generator.

We should clearly substitute Main.foo for t, either in Core-to-STG, or during code generation.

Why hasn't this happened before now? It is quite hard to provoke, because floating the thunk for t to top level stops it happening. So it only happens if you switch off full laziness (as my test case here does), or if some very delicate inlining happens after the last float-out. The latter is very rare, but it's what happened to Alan.

Change History (17)

comment:1 Changed 4 years ago by simonpj

Summary: Trivial error thunk gives "undefined reference to stg_ap_0_upd_info"Trivial thunk gives "undefined reference to stg_ap_0_upd_info"

comment:2 Changed 4 years ago by hvr

Priority: normalhigh

Fyi, I'm seeing this during GHC building as well (which makes the current Ubuntu PPA nightlies fail):

...
  AR compiler/stage2/build/libHSghc-7.11.20151202.a
  HC [stage 1] compiler/stage2/build/libHSghc-7.11.20151202-ghc7.11.20151202.so
/usr/bin/ar: creating compiler/stage2/build/libHSghc-7.11.20151202.a
Warning: -rtsopts and -with-rtsopts have no effect with -shared.
    Call hs_init_ghc() from your main() function to set these options.
"rm" -f compiler/stage2/build/libHSghc-7.11.20151202.a.contents  
  HC [stage 1] ghc/stage2/build/GhciTags.dyn_o
  HC [stage 1] ghc/stage2/build/InteractiveUI.dyn_o
  HC [stage 1] ghc/stage2/build/Main.dyn_o
  HC [stage 1] ghc/stage2/build/tmp/ghc-stage2
Warning: -rtsopts and -with-rtsopts have no effect with -no-hs-main.
    Call hs_init_ghc() from your main() function to set these options.
/«PKGBUILDDIR»/compiler/stage2/build/libHSghc-7.11.20151202-ghc7.11.20151202.so: undefined reference to `stg_ap_0_upd_info'
collect2: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
make[3]: *** [ghc/stage2/build/tmp/ghc-stage2] Error 1
make[2]: *** [all] Error 2
make[2]: Leaving directory `/«PKGBUILDDIR»'
make[1]: *** [override_dh_auto_build] Error 2
make[1]: Leaving directory `/«PKGBUILDDIR»'
make: *** [build] Error 2

comment:3 Changed 4 years ago by alanz

Cc: alanz added

comment:4 Changed 4 years ago by Simon Peyton Jones <simonpj@…>

In 1c9fd3f1/ghc:

Case-of-empty-alts is trivial (Trac #11155)

As you'll see from Trac #11155, the code generator was confused
by a binding let x = y in ....   Why did that happen? Because of
a (case y of {}) expression on the RHS.

The right thing is just to expand what a "trivial" expression is.

See Note [Empty case is trivial] in CoreUtils.

comment:5 Changed 4 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: simplCore/should_compile/T11155

I claim this is fixed. Alan, Herbert, does this fix the manifestations you see?

I'll close it meanwhile.

Simon

comment:6 Changed 4 years ago by alanz

Yes, the linker error is gone for haddock in D1558. Thanks.

comment:7 Changed 4 years ago by hvr

I don't see the manifestation either anymore (i.e. the PPA builds work again now)

comment:8 Changed 4 years ago by thomie

Milestone: 8.0.1

comment:9 Changed 3 years ago by gridaphobe

I just ran into this (or a similar issue) when building GHC (9b6820cdd6bac8b8346be48224627e3feefa9036) on OSX. This is a clean build with the default settings, and it fails at the very last step of stage 2.

  HC [stage 1] ghc/stage2/build/tmp/ghc-stage2
Warning: -rtsopts and -with-rtsopts have no effect with -no-hs-main.
    Call hs_init_ghc() from your main() function to set these options.
Undefined symbols for architecture x86_64:
  "_stg_sel_17_upd_info", referenced from:
      _s1s8Z_info in UI.dyn_o
      _s1s9w_info in UI.dyn_o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

comment:10 Changed 3 years ago by wereHamster

Ran into this trying to build HEAD today on Mac OS X 10.11.3. But a slightly different message:

Warning: -rtsopts and -with-rtsopts have no effect with -no-hs-main.
    Call hs_init_ghc() from your main() function to set these options.
Undefined symbols for architecture x86_64:
  "_stg_sel_17_upd_info", referenced from:
      _s1xPf_info in UI.dyn_o
      _s1xQA_info in UI.dyn_o
      _s1xZU_info in UI.dyn_o
      _s1y0r_info in UI.dyn_o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
make[1]: *** [ghc/stage2/build/tmp/ghc-stage2] Error 1
make: *** [all] Error 2

comment:11 in reply to:  10 Changed 3 years ago by George

I ran into this today building 8.0.1 rc3 on Mac 10.11.4 with XCode 7.3 invoking with "make -j5":

Warning: -rtsopts and -with-rtsopts have no effect with -no-hs-main.
    Call hs_init_ghc() from your main() function to set these options.
Undefined symbols for architecture x86_64:
  "_stg_sel_17_upd_info", referenced from:
      _s1xEL_info in UI.dyn_o
      _s1xG6_info in UI.dyn_o
      _s1xPC_info in UI.dyn_o
      _s1xQ9_info in UI.dyn_o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
make[1]: *** [ghc/stage2/build/tmp/ghc-stage2] Error 1
make: *** [all] Error 2
bash-3.2$ 

Should I reopen this ticket or open a new one?

Last edited 3 years ago by George (previous) (diff)

comment:12 Changed 3 years ago by bgamari

Description: modified (diff)
Resolution: fixed
Status: closednew

The fix mentioned in comment:4 is present on the ghc-8.0 branch as 1c9fd3f1c5522372fcaf250c805b959e8090a62c.

Indeed it seems that something is still amiss here.

comment:13 Changed 3 years ago by bgamari

Priority: highhighest

comment:14 Changed 3 years ago by bgamari

Resolution: fixed
Status: newclosed

This actually appears to be a much different issue from that originally reported in this ticket as the symbol in question are update closures instead of zero-arity applications. Let's track this new issue in #11823.

comment:15 Changed 3 years ago by bgamari

See Phab:D2230 for a quick patch to catch this sort of issue during C-- pretty-printing.

comment:16 Changed 3 years ago by Ben Gamari <ben@…>

In f091218/ghc:

CLabel: Catch #11155 during C-- pretty-printing

In #11555 we ended up generating references to the non-existence
stg_ap_0_upd. Here we add asserts to verify that we don't generate
references to non-existent selector or application symbols.

It would likely also make sense to add further asserts during code
generation, so we can catch the issue even closer to its source.

Test Plan: Validate

Reviewers: simonmar, austin, ezyang

Reviewed By: simonmar, austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2230

GHC Trac Issues: #11155

comment:17 Changed 12 months ago by Simon Peyton Jones <simonpj@…>

In 2dbf88b3/ghc:

Fix get getIdFromTrivialExpr

This bug, discovered by Trac #15325, has been lurking since

  commit 1c9fd3f1c5522372fcaf250c805b959e8090a62c
  Author: Simon Peyton Jones <simonpj@microsoft.com>
  Date:   Thu Dec 3 12:57:54 2015 +0000

    Case-of-empty-alts is trivial (Trac #11155)

I'd forgotttnen to modify getIdFromTrivialExpr when I
modified exprIsTrivial.   Easy to fix, though.
Note: See TracTickets for help on using tickets.