-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
dll symbol visibility is a bit messy and platform specific; would be nice to have a cross-platform way to do it.
example
proc fun1() {.exportc.} = discard
proc local_fun1() {.exportc.} = discard
proc global_fun1() {.exportc.} = discard
proc fun1_other() = discard
if false: fun1_other() # prevents optimizing it out (maybe there's a more robust way)
OSX
after trying a bit, the key is to use: --passc:-fvisibility=default --passl:-Wl,-exported_symbol,_fun1
(-exported_symbols_list filename
could also be used)
Nothing else worked. In particular, --version-script is not supported on OSX nor is -export-symbols-regex
(note: to help debugging what gets executed, I had to use --listcmd --hint:exec:on
)
nim c --app:lib --passl:-Wl,-exported_symbol,_fun1 main.nim
nm libmain.dylib | grep fun1
000000000000eba0 T _fun1
000000000000edb0 t _fun1_other__mxNciiSalhqvqXpk1aCNHw_2
000000000000ed40 t _global_fun1
000000000000ecd0 t _local_fun1
more docs: https://www.unix.com/man-page/osx/1/ld/
linux?
-export-symbols-regex
?
--version-script
?
We need to make sure it works across compilers
windows?
We need to make sure it works across compilers
note
- the point is to avoid (or have an alternative to) decorating individual symbols with things like
__attribute__(("visibility" ("default)))
(eg:{.pragma: lib, exportc, codegenDecl: """extern __attribute__((visibility("default"))) $# $#$#""".}
), which is not good in many cases (eg maybe different libraries want to export a given symbol differently etc) - briefly discussed in IRC by leorize
leorize Araq: btw on *nix Nim isn't hiding unexported symbols when building dlls
leorize should we just enforce -fvisibility=hidden then un-hide symbols like for windows?
proposal
- we add a nim specific cmdline flag that abstracts away platform specific differences to export what user wants.
- ideally, it should work even with nim's mangled symbols without needing to know the mangled symbol name; the compilers knows the mapping
nimName=>mangledName
so should be able to help - it should work with non-nim code, eg C/C++ code emitted inside nim code
- we should have a simple way to list a number of symbols; ideally via a regex (the compiler can then do the magic to support OSX which doesn't have
-export-symbols-regex
)
links
- Support a cross-platform symbol export list for library targets · Issue #4298 · mesonbuild/meson : Support a cross-platform symbol export list for library targets · Issue #4298 · mesonbuild/meson
- Control over symbol exports in GCC - antek's tech blog : Control over symbol exports in GCC - antek's tech blog
- https://www.unix.com/man-page/osx/1/ld/
- https://flameeyes.blog/2011/01/20/hide-those-symbols/
- http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html (lines 7 and 8 )