Having trouble using SBCL as a library from Rust on Windows.

"Sage Imel" <[email protected]> Sun, 19 Jan 2025 04:07:44 -0800
Newsgroups gmane.lisp.steel-bank.general
Message-ID <[email protected]>
Hello,

I'm having trouble getting SBCL to find the symbols for initialize-lisp to set values to on Windows. I'm not sure if I'm doing something wrong or if this isn't supported on Windows or what. I've got a global variable declared in my rust project exported as the name that my lisp code expects, and the rust code is compiled with the `export-executable-symbols` flag (which I believe marks the variable as if it had been declared with __declspec(dllexport)  in C). On Linux this works when compiled with the `-rdynamic` flag.

My example symbol is `moocow`. When I try my rust binary it fails with:

PS C:\Users\sage\windows_test> make rtest
host_test/target/debug/host_test
["sbcl", "--core", "lisp.lib", "--disable-signal-handlers", "--no-sysinit", "--no-userinit"]
Moocow: None
Initing lisp
This is SBCL 2.5.0.0.HEAD.5-41413d130, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
Missing required foreign symbol 'trunc'
Missing required foreign symbol 'truncf'
Missing required foreign symbol 'log1p'
Missing required foreign symbol 'log2'
Unhandled SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR in thread #<SB-THREAD:THREAD tid=24648 "main thread" RUNNING
                                                                 {1100BB8003}>:
  Attempt to access an undefined alien variable.

Backtrace for: #<SB-THREAD:THREAD tid=24648 "main thread" RUNNING {1100BB8003}>
0: (SB-DEBUG::DEBUGGER-DISABLED-HOOK #<SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR {1100BAEEF3}> #<unused argument> :QUIT T)
1: (SB-DEBUG::RUN-HOOK *INVOKE-DEBUGGER-HOOK* #<SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR {1100BAEEF3}>)
2: (INVOKE-DEBUGGER #<SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR {1100BAEEF3}>)
3: (ERROR SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR)
4: (SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR)
5: ("foreign function: #x7FFF89696675")
6: ("foreign function: #x7FFF89696740")
7: ((SETF SB-SYS:SAP-REF-SAP) :INVALID-VALUE-FOR-UNESCAPED-REGISTER-STORAGE :INVALID-VALUE-FOR-UNESCAPED-REGISTER-STORAGE :INVALID-VALUE-FOR-UNESCAPED-REGISTER-STORAGE)
8: (SB-EVAL::EVAL-PROGN ((SETF (SB-SYS:SAP-REF-SAP SB-ALIEN::SAP (/ SB-ALIEN::OFFSET SB-VM:N-BYTE-BITS)) SB-ALIEN::VALUE) (SB-ALIEN-INTERNALS:NATURALIZE SB-ALIEN::VALUE (QUOTE #<ALIEN-TYPE (* T)>))) #<SB-EVAL::ENV {1100BAEAD3}>)
9: ((SETF SB-ALIEN-INTERNALS:%ALIEN-VALUE) #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X20010CC0 :TYPE (* T)> #.(SB-SYS:INT-SAP #X1C3CB700000) 0 #<ALIEN-TYPE (* T)>)
10: (SB-IMPL::%START-LISP)
11: ("foreign function: #x7FFF89696675")
12: ("foreign function: #x7FFF8965A0E0")

unhandled condition in --disable-debugger mode, quitting
A nested error within --disable-debugger error handling prevents printing the backtrace. Sorry, exiting.





I'm also nervous about why trunc, truncf, log1p, and log2 are missing but that's probably a completely separate problem... 




The regular symbol table seems to be empty for my binary (i'm not really that familiar with windows executable/dll structure but this might be normal?):

PS C:\Users\sage\windows_test> dumpbin.exe /SYMBOLS .\host_test\target\debug\host_test.exe
Microsoft (R) COFF/PE Dumper Version 14.42.34435.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file .\host_test\target\debug\host_test.exe

File Type: EXECUTABLE IMAGE

  Summary

        1000 .00cfg
        4000 .data
        3000 .idata
        E000 .pdata
       48000 .rdata
        3000 .reloc
      11D000 .text
        1000 .tls

But it does seem to have the `moocow` symbol exported for use by DLLs:

PS C:\Users\sage\windows_test> dumpbin.exe /EXPORTS .\host_test\target\debug\host_test.exe
Microsoft (R) COFF/PE Dumper Version 14.42.34435.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file .\host_test\target\debug\host_test.exe

File Type: EXECUTABLE IMAGE

  Section contains the following exports for host_test.exe

    00000000 characteristics
    FFFFFFFF time date stamp
        0.00 version
           1 ordinal base
           2 number of functions
           2 number of names

    ordinal hint RVA      name

          1    0 00003FE4 main = @ILT+12255(main)
          2    1 00167450 moocow = moocow

  Summary

        1000 .00cfg
        4000 .data
        3000 .idata
        E000 .pdata
       48000 .rdata
        3000 .reloc
      11D000 .text
        1000 .tls 

The code I'm trying is available at: https://github.com/nightfly19/sbcl-windows-rust-problem

I've also posted about this on the Rust Reddit, since I'm not really sure where the problem lies... https://old.reddit.com/r/rust/comments/1i4oi54/exporting_static_global_variable_in_binary_on/

I'd appreciate any help at all, I'm way outside my comfort zone here especially on the Windows side of this.

Thanks,

Sage Imel

_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help