Skip to content

Linker error when recompiling after removing string literal from inline function #1897

@Nimaoth

Description

@Nimaoth

start with bar.nim

import std/[syncio]

proc bar*() =
  echo "very long long long string"

proc baz*() {.inline.} =
  echo "another long long long string"

and strlit.nim

import helpers/bar

bar()
baz()

then compile

PS C:\dev\nimony> nimony c -r -o:test.exe .\tests\incremental\strlit.nim
very long long long string
another long long long string

then remove the echo in bar:

import std/[syncio]

proc bar*() =
  discard

proc baz*() {.inline.} =
  echo "another long long long string"

then compile again

PS C:\dev\nimony> nimony c -r -o:test.exe .\tests\incremental\strlit.nim
c:/dev/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: nimcache\strn9h6ct1\strn9h6ct1.o:strn9h6ct1.c:(.rdata$.refptr.strlit_1_barqgpk1b[.refptr.strlit_1_barqgpk1b]+0x0): undefined reference to `strlit_1_barqgpk1b'
collect2.exe: error: ld returned 1 exit status
FAILURE: C:\dev\nimony\bin\nifmake.exe --base:.\tests\incremental -j run nimcache\strn9h6ct1.final.build.nif

nifc inlines the baz function, which refers to a generated global for it's string literal (strlit_1_barqgpk1b). That string literal global becomes strlit_0_barqgpk1b after removing the other string literal in bar, but nifc isn't rerun to regenerate the c file from the .c.nif file for strlit.nim.

Manually running nifc on any file that inlines baz fixes the problem, so I assume the problem is that nifc doesn't know that it needs to rerun when inlined dependencies change, it's only rerun when the .c.nif file changes which is not the case here because the inlining happens in nifc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions