Subject: bug#24574: emacs-module is not GPL compatible (Windows)

From: Mambo Levis <[email-masked]>
Date: Sat, 1 Oct 2016 20:28:15 +0000 (UTC)

Thank you for the pexports recommendation.
For somebody that just read this problem for the first time, a summary:
Emacs version: GNU Emacs 25.1.1

Emacs module repo: https://github.com/syohex/emacs-sqlite3

Build process: mingw64_shell.bat (Windows) 
Dependency: sqlite.lib
Makefile:
EMACS = D:\user\emacs-src\emacs-25-branch-srcINCLUDE = -I. -I$(EMACS)\src 
CC      = gccLD      = gccLDFLAGS =
# On MS-Windows, say "make SO=dll" to build the moduleSO      = dll# -fPIC is a no-op on Windows, but causes a compiler warningifeq ($(SO),dll)CFLAGS  = -std=gnu99 -ggdb3 -WallelseCFLAGS  = -std=gnu99 -ggdb3 -Wall -fPICendif
all: sqlite3-core.$(SO)
%.$(SO): %.o $(LD) -shared $(LDFLAGS) -o $@ $< sqlite3.lib
%.o: %.c $(CC) $(CFLAGS) $(INCLUDE) -c $<
check: $(EMACS)/src/emacs -batch -l ert -l test.el -f ert-run-tests-batch-and-exit    clean: rm -rf *.o *.dll *.a *.d
--------------------------------------------------------------------------------------------------------------------------------
Now the result of my tests:

1. The symbols exported by the modules without considering any sqlite function are:
 LIBRARY sqlite3-core.dll
EXPORTSemacs_module_init ; .text ; RVA 00001685plugin_is_GPL_compatible DATA ; no section ; RVA 00007010
2. onsidering the following sqlite3 related function:
static voidel_sqlite3_free(void *arg){ sqlite3_close((sqlite3*)arg);}
When I generate the sqlite3-core.dll using at least one sqlite3 DLL function, for example sqlite3_close , an error message appears:  (the module can't be found) ..../modules/emacs-sqlite3/sqlite3-core.dll: Das angegebene Modul wurde nicht gefunden.

I check the sqlite3.dll using pexports tool, and the symbols sqlite3_close is exported.LIBRARY sqlite3.dllEXPORTS.....sqlite3_changes ; .text ; RVA 0009c648sqlite3_clear_bindings ; .text ; RVA 000373dcsqlite3_close ; .text ; RVA 0009c9e8sqlite3_close_v2 ; .text ; RVA 0009ca08sqlite3_collation_needed ; .text ; RVA 0009f4b3sqlite3_collation_needed16 ; .text ; RVA 0009f51f
I check the module qlite3-core.dll again and the symbols are there.
; .text   : RVA: 00001000, File offset: 00000600; .data   : RVA: 00003000, File offset: 00002400; .rdata  : RVA: 00004000, File offset: 00002600; .pdata  : RVA: 00005000, File offset: 00002e00; .xdata  : RVA: 00006000, File offset: 00003200; .bss    : RVA: 00007000, File offset: 00000000; .edata  : RVA: 00008000, File offset: 00003400; .idata  : RVA: 00009000, File offset: 00003600; .CRT    : RVA: 0000a000, File offset: 00003e00; .tls    : RVA: 0000b000, File offset: 00004000; .reloc  : RVA: 0000c000, File offset: 00004200; /4      : RVA: 0000d000, File offset: 00004400; /19     : RVA: 0000e000, File offset: 00004800; /31     : RVA: 00018000, File offset: 0000e200; /45     : RVA: 0001a000, File offset: 0000fa00; /57     : RVA: 0001c000, File offset: 00011200; /70     : RVA: 0001d000, File offset: 00011e00; /81     : RVA: 0001e000, File offset: 00012200; /92     : RVA: 00021000, File offset: 00015200; /105    : RVA: 0002b000, File offset: 0001f200; Reading exports from section: .edata; Export table: sqlite3-core.dll; Ordinal base: 1; Ordinal table RVA: 00008038; Name table RVA: 0008030; Export address table RVA: 00008028LIBRARY sqlite3-core.dllEXPORTSemacs_module_init ; .text ; RVA 00001696plugin_is_GPL_compatible DATA ; no section ; RVA 000078f0 

Please, notice that this time the plugin_is_GPL_compatible. The problem is now that the module can't be found when a sqlite3.dll symbol is used.
Any Idea or suggestion?
Thanks
Levis
    On Saturday, October 1, 2016 5:40 PM, Eli Zaretskii <[email-masked]> wrote:

 [Please don't cross post to help-gnu-emacs if you report bugs.]

> Date: Sat, 1 Oct 2016 12:31:26 +0000 (UTC)
> From: Mambo Levis <[email-masked]>
> Cc: [email-masked], [email-masked]
> 
> 1. I commented all module's functions related with sqlite3 library and only leave uncommented one of function
> to verify if the module is working:
> 
> /* emacs-sqlite-version*/
> static emacs_value
> Femacs_sqlite_version (emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data)
> {
> const char* msg_docstr = "emacs-sqlite module version 0.1";
> return env->make_string (env, msg_docstr, strlen(msg_docstr));
> }
> 
> When I require (emacs-sqlite-version) it works as expected.
> 
> 2. I tested only two function: the previous one Femacs_sqlite_version and other associated with sqlite. Once I
> consider a module function related to sqlite error message appears: 
> is not GPL compatible
> 
> I think the error is related with the linking process of the sqlite3.lib . One possible test is not linking sqlite3.lib
> and stead just using sqlite source code as a part of the module.
> 
> Do you have any suggestion?

I'd start by using the pexports program (or something similar) to see
which symbols are exported by the sqlite DLL.