Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[regression] Importing more than one module with same name from different packages produce bad codegen #12420

Closed
jangko opened this issue Oct 12, 2019 · 5 comments

Comments

@jangko
Copy link
Contributor

jangko commented Oct 12, 2019

One of the module have to contains initialization code.
The other one contains procs.
The importer import the two or more modules with same name directly or indirectly via another module.
It will trigger bad codegen.

Example

# module a/utils.nim
proc burnMem*(a: int) =
  discard
# module b/utils.nim
let x = 10
import b/utils, a/utils as autils

burnMem(10)

Current Output

F:\nimcache\bug\debug\utils.nim.c.o:utils.nim.c:(.text+0xaa): multiple definition of `burnMem__1hiCVbSm2i9a2dZa7QJ9aihg'
F:\nimcache\bug\debug\utils.nim.c.o:utils.nim.c:(.text+0xaa): first defined here
F:\nimcache\bug\debug\bug.nim.c.o:bug.nim.c:(.text+0xd4): undefined reference to `unknown_utilsInit000'
collect2.exe: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc.exe   -o F:\projects\bug\bug.exe  F:\nimcache\bug\debug\stdlib_io.nim.c.o F:\nimcache\bug\debug\stdlib_system.nim.c.o F:\nimcache\bug\debug\utils.nim.c.o F:\nimcache\bug\debug\utils.nim.c.o F:\nimcache\bug\debug\bug.nim.c.o    '

Additional Information

$ nim -v
Nim Compiler Version 1.0.99 [Windows: amd64]
Compiled at 2019-10-12
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: eeffa0163fba932f5e0a16023ef3c4b833b36358
active boot switches: -d:release
@jangko
Copy link
Contributor Author

jangko commented Oct 19, 2019

hi @Araq, thank you for fixing this one. but I still encounter the same problem if the modules are located in nimble install dir and not located in local subdir. could you please take a look?

@Araq
Copy link
Member

Araq commented Oct 19, 2019

How to reproduce?

@Araq Araq reopened this Oct 19, 2019
@jangko
Copy link
Contributor Author

jangko commented Oct 19, 2019

the easiest perhaps follow this steps:

$> nimble install eth
$> nimble install nimcrypto

then compile this file with nim c -threads:on -d:metrics bug

# bug.nim
import eth/common/utils as autils, nimcrypto/utils

var x: array[100, byte]
burnMem(x)

@Araq
Copy link
Member

Araq commented Oct 20, 2019

But this compiles for me...

@jangko
Copy link
Contributor Author

jangko commented Oct 20, 2019

Sorry for wasting your time. After I remove all nimcache and rebuild the compiler with latest devel branch the problem is gone. Somehow the nimcache messed up with the compiler binary.
Thanks again for your hard work. We will soon move to Nim 1.0.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants