Skip to content

Make tlsh_unittest shared-linkable #111

@mapreri

Description

@mapreri

Hi!

I understand that you don't seem to appreciate shared linked binaries, but in Debian we tend to at least have a preference for them.

Currently forcing tlsh_unittest to link libtlsh.so fails with this:

/usr/bin/ld: CMakeFiles/tlsh_unittest.dir/tlsh_unittest.cpp.o: in function `trendLSH_ut(char*, char*, char*, char*, int, int, char*, char*, int, bool, int, int, int, int, int, int, char*, int)':
tlsh_unittest.cpp:(.text+0x459): undefined reference to `set_input_desc(char*, char*, int, int, char*, char*, int, int, char*, InputDescr*, int)'
/usr/bin/ld: tlsh_unittest.cpp:(.text+0x4a6): undefined reference to `read_file_eval_tlsh(char*, Tlsh*, int, int, int)'
/usr/bin/ld: tlsh_unittest.cpp:(.text+0x594): undefined reference to `freeFileName(FileName*, int)'
/usr/bin/ld: tlsh_unittest.cpp:(.text+0x7da): undefined reference to `convert_special_chars(char*, char*, unsigned long, int)'
/usr/bin/ld: tlsh_unittest.cpp:(.text+0x7fb): undefined reference to `convert_special_chars(char*, char*, unsigned long, int)'
/usr/bin/ld: tlsh_unittest.cpp:(.text+0xa30): undefined reference to `convert_special_chars(char*, char*, unsigned long, int)'
/usr/bin/ld: tlsh_unittest.cpp:(.text+0xb01): undefined reference to `convert_special_chars(char*, char*, unsigned long, int)'
/usr/bin/ld: tlsh_unittest.cpp:(.text+0xba3): undefined reference to `convert_special_chars(char*, char*, unsigned long, int)'
/usr/bin/ld: CMakeFiles/tlsh_unittest.dir/tlsh_unittest.cpp.o:tlsh_unittest.cpp:(.text+0xbc4): more undefined references to `convert_special_chars(char*, char*, unsigned long, int)' follow
/usr/bin/ld: CMakeFiles/tlsh_unittest.dir/tlsh_unittest.cpp.o: in function `trendLSH_ut(char*, char*, char*, char*, int, int, char*, char*, int, bool, int, int, int, int, int, int, char*, int)':
tlsh_unittest.cpp:(.text+0xe06): undefined reference to `freeFileName(FileName*, int)'
collect2: error: ld returned 1 exit status

This is a partial result of using -fvisibility=internal (which is great!), but it also means that the tlsh_unittest binary is making use of functions that are not part of the public API nor ABI.

I made it build with this patch, that exposes the missing function in the library:

--- a/src/input_desc.cpp
+++ b/src/input_desc.cpp
@@ -153,6 +153,7 @@
         return (strcmp(r1->full_fname, r2->full_fname));
 }
 
+__attribute__ ((visibility ("default")))
 int set_input_desc(char *dirname, char *listname, int listname_col, int listname_csv,
 	char *fname, char *digestname, int show_details, int fc_cons_option, char *splitlines, struct InputDescr *inputd, int showvers)
 {
--- a/src/shared_file_functions.cpp
+++ b/src/shared_file_functions.cpp
@@ -138,6 +138,7 @@
 	}
 }
 
+__attribute__ ((visibility ("default")))
 const char *convert_special_chars(char *filename, char *buf, size_t bufSize, int output_json)
 {
 	int len = strlen(filename);
@@ -182,6 +183,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
+__attribute__ ((visibility ("default")))
 int read_file_eval_tlsh(char *fname, Tlsh *th, int show_details, int fc_cons_option, int showvers)
 {
 	///////////////////////////////////////
@@ -402,6 +404,7 @@
 	return(err);
 }
 
+__attribute__ ((visibility ("default")))
 void freeFileName(struct FileName *fnames, int count)
 {
     for (int i=0; i<count; i++) {

However, that's clearly not an optimal solution. I think it would be best if one of the followings could happen (this is not exhaustive, just what came to my mind):

  1. move those functions into the official public API/ABI
  2. make those functions static or inline, that should make the compiler pick them up earlier
  3. ... not sure about other options right away ...

Besides this, it would be nice if you could elaborate on what "problems" it was causing when "compiling / testing tools on Linux", as it's mentioned in src/CMakeLists.txt.

Thank you for considering at least! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions