1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-12 22:45:13 +00:00

Fix DECLARE LIBRARY against stripped .so file

.so files can be stripped such that they contain no "regular" symbol
table but do still contain the "dynamic" symbol table, this is pretty
typical for .so files. QB64-PE is supposed to check both tables when
linking against a .so file, but a bug in ab0c2b18 meant that the second
run of nm with the -D flag to check the dynamic symbol table no longer
happens. The fix is to introduce a new output file for the dynamic run
so that they are handled separately in terms of caching the result.

A new test .so file that only contains a dynamic symbol table was added
to avoid this in the future.

Fixes: #301
This commit is contained in:
Matthew Kilgore 2023-02-07 02:38:10 -05:00 committed by Matt Kilgore
parent 7cd5da3d41
commit fac5375ea6
5 changed files with 43 additions and 12 deletions

View file

@ -12582,8 +12582,11 @@ END IF
'Clear nm output from previous runs 'Clear nm output from previous runs
FOR x = 1 TO ResolveStaticFunctions FOR x = 1 TO ResolveStaticFunctions
IF LEN(ResolveStaticFunction_File(x)) THEN IF LEN(ResolveStaticFunction_File(x)) THEN
s$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x)) s$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x), 0)
IF _FILEEXISTS(s$) THEN KILL s$ IF _FILEEXISTS(s$) THEN KILL s$: ClearBuffers s$
s$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x), 1)
IF _FILEEXISTS(s$) THEN KILL s$: ClearBuffers s$
END IF END IF
NEXT x NEXT x
@ -12602,7 +12605,8 @@ IF os$ = "WIN" THEN
'resolve static function definitions and add to global.txt 'resolve static function definitions and add to global.txt
FOR x = 1 TO ResolveStaticFunctions FOR x = 1 TO ResolveStaticFunctions
nm_output_file$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x)) nm_output_file$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x), 0)
nm_output_file_dynamic$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x), 1)
IF LEN(ResolveStaticFunction_File(x)) THEN IF LEN(ResolveStaticFunction_File(x)) THEN
n = 0 n = 0
@ -12659,8 +12663,8 @@ IF os$ = "WIN" THEN
END IF END IF
IF n = 0 THEN 'a C++ dynamic object library? IF n = 0 THEN 'a C++ dynamic object library?
IF NOT _FILEEXISTS(nm_output_file$) THEN IF NOT _FILEEXISTS(nm_output_file_dynamic$) THEN
SHELL _HIDE "cmd /c internal\c\c_compiler\bin\nm.exe " + AddQuotes$(ResolveStaticFunction_File(x)) + " -D --demangle -g >" + AddQuotes$(nm_output_file$) SHELL _HIDE "cmd /c internal\c\c_compiler\bin\nm.exe " + AddQuotes$(ResolveStaticFunction_File(x)) + " -D --demangle -g >" + AddQuotes$(nm_output_file_dynamic$)
END IF END IF
s$ = " " + ResolveStaticFunction_Name(x) + "(" s$ = " " + ResolveStaticFunction_Name(x) + "("
fh = OpenBuffer%("I", nm_output_file$) fh = OpenBuffer%("I", nm_output_file$)
@ -12687,7 +12691,7 @@ IF os$ = "WIN" THEN
IF n = 0 THEN 'a C dynamic object library? IF n = 0 THEN 'a C dynamic object library?
s$ = " " + ResolveStaticFunction_Name(x) s$ = " " + ResolveStaticFunction_Name(x)
fh = OpenBuffer%("I", nm_output_file$) fh = OpenBuffer%("I", nm_output_file_dynamic$)
DO UNTIL EndOfBuf%(fh) DO UNTIL EndOfBuf%(fh)
a$ = ReadBufLine$(fh) a$ = ReadBufLine$(fh)
IF LEN(a$) THEN IF LEN(a$) THEN
@ -12751,7 +12755,8 @@ IF os$ = "LNX" THEN
END IF END IF
FOR x = 1 TO ResolveStaticFunctions FOR x = 1 TO ResolveStaticFunctions
nm_output_file$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x)) nm_output_file$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x), 0)
nm_output_file_dynamic$ = MakeNMOutputFilename$(ResolveStaticFunction_File(x), 1)
IF LEN(ResolveStaticFunction_File(x)) THEN IF LEN(ResolveStaticFunction_File(x)) THEN
n = 0 n = 0
@ -12814,8 +12819,8 @@ IF os$ = "LNX" THEN
IF n = 0 THEN 'a C++ dynamic object library? IF n = 0 THEN 'a C++ dynamic object library?
IF MacOSX THEN GOTO macosx_libfind_failed IF MacOSX THEN GOTO macosx_libfind_failed
IF NOT _FILEEXISTS(nm_output_file$) THEN IF NOT _FILEEXISTS(nm_output_file_dynamic$) THEN
SHELL _HIDE "nm " + AddQuotes$(ResolveStaticFunction_File(x)) + " -D --demangle -g >" + AddQuotes$(nm_output_file$) + " 2>" + AddQuotes$(tmpdir$ + "nm_error.txt") SHELL _HIDE "nm " + AddQuotes$(ResolveStaticFunction_File(x)) + " -D --demangle -g >" + AddQuotes$(nm_output_file_dynamic$) + " 2>" + AddQuotes$(tmpdir$ + "nm_error.txt")
END IF END IF
s$ = " " + ResolveStaticFunction_Name(x) + "(" s$ = " " + ResolveStaticFunction_Name(x) + "("
fh = OpenBuffer%("I", nm_output_file$) fh = OpenBuffer%("I", nm_output_file$)
@ -12842,7 +12847,7 @@ IF os$ = "LNX" THEN
IF n = 0 THEN 'a C dynamic object library? IF n = 0 THEN 'a C dynamic object library?
s$ = " " + ResolveStaticFunction_Name(x) s$ = " " + ResolveStaticFunction_Name(x)
fh = OpenBuffer%("I", nm_output_file$) fh = OpenBuffer%("I", nm_output_file_dynamic$)
DO UNTIL EndOfBuf%(fh) DO UNTIL EndOfBuf%(fh)
a$ = ReadBufLine$(fh) a$ = ReadBufLine$(fh)
IF LEN(a$) THEN IF LEN(a$) THEN

View file

@ -27,6 +27,8 @@ FUNCTION GetMakeExecutable$ ()
END IF END IF
END FUNCTION END FUNCTION
FUNCTION MakeNMOutputFilename$ (libfile AS STRING) FUNCTION MakeNMOutputFilename$ (libfile AS STRING, dynamic As Long)
MakeNMOutputFilename$ = tmpdir$ + "nm_output_" + StrReplace$(StrReplace$(libfile, pathsep$, "."), ":", ".") + ".txt" If dynamic Then dyn$ = "_dynamic" Else dyn$ = ""
MakeNMOutputFilename$ = tmpdir$ + "nm_output_" + StrReplace$(StrReplace$(libfile, pathsep$, "."), ":", ".") + dyn$ + ".txt"
END FUNCTION END FUNCTION

View file

@ -0,0 +1,23 @@
$CONSOLE:ONLY
$IF LNX THEN
' This file is missing the regular symbol table and only contains the dynamic symbol table
DECLARE LIBRARY "./libstripped"
FUNCTION add_values&(BYVAL v1 AS LONG, BYVAL v2 as LONG)
END DECLARE
result = add_values&(2, 3)
PRINT result
$ELSE
' Windows can't use regular DECLARE LIBRARY to link against a dll, just skip this test
'
' Mac OS dylib files don't have a dynamic symbol table, so also nothing to test
PRINT 5
$END IF
SYSTEM