Files
Nim/tests/dll/visibility.nim
alaviss f500895efe Unexport even more symbols (#13214)
* system/gc: don't export markStackAndRegisters

* compiler/cgen: unexport internal symbols

As these functions are Nim-specific walkaround against C's optimization
schemes, they don't serve any purpose being exported.

* compiler/cgen: don't export global var unless marked

* compiler/ccgthreadvars: don't export threadvar unless marked

* tests/dll/visibility: also check for exports

This ensure that these changes don't break manual exports.

* compiler/cgen: hide all variables created for constants

* compiler/ccgtypes: don't export RTTI variables

* compiler/ccgexprs: make all complex const static

* nimbase.h: fix export for windows

* compiler/cgen, ccgthreadvars: export variables correctly

For C/C++ variables, `extern` means that the variable is defined in an
another unit. Added a new N_LIB_EXPORT_VAR to correctly export
variables.
2020-01-23 13:45:31 +01:00

44 lines
891 B
Nim

discard """
output: ""
"""
const LibName {.used.} =
when defined(windows):
"visibility.dll"
elif defined(macosx):
"libvisibility.dylib"
else:
"libvisibility.so"
when compileOption("app", "lib"):
var
bar {.exportc.}: int
thr {.exportc, threadvar.}: int
proc foo() {.exportc.} = discard
var
exported {.exportc, dynlib.}: int
exported_thr {.exportc, threadvar, dynlib.}: int
proc exported_func() {.exportc, dynlib.} = discard
elif isMainModule:
import dynlib
let handle = loadLib(LibName)
template check(sym: untyped) =
const s = astToStr(sym)
if handle.symAddr(s) != nil:
echo s, " is exported"
template checkE(sym: untyped) =
const s = astToStr(sym)
if handle.symAddr(s) == nil:
echo s, " is not exported"
check foo
check bar
check thr
checkE exported
checkE exported_thr
checkE exported_func