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

{.codegenDecl: "__thread $# $#".} does not seem to work across files #2101

Open
ckkashyap opened this issue Feb 11, 2015 · 6 comments
Open

Comments

@ckkashyap
Copy link

Linker complains when a file that uses a var declared with codegenDecl in another file.

kashyap@kashyap-tp:~/junk$ nim c hello.nim
config/nim.cfg(45, 2) Hint: added path: '/home/kashyap/.babel/pkgs/' [Path]
config/nim.cfg(46, 2) Hint: added path: '/home/kashyap/.nimble/pkgs/sdl2-1.0' [Path]
config/nim.cfg(46, 2) Hint: added path: '/home/kashyap/.nimble/pkgs/nimble-0.6.0' [Path]
config/nim.cfg(46, 2) Hint: added path: '/home/kashyap/.nimble/pkgs/opengl-1.0' [Path]
config/nim.cfg(46, 2) Hint: added path: '/home/kashyap/.nimble/pkgs/x11-1.0' [Path]
config/nim.cfg(46, 2) Hint: added path: '/home/kashyap/.nimble/pkgs/opencv-0.1.0' [Path]
config/nim.cfg(46, 2) Hint: added path: '/home/kashyap/.nimble/pkgs/' [Path]
Hint: used config file '/home/kashyap/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: hello [Processing]
Hint: world [Processing]
CC: world
[Linking]
/usr/bin/ld: worldptr_89012: TLS definition in /home/kashyap/junk/nimcache/world.o section .tbss mismatches non-TLS reference in /home/kashyap/junk/nimcache/hello.o
/home/kashyap/junk/nimcache/hello.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Error: execution of an external program failed

world.nim

type WORLD* = object
  dingo*: int

var worldptr* {.codegenDecl: "__thread $# $#".}: ptr WORLD

hello.nim

import world
echo "hello", worldptr.dingo
@Araq
Copy link
Member

Araq commented Feb 11, 2015

For __thread you don't need codegenDecl, use the .threadVar pragma.

@ckkashyap
Copy link
Author

Using .threadVar does not seem to influence the generated C.

var variable {.threadvar.} : ptr int

produces

NI* variable_89004;

Should it not insert __thread?

@Varriount
Copy link
Contributor

@ckkashyap Under certain cases, Nim uses emulated TLS, to work around compiler bugs and such. Are you sure that nothing has changed in the generated C code? Try using '--tlsEmulation:off' in your command line arguments.

@ckkashyap
Copy link
Author

Passing --threads:on (as Araq mentioned in IRC) made {.threadvar.} work correctly.

Araq had asked to leave the bug open since the original issue about {.codegenDecl: "__thread $# $#".} was valid.

@andreaferretti
Copy link
Collaborator

Original example works for me with devel on MacOS

@andreaferretti
Copy link
Collaborator

Still not working on Linux: seems like a difference between gcc and clang

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

4 participants