PLC-lang / StandardFunctions

Standard functions for PLC as described by IEC61131
GNU Lesser General Public License v2.1
10 stars 2 forks source link

Missing function symbols in object code #64

Closed mhasel closed 1 year ago

mhasel commented 1 year ago

It is currently not possible to call ST wrappers that do not point to rust functions in the standard library. Trying to do so will result in linking errors, since the symbols are missing. LEFT does not get resolved to LEFT__STRING. The compiled .so file only contains symbols for LEFT_EXT. This happens both for debug and release configurations.

To reproduce: compile rustyc and the stdlib and try to call any string wrapper function in a test program

FUNCTION LEFT <T: ANY_STRING> : T
VAR_INPUT {ref}
    IN : T;
END_VAR
VAR_INPUT
    L  : DINT;
END_VAR
END_FUNCTION

{external}
FUNCTION LEFT_EXT<T: ANY_STRING> : DINT
VAR_INPUT {ref}
    IN : T;
END_VAR
VAR_INPUT
    L  : DINT;
END_VAR
VAR_IN_OUT
    OUT: T;
END_VAR
END_FUNCTION

FUNCTION LEFT__STRING : STRING[2048]
VAR_INPUT {ref}
    IN : STRING[2048];
END_VAR
VAR_INPUT
    L  : DINT;
END_VAR
    LEFT_EXT(IN, L, LEFT__STRING);
END_FUNCTION

{external}
FUNCTION LEFT_EXT__STRING : DINT
VAR_INPUT {ref}
    IN : STRING[2048];
END_VAR
VAR_INPUT
    L  : DINT;
END_VAR
VAR_IN_OUT
    OUT: STRING[2048];
END_VAR
END_FUNCTION

FUNCTION main : DINT
VAR
    s1: STRING := 'hi';
    s2: STRING;
END_VAR
    s2 := LEFT(s1, 1);   // <------- this will fail
END_FUNCTION

when trying to compile:

in function `main':
main:(.text+0x32): undefined reference to `LEFT__STRING'
collect2: error: ld returned 1 exit status
Error: GeneralError { message: "An error occured during linking", err_no: linker__generic_error }
mhasel commented 1 year ago

When using the provided build scripts for both rusty and the stdlib, the object code is no longer missing functions.